what's the best way to define a concept with a nested concept requirements for a data member of the type? Something along these lines:
template<typename T>
concept MyConcept = requires(T a) {
{a.something} -> std::integral;
};
This doesn't work because a.something is picked up as a reference (delctype((a.something))). The best I came up with that works is something like this that forces an rvalue:
constexpr auto copy = [](auto value) { return value; };
template<typename T>
concept MyConcept = requires(T a) {
{copy(a.something)} -> std::integral;
};
Do I have any better options?
The downside of copy is that it can create false positives for you. A reference member will decay to a value. The only way to ensure the actual type of the member is analyzed, is to write an explicit nested requirement.
template<typename T>
concept MyConcept = requires(T a) {
requires std::integral<decltype(a.something)>;
};
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