std::negation(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::negation(3) β€” from the C++ Standard Libary πŸ’…

✨ NAME ✨

std::negation β€” std::negation. That’s literally the name, bestie, no cap. It’s the C++ Standard Libary page for std::negation.


🌸 Synopsis 🌸

Defined in header <type_traits>
template< class B >              (since C++17)
struct negation;

okay so std::negation forms the logical negation of the type trait B πŸ’…

The type std::negation<B> is a UnaryTypeTrait with a base characteristic of std::bool_constant<!bool(B::value)>.

🚨 bestie, important: if the program adds specializations for std::negation or std::negation_v, the behavior is undefined. not cute, not iconic, just undefined 😭

πŸ¦‹ Template parameters πŸ¦‹

  • B β€” any type such that the expression bool(B::value) is a valid constant expression.

πŸŽ€ Helper variable template πŸŽ€

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

🫢 Inherited from std::integral_constant 🫢


πŸ’– Member constants πŸ’–

  • value β€” true if B has a member ::value that is false when explicitly converted to [static] bool, false otherwise (public static member constant).

πŸ’… Member functions πŸ’…

  • operator bool β€” converts the object to bool, returns value (public member function).
  • operator() β€” returns value (C++14) (public member function).

🌈 Member types 🌈

  • value_type β€” bool
  • type β€” std::integral_constant<bool, value>

✨ Possible implementation ✨

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

πŸ“ Notes πŸ“

  • Feature-test macro: __cpp_lib_logical_traits β€” Value: 201510L β€” Std: (C++17) β€” Feature: Logical operator type traits

πŸ’» Example πŸ’»

Run this code, bestie:

       // Run this code

        #include <iostream>
        #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,
            "");

        int main()
        {
            std::cout << std::boolalpha;
            std::cout << std::negation<std::bool_constant<true>>::value <<
       '\n';
            std::cout << std::negation<std::bool_constant<false>>::value <<
       '\n';
        }

πŸ“€ Output πŸ“€

false
true

πŸ‘€ See also πŸ‘€

  • conjunction β€” variadic logical AND metafunction (C++17) (class template)
  • disjunction β€” variadic logical OR metafunction (C++17) (class template)
  • integral_constant β€” (C++11) (class template)
  • bool_constant β€” compile-time constant of specified type with specified value (C++17) (class template)

okay bestie, that’s the whole page πŸ’– source: http://cppreference.com, version/date stamp: 2024.06.10, and this is std::negation(3) signing off πŸŽ€βœ¨

πŸ“¦ where this page comes from