Namespaces
Variants

std:: ignore

From cppreference.net
Utilities library
헤더에 정의됨 <tuple>
헤더에 정의됨 <utility>
(1)
const /*ignore-type*/ ignore ;
(C++11부터)
(C++14까지)
constexpr /*ignore-type*/ ignore ;
(C++14부터)
(C++17부터 inline)
(2)
struct /*ignore-type*/

{
template < class T >
const /*ignore-type*/ & operator = ( const T & ) const noexcept
{
return * this ;
}

} ;
(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을 개별 객체들로 풀어냄
(함수 템플릿)