Skip to content

Commit d4365d3

Browse files
committed
Add decay_tuple.
1 parent b0e5eb8 commit d4365d3

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

include/bitcoin/system/typelets.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ template <typename Larger, typename Smaller, size_t Lanes = one,
151151
////std::enable_if_t<Lanes <= (max_size_t / size_of<Smaller>()), bool> = true>
152152
constexpr size_t capacity = size_of<Larger>() / (Lanes * size_of<Smaller>());
153153

154+
/// std::tuple decay elements.
155+
/// ---------------------------------------------------------------------------
156+
157+
template <typename Tuple>
158+
struct decay_tuple;
159+
160+
template <typename ...Args>
161+
struct decay_tuple<std::tuple<Args...>>
162+
{
163+
using type = std::tuple<std::decay_t<Args>...>;
164+
};
165+
154166
/// uintx_t detection.
155167
/// ---------------------------------------------------------------------------
156168

test/typelets.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,55 @@ static_assert(size_of<std_array<const volatile std_array<std_array<uint32_t, 42>
417417
static_assert(size_of<std_array<std_array<const volatile std_array<uint32_t, 42>, 24>, 8>>() == sizeof(uint32_t) * 42 * 24 * 8);
418418
static_assert(size_of<const volatile std_array<const volatile std_array<const volatile std_array<uint32_t, 42>, 24>, 8>&>() == sizeof(uint32_t) * 42 * 24 * 8);
419419

420+
421+
// std::tuple decay elements.
422+
// ----------------------------------------------------------------------------
423+
// is_same_type decays individual types (but not tuple elements).
424+
425+
using test_tuple = std::tuple<int&, bool&&, const std::string&>;
426+
static_assert( is_same_type<decay_tuple<test_tuple>, decay_tuple<test_tuple>>);
427+
static_assert(!is_same_type<test_tuple, decay_tuple<test_tuple>>);
428+
static_assert(!is_same_type<decay_tuple<test_tuple>, test_tuple>);
429+
430+
static_assert(!std::is_same_v<std::tuple_element<0, test_tuple>::type, int>);
431+
static_assert(!std::is_same_v<std::tuple_element<1, test_tuple>::type, bool>);
432+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, std::string>);
433+
434+
static_assert(!std::is_same_v<std::tuple_element<0, test_tuple>::type, const int>);
435+
static_assert(!std::is_same_v<std::tuple_element<1, test_tuple>::type, const bool>);
436+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, const std::string>);
437+
438+
static_assert( std::is_same_v<std::tuple_element<0, test_tuple>::type, int&>);
439+
static_assert(!std::is_same_v<std::tuple_element<1, test_tuple>::type, bool&>);
440+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, std::string&>);
441+
442+
static_assert(!std::is_same_v<std::tuple_element<0, test_tuple>::type, int&&>);
443+
static_assert( std::is_same_v<std::tuple_element<1, test_tuple>::type, bool&&>);
444+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, std::string&&>);
445+
446+
using normal_test_tuple = std::tuple<int, bool, std::string>;
447+
using decayed_test_tuple = decay_tuple<test_tuple>::type;
448+
static_assert(is_same_type<normal_test_tuple, decayed_test_tuple>);
449+
450+
static_assert(std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, int>);
451+
static_assert(std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, bool>);
452+
static_assert(std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, std::string>);
453+
454+
static_assert(!std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, const int>);
455+
static_assert(!std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, const bool>);
456+
static_assert(!std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, const std::string>);
457+
458+
static_assert(!std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, int&>);
459+
static_assert(!std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, bool&>);
460+
static_assert(!std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, std::string&>);
461+
462+
static_assert(!std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, int&&>);
463+
static_assert(!std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, bool&&>);
464+
static_assert(!std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, std::string&&>);
465+
466+
// is_uintx
467+
// ----------------------------------------------------------------------------
468+
420469
static_assert(is_uintx<uint5_t>);
421470
static_assert(is_uintx<uint11_t>);
422471
static_assert(is_uintx<uint48_t>);

0 commit comments

Comments
 (0)