Ignoring the obvious readability flaws in this mechanism, it doesn't actually work. Consider the following:
template<labdified_concept T>
void foo(T t) {}
template<typename T>
void foo(T t) {}
The rules of concepts tell us that if a given T
doesn't satisfy labdified_concept
, then the other foo
should be instantiated instead. But that's not what happens if we provide SS
to such a template. Instead, we get a hard error because labdified_concept<SS>
cannot be instantiated.
The stuff within a requires
expression has special handling that allows certain types of errors to be regarded as failures to meet the requirement. But that handling doesn't apply to the body of a lambda. There, ill-formed code is ill-formed and thus you get a compile error when trying to instantiate it.
And even if it did work, it still doesn't work. Concepts have complex rules for subsumption of concepts, which allows different concepts to be considered more highly specialized than others. This allows overloading on different concepts, which lets the more constrained concept get called. For example a concept that only requires default_initializable
is more generic than one which requires default_initializable
and moveable
. Thus, if a type fulfills both, the latter will be taken because it is more constrained.
But this only works because of the special rules for concept
s. Hiding requirements in lambdas wouldn't allow this to work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…