Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::has_un...esentations(3)  C++ Standard Libary std::has_un...esentations(3)

NAME
       std::has_unique_object_representations  - std::has_unique_object_repre-
       sentations

Synopsis
	  Defined in header <type_traits>
	  template< class T >			     (since C++17)
	  struct has_unique_object_representations;

	  std::has_unique_object_representations is a UnaryTypeTrait.

	  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 is the same.

	  It  is implementation-defined	which scalar types satisfy this	trait,
       but
	  unsigned
	  (until C++20)	integer	types that do not use padding bits are guaran-
       teed 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.

	  If  the program adds specializations for std::has_unique_object_rep-
       resentations or
	  std::has_unique_object_representations_v, the	behavior is undefined.

Template parameters
	  T - a	type to	check

	  Helper variable template

	  template< class T >

	  inline constexpr bool	has_unique_object_representations_v =	(since
       C++17)

	      has_unique_object_representations<T>::value;

       Inherited from std::integral_constant

Member constants
	  value	    true  if T has unique object representations, false	other-
       wise
	  [static] (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
	  Type	     Definition
	  value_type bool
	  type	     std::integral_constant<bool, value>

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  ar-
       ray.

		   Feature-test	     macro		      Value	   Std
       Feature	__cpp_lib_has_unique_object_representations  201606L   (C++17)
       std::has_unique_object_representations

Example
       // Run this code

	#include <cstdint>
	#include <type_traits>

	struct unpadded
	{
	    std::uint32_t a, b;
	};

	struct likely_padded
	{
	    std::uint8_t c;
	    std::uint16_t st;
	    std::uint32_t i;
	};

	int main()
	{
	    //	Every value of a char corresponds to exactly one object	repre-
       sentation.
	    static_assert(std::has_unique_object_representations_v<char>);
	    // For IEC 559 floats, assertion passes because the	value NaN has
	    // multiple	object representations.
	    static_assert(!std::has_unique_object_representations_v<float>);

	    // Should succeed in any sane implementation because unpadded
	    // is typically  not  padded,  and	std::uint32_t  cannot  contain
       padding bits.
	    static_assert(std::has_unique_object_representations_v<unpadded>);
	    // Fails in	most implementations because padding bits are inserted
	    //	between	 the data members c and	st for the purpose of aligning
       st to 16	bits.
	    static_assert(!std::has_unique_object_representa-
       tions_v<likely_padded>);

	    // Notable architectural divergence:
	    static_assert(std::has_unique_object_representations_v<bool>);  //
       x86
	 // static_assert(!std::has_unique_object_representations_v<bool>); //
       ARM
	}

See also
	  is_standard_layout checks if a type is a standard-layout type
	  (C++11)	     (class template)
	  hash		     hash function object
	  (C++11)	     (class template)

http://cppreference.com		  2024.06.10	  std::has_un...esentations(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::has_unique_object_representations&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help