diff options
-rw-r--r-- | source/blender/functions/FN_array_spans.hh | 2 | ||||
-rw-r--r-- | source/blender/functions/FN_cpp_type.hh | 5 | ||||
-rw-r--r-- | source/blender/functions/FN_generic_vector_array.hh | 2 | ||||
-rw-r--r-- | source/blender/functions/FN_spans.hh | 6 | ||||
-rw-r--r-- | tests/gtests/functions/FN_cpp_type_test.cc | 6 |
5 files changed, 16 insertions, 5 deletions
diff --git a/source/blender/functions/FN_array_spans.hh b/source/blender/functions/FN_array_spans.hh index fac2ef42c9d..acd3e921b50 100644 --- a/source/blender/functions/FN_array_spans.hh +++ b/source/blender/functions/FN_array_spans.hh @@ -184,7 +184,7 @@ class GVArraySpan : public VArraySpanBase<void> { template<typename T> VArraySpan<T> typed() const { - BLI_assert(CPPType::get<T>() == *m_type); + BLI_assert(m_type->is<T>()); return VArraySpan<T>(*this); } diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh index e44ce858b74..706ff85bdf3 100644 --- a/source/blender/functions/FN_cpp_type.hh +++ b/source/blender/functions/FN_cpp_type.hh @@ -483,6 +483,11 @@ class CPPType { template<typename T> static const CPPType &get(); + template<typename T> bool is() const + { + return this == &CPPType::get<T>(); + } + private: uint m_size; uint m_alignment; diff --git a/source/blender/functions/FN_generic_vector_array.hh b/source/blender/functions/FN_generic_vector_array.hh index 1c8f74f2abe..6be1b68da4d 100644 --- a/source/blender/functions/FN_generic_vector_array.hh +++ b/source/blender/functions/FN_generic_vector_array.hh @@ -167,7 +167,7 @@ template<typename T> class GVectorArrayRef { public: GVectorArrayRef(GVectorArray &vector_array) : m_vector_array(&vector_array) { - BLI_assert(vector_array.m_type == CPPType::get<T>()); + BLI_assert(vector_array.m_type.is<T>()); } void append(uint index, const T &value) diff --git a/source/blender/functions/FN_spans.hh b/source/blender/functions/FN_spans.hh index d3497c05eb9..b4607527fb5 100644 --- a/source/blender/functions/FN_spans.hh +++ b/source/blender/functions/FN_spans.hh @@ -100,7 +100,7 @@ class GSpan { template<typename T> Span<T> typed() const { - BLI_assert(CPPType::get<T>() == *m_type); + BLI_assert(m_type->is<T>()); return Span<T>((const T *)m_buffer, m_size); } }; @@ -166,7 +166,7 @@ class GMutableSpan { template<typename T> MutableSpan<T> typed() { - BLI_assert(CPPType::get<T>() == *m_type); + BLI_assert(m_type->is<T>()); return MutableSpan<T>((T *)m_buffer, m_size); } }; @@ -372,7 +372,7 @@ class GVSpan : public VSpanBase<void> { template<typename T> VSpan<T> typed() const { - BLI_assert(CPPType::get<T>() == *m_type); + BLI_assert(m_type->is<T>()); return VSpan<T>(*this); } diff --git a/tests/gtests/functions/FN_cpp_type_test.cc b/tests/gtests/functions/FN_cpp_type_test.cc index 83dc327e381..33e6fbee7f6 100644 --- a/tests/gtests/functions/FN_cpp_type_test.cc +++ b/tests/gtests/functions/FN_cpp_type_test.cc @@ -84,6 +84,12 @@ TEST(cpp_type, Alignment) EXPECT_EQ(CPPType_TestType.alignment(), alignof(TestType)); } +TEST(cpp_type, Is) +{ + EXPECT_TRUE(CPPType_TestType.is<TestType>()); + EXPECT_FALSE(CPPType_TestType.is<int>()); +} + TEST(cpp_type, DefaultConstruction) { int buffer[10] = {0}; |