Boost logo

Boost Users :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2008-01-07 18:31:24


Joel de Guzman wrote:
> Anyway, I agree with you, not in the standpoint of what is
> a better API, but in the standpoint of practicality.

Yep. I can follow your perspective: The only logical outcome of a switch
operation is in fact a union type.

Besides the efficiency aspect, the devil is in the details: The default
constructor's semantics of Variant, the trade-off between 'variant' and
'any', and syntactic inconsistency vs. clutter in case there's just one
type...

> Many languages do switch the /variant/ way.

In a lot of programming languages (especially dynamically typed ones)
variants are a much more of a natural thing than they are in C++. What
you call "the variant way" (or should I say the "optional variant way")
is often just "the way variables work".

Perl did not even have a switch statement until Version 5.10 -- you'd
simply "bend the syntax to switch":

     http://ipserve.com/school/public/perl/perlsyn.htm#perlsyn_basic_0

Ruby has similar, though somewhat more expressive and goal-oriented
constructs.

We probably shouldn't tell programmers with native languages like these
about 'get', 'variant', 'any' and 'optional' ;-)...

Regards,
Tobias


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net