Namespaces
Variants

std:: has_unique_object_representations

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
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)
has_unique_object_representations
(C++17)
Type trait constants
Metafunctions
(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
헤더에 정의됨 <type_traits>
template < class T >
struct has_unique_object_representations ;
(C++17부터)

std::has_unique_object_representations UnaryTypeTrait 입니다.

만약 T trivially copyable 이고, 동일한 값을 갖는 T 타입의 두 객체가 동일한 object representation 을 갖는 경우, 멤버 상수 value true 로 제공합니다. 다른 모든 타입에 대해서는 value false 입니다.

이 특성의 목적상, 두 배열은 그 요소들이 동일한 값을 가지면 동일한 값을 가지며, 두 비-공용체 클래스는 그 직접 하위 객체들이 동일한 값을 가지면 동일한 값을 가지며, 두 공용체는 동일한 활성 멤버를 가지고 그 멤버의 값이 동일하면 동일한 값을 가집니다.

어떤 스칼라 타입이 이 특성을 만족하는지는 구현에 따라 정의되지만, unsigned (until C++20) integer 타입 중 패딩 비트를 사용하지 않는 타입들은 고유한 객체 표현을 가진다는 것이 보장됩니다.

만약 std:: remove_all_extents_t < T > 가 (가능하다면 cv-qualified) void 를 제외한 불완전한 타입인 경우, 동작은 정의되지 않습니다.

프로그램이 std::has_unique_object_representations 또는 std::has_unique_object_representations_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T >

constexpr bool has_unique_object_representations_v =

has_unique_object_representations < T > :: value ;
(C++17부터)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true 만약 T 가 고유한 객체 표현을 가지면, false 그렇지 않으면
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type bool
type std:: integral_constant < bool , value >

참고 사항

이 특성은 어떤 타입이 해당 객체 표현을 바이트 배열로 해싱하여 올바르게 해시될 수 있는지 여부를 판단할 수 있도록 도입되었습니다.

기능 테스트 매크로 표준 기능
__cpp_lib_has_unique_object_representations 201606L (C++17) std::has_unique_object_representations

예제

#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()
{
    // char의 모든 값은 정확히 하나의 객체 표현에 대응됩니다.
    static_assert(std::has_unique_object_representations_v<char>);
    // IEC 559 float의 경우, NaN 값이 여러 객체 표현을 가지므로
    // 어설션이 통과됩니다.
    static_assert(!std::has_unique_object_representations_v<float>);
    // unpadded는 일반적으로 패딩되지 않으며 std::uint32_t는 패딩 비트를
    // 포함할 수 없으므로 모든 정상적인 구현에서 성공해야 합니다.
    static_assert(std::has_unique_object_representations_v<unpadded>);
    // 대부분의 구현에서 실패합니다. 왜냐하면 st를 16비트로 정렬하기 위해
    // 데이터 멤버 c와 st 사이에 패딩 비트가 삽입되기 때문입니다.
    static_assert(!std::has_unique_object_representations_v<likely_padded>);
    // 주목할 만한 아키텍처 차이:
    static_assert(std::has_unique_object_representations_v<bool>);  // x86
 // static_assert(!std::has_unique_object_representations_v<bool>); // ARM
}

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 4113 C++17 T 는 요소 타입이 불완전한 경우에도
알 수 없는 경계의 배열일 수 있었음
요소 타입이 완전해야
함을 요구

참고 항목

타입이 standard-layout 타입인지 확인
(클래스 템플릿)
(C++11)
해시 함수 객체
(클래스 템플릿)