types_negation (논리 부정)
이 페이지는 C++ 표준 라이브러리의 std::negation 타입 특성에 대해 설명해요. std::negation은 주어진 타입 특성 B의 논리 부정을 나타내는 메타함수예요. 즉, B::value가 false로 평가되면 true를, 그렇지 않으면 false를 값으로 가지는 타입을 만들어 줘요.
출처: cppreference
본문
정의
<type_traits> 헤더에 정의되어 있어요.
| 템플릿 선언 |
|
template < class B > struct negation; |
(C++17부터) |
std::negation<B>는 타입 특성 B의 논리 부정을 형성해요. 이 타입은 std::bool_constant<!bool(B::value)>를 기본 특성으로 가지는 UnaryTypeTrait이에요.
프로그램에서 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] |
B가 멤버 ::value를 가지고 있고, 그 값을 명시적으로 bool로 변환했을 때 false라면 true, 그렇지 않으면 false (공용 정적 멤버 상수) |
멤버 함수
operator bool |
객체를 bool로 변환하고 value를 반환해요 (공용 멤버 함수) |
operator() (C++14) |
value를 반환해요 (공용 멤버 함수) |
멤버 타입
| 타입 |
정의 |
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() {}
같이 보기
conjunction (C++17) |
가변 인자 논리 AND 메타함수 (클래스 템플릿) |
disjunction (C++17) |
가변 인자 논리 OR 메타함수 (클래스 템플릿) |
integral_constant bool_constant (C++11) (C++17) |
지정된 타입과 값을 가지는 컴파일 타임 상수 (클래스 템플릿) |
더 알아보기 (Learn more)
cppreference