How would I write template or constexpr
code such that match
is true only if Ts
contains an instance of A
?
template <std::uint32_t, int, int>
struct A;
template <typename... Ts>
struct X
{
constexpr bool match = ???;
};
Another parameter we can pass is a template (as opposed to a type). This means that the parameter we pass is itself a template: template<template <typename T> typename Templ> class MyTemplateTemplateClass { // ... };
A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.
8. Why we use :: template-template parameter? Explanation: It is used to adapt a policy into binary ones.
A non-type template parameter must have a structural type, which is one of the following types (optionally cv-qualified, the qualifiers are ignored): lvalue reference type (to object or to function); an integral type; a pointer type (to object or to function);
Write a trait:
template<class>
struct is_A : std::false_type {};
template<std::uint32_t X, int Y, int Z>
struct is_A<A<X,Y,Z>> : std::true_type {};
Then use it:
template <typename... Ts>
struct X
{
constexpr bool match = std::disjunction_v<is_A<Ts>...>;
};
See cppreference for an implementation of std::disjunction
in C++11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With