Skip to content

Commit abe7bd9

Browse files
authored
Merge pull request #1754 from evoskuil/master
Set preprocessor conformance in vc++, add decay_tuple.
2 parents 5d559a7 + f640e4b commit abe7bd9

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

builds/msvc/properties/Common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
<!-- Language -->
2929
<!-- /Zc is conformance mode. -->
30-
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
30+
<AdditionalOptions>/Zc:__cplusplus /Zc:preprocessor %(AdditionalOptions)</AdditionalOptions>
3131
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
3232
<RuntimeTypeInfo>true</RuntimeTypeInfo>
3333
<OpenMPSupport>false</OpenMPSupport>

include/bitcoin/system/constraints.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ template <typename Integer>
259259
using if_floating_point = bool_if<
260260
is_floating_point<Integer>>;
261261

262-
/// std::array/std::vector
262+
/// std::array/std::vector/std::tuple
263263

264264
template <typename Type>
265265
using if_std_array = bool_if<
@@ -274,6 +274,10 @@ using if_integral_array = bool_if<
274274
is_std_array<Type> &&
275275
is_integral_integer<typename Type::value_type>>;
276276

277+
template <typename Type>
278+
using if_tuple = bool_if<
279+
is_tuple<Type>>;
280+
277281
template <typename Type>
278282
using if_byte_insertable = bool_if<
279283
std::is_base_of<std::string, Type>::value ||

include/bitcoin/system/typelets.hpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ constexpr size_t bits = to_bits(sizeof(Type));
9797
template <size_t Bits, std::enable_if_t<is_byte_sized(Bits), bool> = true>
9898
constexpr size_t bytes = Bits / byte_bits;
9999

100-
/// std_array.
100+
/// std_array/std_vector.
101101
/// ---------------------------------------------------------------------------
102102

103103
template<typename>
@@ -140,7 +140,7 @@ constexpr size_t size_of()
140140

141141
// Type constraint fails to match as throw is not constexpr.
142142
if (count > (std::numeric_limits<size_t>::max() / size))
143-
throw overflow_exception("type contraint violated");
143+
throw overflow_exception("type constraint violated");
144144

145145
return size * count;
146146
}
@@ -151,6 +151,25 @@ 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.
155+
/// ---------------------------------------------------------------------------
156+
157+
template <typename, typename = void>
158+
struct is_tuple_t : std::false_type {};
159+
template <typename ...Args>
160+
struct is_tuple_t<std::tuple<Args...>> : std::true_type {};
161+
template<typename Type>
162+
constexpr bool is_tuple = is_tuple_t<Type>::value;
163+
164+
template <typename Tuple>
165+
struct decay_tuple;
166+
167+
template <typename ...Args>
168+
struct decay_tuple<std::tuple<Args...>>
169+
{
170+
using type = std::tuple<std::decay_t<Args>...>;
171+
};
172+
154173
/// uintx_t detection.
155174
/// ---------------------------------------------------------------------------
156175

test/constraints.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,12 @@ static_assert(is_defined<if_integral_array<std_array<uint8_t, 0>>>);
645645
////static_assert(!is_defined<if_integral_array<std_array<base, 0>>>);
646646
////static_assert(!is_defined<if_integral_array<uint8_t>>);
647647

648+
static_assert(is_defined<if_tuple<std::tuple<>>>);
649+
static_assert(is_defined<if_tuple<std::tuple<uint8_t, bool>>>);
650+
////static_assert(!is_defined<if_tuple<std_array<uint8_t, 0>>>);
651+
////static_assert(!is_defined<if_tuple<uint8_t>>);
652+
////static_assert(!is_defined<if_tuple<bool>>);
653+
648654
static_assert(is_defined<if_byte_insertable<std::string>>);
649655
static_assert(is_defined<if_byte_insertable<std::vector<uint8_t>>>);
650656
static_assert(is_defined<if_byte_insertable<std_vector<uint8_t>>>);

test/typelets.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,62 @@ 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+
// std::tuple.
421+
// ----------------------------------------------------------------------------
422+
// is_same_type decays individual types (but not tuple elements).
423+
424+
static_assert(!is_tuple<uint8_t>);
425+
static_assert(!is_tuple<std::string>);
426+
static_assert(!is_tuple<std::array<uint8_t, 42>>);
427+
static_assert( is_tuple<std::tuple<int, bool>>);
428+
static_assert( is_tuple<std::tuple<>>);
429+
static_assert( is_same_type<decltype(is_tuple<std_array<uint8_t, 0>>), const bool>);
430+
static_assert( is_same_type<decltype(is_tuple<std::tuple<int, bool>&>), const bool>);
431+
432+
using test_tuple = std::tuple<int&, bool&&, const std::string&>;
433+
static_assert( is_same_type<decay_tuple<test_tuple>, decay_tuple<test_tuple>>);
434+
static_assert(!is_same_type<test_tuple, decay_tuple<test_tuple>>);
435+
static_assert(!is_same_type<decay_tuple<test_tuple>, test_tuple>);
436+
437+
static_assert(!std::is_same_v<std::tuple_element<0, test_tuple>::type, int>);
438+
static_assert(!std::is_same_v<std::tuple_element<1, test_tuple>::type, bool>);
439+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, std::string>);
440+
441+
static_assert(!std::is_same_v<std::tuple_element<0, test_tuple>::type, const int>);
442+
static_assert(!std::is_same_v<std::tuple_element<1, test_tuple>::type, const bool>);
443+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, const std::string>);
444+
445+
static_assert( std::is_same_v<std::tuple_element<0, test_tuple>::type, int&>);
446+
static_assert(!std::is_same_v<std::tuple_element<1, test_tuple>::type, bool&>);
447+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, std::string&>);
448+
449+
static_assert(!std::is_same_v<std::tuple_element<0, test_tuple>::type, int&&>);
450+
static_assert( std::is_same_v<std::tuple_element<1, test_tuple>::type, bool&&>);
451+
static_assert(!std::is_same_v<std::tuple_element<2, test_tuple>::type, std::string&&>);
452+
453+
using normal_test_tuple = std::tuple<int, bool, std::string>;
454+
using decayed_test_tuple = decay_tuple<test_tuple>::type;
455+
static_assert(is_same_type<normal_test_tuple, decayed_test_tuple>);
456+
457+
static_assert(std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, int>);
458+
static_assert(std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, bool>);
459+
static_assert(std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, std::string>);
460+
461+
static_assert(!std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, const int>);
462+
static_assert(!std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, const bool>);
463+
static_assert(!std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, const std::string>);
464+
465+
static_assert(!std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, int&>);
466+
static_assert(!std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, bool&>);
467+
static_assert(!std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, std::string&>);
468+
469+
static_assert(!std::is_same_v<std::tuple_element<0, decayed_test_tuple>::type, int&&>);
470+
static_assert(!std::is_same_v<std::tuple_element<1, decayed_test_tuple>::type, bool&&>);
471+
static_assert(!std::is_same_v<std::tuple_element<2, decayed_test_tuple>::type, std::string&&>);
472+
473+
// is_uintx
474+
// ----------------------------------------------------------------------------
475+
420476
static_assert(is_uintx<uint5_t>);
421477
static_assert(is_uintx<uint11_t>);
422478
static_assert(is_uintx<uint48_t>);

0 commit comments

Comments
 (0)