I have a collection of concepts:
template <typename type_t>
concept boolean_c = std::is_same_v<std::decay_t<type_t>, bool>;
template <typename type_t>
concept integer_c = !boolean_c<type_t> && std::is_integral_v<std::decay_t<type_t>>;
…
…
…
template <typename type_t>
concept number_c = std::is_floating_point_v<std::decay_t<type_t>>;
template <typename type_t>
concept string_c = std::is_same_v<std::decay_t<type_t>, std::string>;
And I want a new concept that checks if a given type matches any concept of a given list of the previously defined concepts. So I guess that a template-template parameter is mandatory:
template <typename type_t, template<typename> class ... concept_pack>
concept any_of_c = (concept_pack<type_t> || ...);
template <typename type_t>
concept compatible_type_c = any_of_c<type_t, boolean_c, integer_c, number_c, string_c>;
I need the compatible_type_c
to ve a variadic template because I'll use it to check std::tuple
s and std::variant
s. The code above does not compile:
<source>:17:45: error: expected ')'
concept any_of_c = (concept_pack<type_t> || ...);
^
<source>:17:20: note: to match this '('
concept any_of_c = (concept_pack<type_t> || ...);
^
<source>:17:49: error: expected expression
concept any_of_c = (concept_pack<type_t> || ...);
^
<source>:20:46: error: too few template arguments for concept 'boolean_c'
concept compatible_type_c = any_of_c<type_t, boolean_c, integer_c, number_c, string_c>;
I wasn't able to write the any_of_c
in a way that the compiler understands (I've tried with and without parenthesis and different placement of the elipsis) and the compatible_type_c
asks for template parameter even if I've specified that it is a template.
How should I write the code in order to achieve my goal?