From 7c08fc863ac45f2d41b18103b0132004a4c0c524 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 20 Aug 2020 13:34:45 +0200 Subject: Core/Util: Added new utilities * Trinity::new_from_tuple - same as std::make_from_tuple except allocates object using "new" * Trinity::is_tuple - detects whether given type is a tuple specialization * advstd::type_identity - C++20 std::type_identity --- src/common/Utilities/Tuples.h | 31 +++++++++++++++++++++++++++++++ src/common/Utilities/advstd.h | 11 +++++++++++ 2 files changed, 42 insertions(+) (limited to 'src') diff --git a/src/common/Utilities/Tuples.h b/src/common/Utilities/Tuples.h index 73337ebd9f5..8b608fd8901 100644 --- a/src/common/Utilities/Tuples.h +++ b/src/common/Utilities/Tuples.h @@ -29,6 +29,37 @@ namespace Trinity struct has_type> : std::disjunction...> { }; + + template + constexpr bool has_type_v = has_type::value; + + template + struct is_tuple : std::false_type + { + }; + + template + struct is_tuple> : std::true_type + { + }; + + template + constexpr bool is_tuple_v = is_tuple::value; + + namespace Impl + { + template + T* new_from_tuple(Tuple&& args, std::index_sequence) + { + return new T(std::get(std::forward(args))...); + } + } + + template + [[nodiscard]] T* new_from_tuple(Tuple&& args) + { + return Impl::new_from_tuple(std::forward(args), std::make_index_sequence>>{}); + } } #endif // Tuples_h__ diff --git a/src/common/Utilities/advstd.h b/src/common/Utilities/advstd.h index fc8221b7314..2552f7d12bb 100644 --- a/src/common/Utilities/advstd.h +++ b/src/common/Utilities/advstd.h @@ -27,6 +27,17 @@ namespace advstd // C++20 advstd::remove_cvref_t template using remove_cvref_t = std::remove_cv_t>; + + // C++20 std::type_identity + template + struct type_identity + { + using type = T; + }; + + // C++20 std::type_identity_t + template + using type_identity_t = typename type_identity::type; } #endif -- cgit v1.2.3