3 ms·
> As I see it, the foo template function uses structural typing, because the required set of properties of F are explicitly specified (in this case with name "C
by LegionMammal978 2y ago
> As I see it, the foo template function uses structural typing, because the required set of properties of F are explicitly specified (in this case with name "CanDouble"). Two operations, t + t and t * 2, must be defined for F.
Isn't that still duck typing? If the type "walks like a duck" with respect to those two operations, then the concept will automatically be satisfied, even if the type knows nothing about the concept. Or, if I create two different concepts with the same requirements:
template<typename T> concept CanDouble = requires(T t) { t + t; t * 2; };
template<typename T> concept CanTrouble = requires(T t) { t + t; t * 2; };
then they'll be satisified by exactly the same set of types: you can't satisfy one without satisfying the other. So I don't think there's really much 'structure' in either case, the concept is really just acting as an alias for the duck-properties. For structural interfaces in C++, you need base classes or specialization or other such constructs.