mirror of
https://github.com/bkaradzic/bx.git
synced 2026-09-07 02:48:33 +00:00
Added bx::hasUniqueObjectRepresentation type trait. (#420)
This commit is contained in:
committed by
GitHub
parent
671a001d3e
commit
080f466590
@@ -366,6 +366,15 @@ namespace bx
|
||||
return IsTriviallyCopyableT<Ty>::value;
|
||||
}
|
||||
|
||||
//---
|
||||
template<typename Ty> struct HasUniqueObjectRepresentationT : public BoolConstantT<__has_unique_object_representations(Ty)> {};
|
||||
|
||||
template<typename Ty>
|
||||
inline constexpr bool hasUniqueObjectRepresentation()
|
||||
{
|
||||
return HasUniqueObjectRepresentationT<Ty>::value;
|
||||
}
|
||||
|
||||
//---
|
||||
template<typename Ty> struct IsTriviallyDestructibleT : public BoolConstantT<
|
||||
#if BX_COMPILER_GCC
|
||||
|
||||
@@ -129,6 +129,11 @@ namespace bx
|
||||
template<typename Ty>
|
||||
constexpr bool isTriviallyCopyable();
|
||||
|
||||
/// Returns true if any two objects of type `Ty` that hold the same value also have the
|
||||
/// same object representation, otherwise returns false. False for a type with padding.
|
||||
template<typename Ty>
|
||||
constexpr bool hasUniqueObjectRepresentation();
|
||||
|
||||
/// Returns true if type `Ty` has trivial destructor, otherwise returns false.
|
||||
template<typename Ty>
|
||||
constexpr bool isTriviallyDestructible();
|
||||
|
||||
@@ -25,6 +25,8 @@ struct TestClassDerivedB /*
|
||||
: TestClassDerivedA { };
|
||||
struct TestClassDerivedX /* */
|
||||
: TestClassVirtualDtor { };
|
||||
struct TestClassPadded { uint32_t x; uint16_t y; uint8_t z; };
|
||||
struct TestClassNoPadding { uint32_t x; uint16_t y; uint8_t z; uint8_t w; };
|
||||
union TestUnionEmpty { };
|
||||
union TestUnion { int32_t x; float y; };
|
||||
enum TestEnumEmpty { };
|
||||
@@ -210,6 +212,19 @@ TEST_CASE("type-traits isTriviallyCopyable", "")
|
||||
STATIC_REQUIRE(!bx::isTriviallyCopyable<TestClassVirtualDtor >() );
|
||||
}
|
||||
|
||||
TEST_CASE("type-traits hasUniqueObjectRepresentation", "")
|
||||
{
|
||||
STATIC_REQUIRE( 8 == sizeof(TestClassPadded) );
|
||||
STATIC_REQUIRE( 8 == sizeof(TestClassNoPadding) );
|
||||
|
||||
STATIC_REQUIRE( bx::hasUniqueObjectRepresentation<int32_t >() );
|
||||
STATIC_REQUIRE( bx::hasUniqueObjectRepresentation<TestClassMember >() );
|
||||
STATIC_REQUIRE( bx::hasUniqueObjectRepresentation<TestClassNoPadding >() );
|
||||
STATIC_REQUIRE(!bx::hasUniqueObjectRepresentation<TestClassPadded >() );
|
||||
STATIC_REQUIRE(!bx::hasUniqueObjectRepresentation<TestClassVirtualDtor >() );
|
||||
STATIC_REQUIRE(!bx::hasUniqueObjectRepresentation<float >() );
|
||||
}
|
||||
|
||||
TEST_CASE("type-traits isTriviallyConstructible", "")
|
||||
{
|
||||
STATIC_REQUIRE( bx::isTriviallyConstructible<int32_t >() );
|
||||
|
||||
Reference in New Issue
Block a user