For an expression E
in a compound requirement, the type constraint predicate is fed decltype((E))
1.
decltype
encodes the value category of the expression in the type it deduces. Since *p
is an lvalue expression. The deduced type is T&
for some T
.
So you may want to rewrite your pair of concepts as
template <typename T>
concept arithmetic_ref = std::is_arithmetic<std::remove_reference_t<T>>::value;
template <typename T>
concept pointer_to_arithmetic = requires (T a) {
{ *a } -> arithmetic_ref ;
};
The atomic predicate could probably be better named.
Of course, this leaves a couple of questions open. Are you just duck-typing, and so any pointer-like type (even std::optional
has operator*
) is permissible? Or are you after only fundamental pointer types? How should the concept treat cv-qualified types (it currently doesn't permit them)?
Depending on how you answer those questions, the concept could be tweaked further.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…