etl/type_traits.h: Add support for type_identity (#905)

* etl/type_traits.h: Add support for type_identity

* test/test_type_traits.cpp: Add a test for etl::type_identity (type_identity_test_add(1.5f, 2) == 3.5f)

* Update test_type_traits.cpp

Use CHECK_CLOSE instead of CHECK for equality
This commit is contained in:
Tigran Khachatryan 2024-06-11 16:43:59 +04:00 committed by GitHub
parent bb71b60496
commit 6ced0630a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 0 deletions

View File

@ -2295,6 +2295,17 @@ typedef integral_constant<bool, true> true_type;
template <typename T>
using signed_type_t = typename signed_type<T>::type;
#endif
//*********************************************
// type_identity
template <typename T>
struct type_identity { typedef T type; };
#if ETL_USING_CPP11
template <typename T>
using type_identity_t = typename type_identity<T>::type;
#endif
}
// Helper macros

View File

@ -2288,6 +2288,17 @@ typedef integral_constant<bool, true> true_type;
template <typename T>
using signed_type_t = typename signed_type<T>::type;
#endif
//*********************************************
// type_identity
template <typename T>
struct type_identity { typedef T type; };
#if ETL_USING_CPP11
template <typename T>
using type_identity_t = typename type_identity<T>::type;
#endif
}
// Helper macros

View File

@ -122,6 +122,13 @@ namespace
NotDefaultConstructible(NotDefaultConstructible&&) = delete;
NotDefaultConstructible& operator =(NotDefaultConstructible&) = delete;
};
// A function to test etl::type_identity.
template <typename T>
T type_identity_test_add(T first, typename etl::type_identity<T>::type second)
{
return first + second;
}
}
// Definitions for when the STL and compiler built-ins are not available.
@ -1320,4 +1327,9 @@ namespace
CHECK_FALSE(bool(etl::is_base_of_all<Base, D1, D2, D3, D4>::value));
#endif
}
//*************************************************************************
TEST(test_type_identity) {
CHECK_CLOSE(type_identity_test_add(1.5f, 2), 3.5f, 0.01f);
}
}