This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace detail | |
{ | |
template <class...> struct integer_range; | |
template <class T, class Ofst, T... Vals> | |
struct integer_range<T, Ofst, std::integer_sequence<T, Vals...>> | |
{ | |
using type = std::integer_sequence<T, (Ofst::value + Vals)...>; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
int i1(1), i2(1); | |
char c1('o'), c2('k'); | |
auto tp{ std::make_tuple(2., 4., 23, 7, 'x', 'l') }; | |
std::array<char, 4> ar{ { 'a', 'b', 'c', 'd' } }; | |
// 1. read from a slice ----------------------------------- | |
std::tie(i1, i2) = tuple_slice<2, 4>(tp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template< bool... Bs > | |
using bool_sequence = std::integer_sequence< bool, Bs... >; | |
template< bool... Bs > | |
using bool_and = std::is_same< | |
bool_sequence<Bs... >, bool_sequence<(Bs || true)... >>; | |
template< bool... Bs > | |
using bool_or = std::integral_constant< bool, !bool_and< !Bs... >::value >; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <bool... Bs> constexpr bool all_v = (... && Bs); | |
template <bool... Bs> constexpr bool any_v = (... || Bs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------------------------------ "is there ?" | |
template <template <class> class P, class... Ts> | |
constexpr bool existential_quantifier = any_v<P<Ts>::value...>; | |
// ----------------------------------------- "are all ?" | |
template <template <class> class P, class... Ts> | |
constexpr bool universal_quantifier = all_v<P<Ts>::value...>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class... Ts> | |
constexpr bool are_tc = universal_quantifier<std::is_trivially_copyable, Ts...>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T1, class T2> | |
using is_smaller = std::integral_constant<bool, sizeof(T1) < sizeof(T2)>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <template <class...> class C, class...Ts> | |
struct curry | |
{ | |
template <class T> | |
using type = C<Ts..., T>; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct S0 {}; | |
struct alignas(2) S1 {}; | |
struct alignas(4) S2 {}; | |
struct alignas(8) S3 {}; | |
int main() | |
{ | |
static_assert(universal_quantifier<curry<is_smaller, S0>::type, S1, S2, S3>); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class...> struct conjunction : std::true_type { }; | |
template<class B1> struct conjunction<B1> : B1 { }; | |
template<class B1, class... Bn> | |
struct conjunction<B1, Bn...> | |
: std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {}; | |
template<class...> struct disjunction : std::false_type { }; | |
template<class B1> struct disjunction<B1> : B1 { }; | |
template<class B1, class... Bn> | |
struct disjunction<B1, Bn...> |