Re: Non-type Concept Parameters
On 31 Mai, 17:19, Scott Meyers <use...@aristeia.com> wrote:
I'm trying to get a handle on what can be done with non-type concept
parameters.
[...]
Does it make sense to have a concept for ints? For example,
concept MultipleOf<int v, int n> {};
template<typename T, int V>
requires MultipleOf<V, 2>
class Widget { ... };
If so, would I have to set up a concept map manually for every
qualifying value?
concept_map MultipleOf<2, 2> {};
concept_map MultipleOf<4, 2> {};
concept_map Multipleof<6, 2> {};
....
Alternatives:
template<int v, int n>
requires std::True<(v % n == 0)>
concept_map MultipleOf<v,n> {}
Or even better without concept maps:
auto concept MultipleOf<int v, int n> {
requires std::True<(v % n == 0)>;
}
std::True is an example of a non-type concept that is part of the
proposed standard:
concept True<bool> {}
concept_map True<true> {}
If so, it looks to me like a static_assert somewhere would be a much
better approach.
For a class tempate it might not matter. But a requires clause of a
function template can prevent a specialization form being part of the
overload set. A static_assert within the function template's body
could lead to ambiguities w.r.t. overload resolution even though a
specialization that's part of the overload set might not compile due
to a failing static_assert.
Cheers!
SG
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]