I try to define a concept with a requires expression which checks some member function existence on the type.
The problem I run into is, that a single concept has to be plugged in for the return type check without any preceding bool operations like "not". This forces me to also write concepts for the inverse if needed, which is not really handy.
Is there something I am missing or another good way to do it?
Simple example:
template <typename …Run Code Online (Sandbox Code Playgroud) 我试图通过选择类构造函数来推导出 bool 模板参数。一个简单的例子:
template <typename A, bool Condition>
class Subrange {
public:
Subrange(A a) requires (not Condition); /* create Subrange<A, false> */
Subrange(A a, int b) requires (Condition); /* create Subrange<A, true> */
};
Run Code Online (Sandbox Code Playgroud)
这甚至可能还是必须在构造函数上明确指定条件?
PS:条件不依赖于A。