2 ms·
> For example say you want to have a "first" operator that takes the first item of a container, but also works on individual values if they aren't containers:
by weland 11y ago
> For example say you want to have a "first" operator that takes the first item of a container, but also works on individual values if they aren't containers:
But why would I want to do such a thing? Not only does first() not make sense for non-container objects -- but calling x.first() when x is a non-container object is a bug 9 times out of 10 (i.e. something got unpacked when it shouldn't have, an [x] (a single-object vector) ended up x (i.e. the first and only value of that vector).
- MichaelGG 11y agoSFINAE looks like a cheap way to sort of hack around lack of static duck typing. Otherwise these examples could be written in a positive way by saying a certain function only applies to a type containing certain members or constraints.