Namespaces
Variants

std:: negation

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
negation
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더 파일에 정의됨 <type_traits>
template < class B >
struct negation ;
(C++17부터)

B 형식 특성의 논리적 부정 을 형성합니다.

타입 std :: negation < B > UnaryTypeTrait 이며 기본 특성은 std:: bool_constant < ! bool ( B :: value ) > 입니다.

프로그램이 std::negation 또는 std::negation_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

B - bool ( B :: value ) 표현식이 유효한 상수 표현식인 모든 타입

헬퍼 변수 템플릿

template < class B >
constexpr bool negation_v = negation < B > :: value ;
(C++17부터)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true 만약 B :: value 멤버를 가지고 있고, 이를 bool 로 명시적으로 변환할 때 false 인 경우, 그렇지 않으면 false
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type bool
type std:: integral_constant < bool , value >

가능한 구현

template<class B>
struct negation : std::bool_constant<!bool(B::value)> { };

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_logical_traits 201510L (C++17) 논리 연산자 타입 특성

예제

#include <type_traits>
static_assert(
    std::is_same<
        std::bool_constant<false>,
        typename std::negation<std::bool_constant<true>>::type>::value,
    "");
static_assert(
    std::is_same<
        std::bool_constant<true>,
        typename std::negation<std::bool_constant<false>>::type>::value,
    "");
static_assert(std::negation_v<std::bool_constant<true>> == false);
static_assert(std::negation_v<std::bool_constant<false>> == true);
int main() {}

참고 항목

가변 인자 논리 AND 메타 함수
(클래스 템플릿)
가변 인자 논리 OR 메타 함수
(클래스 템플릿)
지정된 타입과 값을 가진 컴파일 타임 상수
(클래스 템플릿)