Namespaces
Variants
Views
Actions

std::has_strong_structural_equality

From cppreference.com
< cpp‎ | types
 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(until C++20)
(C++11)(deprecated in C++20)
(C++11)
has_strong_structural_equality
(C++20)
Type trait constants
Metafunctions
(C++17)
Constant evaluation context
Supported operations
Relationships and property queries
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++17)
(C++11)(until C++20)(C++17)
 
Defined in header <type_traits>
template< class T >
struct has_strong_structural_equality;
(since C++20)

If T has strong structural equality, provides the member constant value equal true. For any other type, value is false.

Contents

[edit] Template parameters

T - a type to check

[edit] Helper variable template

template< class T >
inline constexpr bool has_strong_structural_equality_v = has_strong_structural_equality<T>::value;
(since C++20)

Inherited from std::integral_constant

Member constants

value
[static]
true if T has strong structural equality , false otherwise
(public static member constant)

Member functions

operator bool
converts the object to bool, returns value
(public member function)
operator()
(C++14)
returns value
(public member function)

Member types

Type Definition
value_type bool
type std::integral_constant<bool, value>

[edit] Notes

This type trait is useful to check if a type can be used as a non-type template parameter.

[edit] Example

#include <type_traits>
#include <cstring>
#include <algorithm>
#include <iostream>
 
template<std::size_t N>
struct fixed_string {
    constexpr fixed_string(const char (&s)[N + 1])
    {
        std::copy_n(s, N + 1, m_data);
    }
    bool operator==(const fixed_string&) const = default;
 
    char m_data[N + 1];
};
 
template<std::size_t N>
struct broken_fixed_string {
    constexpr broken_fixed_string(const char (&s)[N + 1])
    {
        std::copy_n(s, N + 1, m_data);
    }
    bool operator==(const broken_fixed_string &rhs) const
    {
        return std::memcmp(m_data, rhs.m_data, N + 1) == 0;
    }
 
    char m_data[N + 1];
};
 
int main()
{
    std::cout
        << std::boolalpha
        << std::has_strong_structural_equality_v<fixed_string<42>> << '\n'
        << std::has_strong_structural_equality_v<broken_fixed_string<42>> << '\n';
}

Output:

true
false

[edit] See also

the result type of 3-way comparison that supports all 6 operators and is substitutable
(class) [edit]
the result type of 3-way comparison that supports only equality/inequality and is substitutable
(class) [edit]