3 ms·
> Yes that interface covers some edge cases that I've _never_ seen in practice (visiting two variants at once??), heh, this was literally one of my first uses
by jcelerier 5y ago
> Yes that interface covers some edge cases that I've _never_ seen in practice (visiting two variants at once??),
heh, this was literally one of my first uses of C++ variants: that job needed a generic set of mathematical functions in a way that emulated a weaker type system (with automated conversions left and right), while preserving the original types as far as possible, and did meaningful conversions otherwise e.g. more-or-less
using value = variant<int, float, string, vector<float>>;
value clamp(value x, value a, value b);
- afranchuk 5y agoAh yeah numeric sort of variants totally make sense for that! In all of my use cases they have been types that don't have operations defined among each other. But really I'd just appreciate the standard library providing at least a convenience function for the common case over their more powerful but obtuse std::visit.