type_traits: added is_transparent[_v] utility

This commit is contained in:
Michele Caini
2021-10-09 19:11:59 +02:00
parent 0fb86f21e4
commit acb2d332ea
2 changed files with 27 additions and 0 deletions

View File

@@ -509,6 +509,25 @@ struct is_ebco_eligible
template<typename Type>
inline constexpr bool is_ebco_eligible_v = is_ebco_eligible<Type>::value;
/**
* @brief Provides the member constant `value` to true if `Type::is_transparent`
* is valid and denotes a type, false otherwise.
* @tparam Type The type to test.
*/
template<typename Type, typename = void>
struct is_transparent: std::false_type {};
/*! @copydoc is_transparent */
template<typename Type>
struct is_transparent<Type, std::void_t<typename Type::is_transparent>>: std::true_type {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
*/
template<typename Type>
inline constexpr bool is_transparent_v = is_transparent<Type>::value;
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.

View File

@@ -1,3 +1,4 @@
#include <functional>
#include <iterator>
#include <tuple>
#include <type_traits>
@@ -160,6 +161,13 @@ TEST(TypeTraits, IsEBCOEligible) {
static_assert(!entt::is_ebco_eligible_v<void>);
}
TEST(TypeTraits, IsTransparent) {
static_assert(!entt::is_transparent_v<std::less<int>>);
static_assert(entt::is_transparent_v<std::less<void>>);
static_assert(!entt::is_transparent_v<std::logical_not<double>>);
static_assert(entt::is_transparent_v<std::logical_not<void>>);
}
TEST(TypeTraits, ConstnessAs) {
static_assert(std::is_same_v<entt::constness_as_t<int, char>, int>);
static_assert(std::is_same_v<entt::constness_as_t<const int, char>, int>);