Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::negation

      From cppreference.com
      <cpp‎ |types
       
       
      Metaprogramming library
      Type traits
      Type categories
      (C++11)
      (C++11)(DR*)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11) 
      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
       
      Defined in header<type_traits>
      template<class B>
      struct negation;
      (since C++17)

      Forms thelogical negation of the type traitB.

      The typestd::negation<B> is aUnaryTypeTrait with a base characteristic ofstd::bool_constant<!bool(B::value)>.

      If the program adds specializations forstd::negation orstd::negation_v, the behavior is undefined.

      Contents

      [edit]Template parameters

      B - any type such that the expressionbool(B::value) is a valid constant expression

      [edit]Helper variable template

      template<class B>
      constexprbool negation_v= negation<B>::value;
      (since C++17)
      [edit]

      Inherited fromstd::integral_constant

      Member constants

      value
      [static]
      true ifB has a member::value that isfalse when explicitly converted tobool,false otherwise
      (public static member constant)

      Member functions

      operator bool
      converts the object tobool, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typebool
      typestd::integral_constant<bool, value>

      [edit]Possible implementation

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

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_logical_traits201510L(C++17)Logical operator type traits

      [edit]Example

      Run this code
      #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(){}

      [edit]See also

      variadic logical AND metafunction
      (class template)[edit]
      variadic logical OR metafunction
      (class template)[edit]
      compile-time constant of specified type with specified value
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/negation&oldid=176460"

      [8]ページ先頭

      ©2009-2025 Movatter.jp