Namespaces
Variants

std::ignore

cppreference.net에서
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 비권장)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교체 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
헤더 <tuple>
에 정의됨 <utility>
const /*ignore-type*/ ignore;
헤더 에 정의됨 (1)
(C++11부터)
constexpr /*ignore-type*/ ignore;
(C++14까지)
(C++14부터)
struct /*ignore-type*/
{
    template< class T >
    const /*ignore-type*/& operator=( const T& ) const noexcept
    {
        return *this;
    }
};
(C++17부터 인라인) (2)
(C++11부터)
(C++14까지)(설명 전용*
struct /*ignore-type*/
{
    template< class T >
    constexpr const /*ignore-type*/& operator=( const T& ) const noexcept
    {
        return *this;
    }
};
)
(C++14부터)(설명 전용*
)1)
아무 값이나 할당해도 효과가 없는 객체입니다.2)std::ignore 의 타입입니다.

참고 사항

A void 표현식 또는 volatile 비트 필드 값은 std::ignore 에 할당할 수 없습니다.

std::ignore 는 std::tie 와 함께 std::tuple 을 언패킹할 때 사용되지 않는 인자들을 위한 자리 표시자로 사용되지만, 원치 않는 대입에 대해서도 사용할 수 있습니다.

일부 코드 가이드는 할당이 필요하지 않더라도 std::ignore 를 사용하여 [[ nodiscard ]] 함수의 사용되지 않은 반환 값에 대한 경고를 피하도록 권장합니다.

할당이 필요하지 않은 값을 무시하기 위해서는 void 로 캐스팅할 수 있습니다. 이름은 있지만 값이 사용되지 않는 변수의 경우, void 로 캐스팅하거나 [[ maybe_unused ]] 속성으로 변수를 선언할 수 있습니다.

예제

  1. std::ignore 의 사용법을 [[ nodiscard ]] 함수와 함께 보여줍니다.
  2. std:: pair < iterator, bool > 에 의해 반환된 값을 std:: set :: insert ( ) 로 언패킹하지만, 부울 값만 저장합니다.
#include <iostream>
#include <set>
#include <string>
#include <tuple>
[[nodiscard]] int dontIgnoreMe()
{
    return 42;
}
int main()
{
    std::ignore = dontIgnoreMe();
    std::set<std::string> set_of_str;
    if (bool inserted{false};
        std::tie(std::ignore, inserted) = set_of_str.insert("Test"),
        inserted)
        std::cout << "Value was inserted successfully.\n";
}

출력:

Value was inserted successfully.

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2773 C++14 std::tuple 이 constexpr 로 만들어졌지만 std::ignore 는 아직 그렇지 않았음 constexpr 로 만듦
P2968R2 C++11 std::ignore 의 동작이 std::tie 외부에서 공식적으로 명세되지 않았음 완전히 명세함

참고 항목

(C++11)
lvalue 참조들의 tuple 을 생성하거나 tuple을 개별 객체들로 풀어냄
(함수 템플릿)