Subject: Re: [boost] [variant] Opinion on boost::safe_get<> and default boost::get<> behavior
From: Peter Dimov (lists_at_[hidden])
Date: 2014-12-09 14:44:32
Gottlob Frege wrote:
> My gut feeling is that "does this variant<X, Y> contain a Z" should be a
> compile time error, because it obviously doesn't contain a Z. (Of course
> less obvious when variant<X,Y> is spelled 'T'.)
Or when it's spelled variant<T...>.
> And because it *can* be a compile time error.
Well yes, that is why we are having this discussion.
> In most C++ code, you need to go out of your way (eg dynamic_cast) to do
> type-stuff at runtime.
get<> ALWAYS does type-stuff at runtime. It's not going to get any less
runtimey. It's just going to catch a few (not very common) errors. It's
still a dynamic_cast; the equivalent of the strict get<> would be a
dynamic_cast that tells you, at compile time, "this cast will always fail,
don't do it." Which, in dynamic_cast's case, is - I suspect - going to be a
mixed blessing unless it's a warning, not an error.
That said, my recommendation still stands. Make get<> strict, see what
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk