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... Args> | |
class sorted_view | |
{ | |
std::tuple<Args...> _ts; | |
mutable std::vector<std::size_t> _is; | |
public: | |
sorted_view(Args&&... args); | |
// sort based on the Ith sequence | |
template <std::size_t I, class F> void sort(F&& bop) const; |
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 T, template <class> class... Ps> | |
constexpr bool satisfies_all_v = std::conjunction<Ps<T>...>::value; | |
template <class T, template <class> class... Ps> | |
constexpr bool satisfies_any_v = std::disjunction<Ps<T>...>::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<typename T> concept bool Data = requires(T t) { t.data; }; | |
template<Data... Ts> | |
requires existential_quantifier<std::is_move_constructible, Ts...> | |
auto f(Ts... ts) | |
{ | |
std::cout << "version for data\n"; | |
return 0; | |
} |
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
// ----------------------------------------------------------- | |
// -------------------- to express "1 predicate Vs many types" | |
template <template <class> class P, class... Ts> | |
concept bool existential_quantifier = any_v<P<Ts>::value...>; | |
template <template <class> class P, class... Ts> | |
concept 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...> 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...> |
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 <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
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 <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
// ------------------------------------ "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...>; |