< 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
Type properties
(C++11)(until C++20)
(C++11)(deprecated in C++20)
Type trait constants
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11)(until C++20)(C++17)
Defined in header <type_traits>
template< class T >
struct has_unique_object_representations;
(since C++17)

If T is TriviallyCopyable and if any two objects of type T with the same value have the same object representation, provides the member constant value equal true. For any other type, value is false.

For the purpose of this trait, two arrays have the same value if their elements have the same values, two non-union classes have the same value if their direct subobjects have the same value, and two unions have the same value if they have the same active member and the value of that member are the same.

It is implementation-defined which scalar types satisfy this trait, but unsigned integer types that do not use padding bits are guaranteed to have unique object representations.

The behavior is undefined if T is an incomplete type other than (possibly cv-qualified) void or array of unknown bound.


[edit] Template parameters

T - a type to check

[edit] Helper variable template

template< class T >
inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<T>::value;
(since C++17)

Inherited from std::integral_constant

Member constants

true if T has unique object representations , false otherwise
(public static member constant)

Member functions

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

Member types

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

[edit] Notes

This trait was introduced to make it possible to determine whether a type can be correctly hashed by hashing its object representation as a byte array.

[edit] Example

#include <iostream>
#include <type_traits>
struct bar
    int a;
    int b;
struct foo
    char c;
    float f;
    short st;
    int i;
int main()
     std::cout  << std::boolalpha 
                << "Does foo have unique object representations? "
                << std::has_unique_object_representations_v<foo> << '\n'
                << "Does bar have unique object representations? " 
                << std::has_unique_object_representations_v<bar> << '\n';

Possible output:

Does foo have unique object representations? false
Does bar have unique object representations? true

[edit] See also

checks if a type is standard-layout type
(class template) [edit]
hash function object
(class template) [edit]