tuple: is_tuple[_v] implementation

This commit is contained in:
Michele Caini
2022-10-24 11:15:34 +02:00
parent b54766d2b4
commit 95b443af16
2 changed files with 42 additions and 0 deletions

View File

@@ -7,6 +7,41 @@
namespace entt {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename>
struct is_tuple_impl: std::false_type {};
template<typename... Args>
struct is_tuple_impl<std::tuple<Args...>>: std::true_type {};
} // namespace internal
/**
* Internal details not to be documented.
* @endcond
*/
/**
* @brief Provides the member constant `value` to true if a given type is a
* tuple, false otherwise.
* @tparam Type The type to test.
*/
template<typename Type>
struct is_tuple: internal::is_tuple_impl<std::remove_cv_t<Type>> {};
/**
* @brief Helper variable template.
* @tparam Type The type to test.
*/
template<typename Type>
inline constexpr bool is_tuple_v = is_tuple<Type>::value;
/**
* @brief Utility function to unwrap tuples of a single element.
* @tparam Type Tuple type of any sizes.

View File

@@ -2,6 +2,13 @@
#include <gtest/gtest.h>
#include <entt/core/tuple.hpp>
TEST(Tuple, IsTuple) {
static_assert(!entt::is_tuple_v<int>);
static_assert(entt::is_tuple_v<std::tuple<>>);
static_assert(entt::is_tuple_v<std::tuple<int>>);
static_assert(entt::is_tuple_v<std::tuple<int, char>>);
}
TEST(Tuple, UnwrapTuple) {
auto single = std::make_tuple(42);
auto multi = std::make_tuple(42, 'c');