mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
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:
parent
bb71b60496
commit
6ced0630a9
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user