Subject: Re: [boost] [variant] Opinion on boost::safe_get<> and default boost::get<> behavior
From: Peter Dimov (lists_at_[hidden])
Date: 2014-12-09 13:31:03
Matt Calabrese wrote:
> While that's true, the old behavior seems about as compelling to me as if
> the language allowed you to static_cast between any two types, but yielded
> a null pointer at run-time if there were no valid conversion.
That's not true. Both get variants can fail (at runtime) if the variant
doesn't contain the target, so your code that uses either MUST be prepared
to deal with this case. The difference is only that one of them allows you
to ask "does this variant<X,Y> contain a Z?" (answering "no"), while the
other does not. But for the question "does this variant<X,Y> contain a X?",
in both cases, "no" is still a valid answer. If your code doesn't expect
"no" as an answer, it's broken, in either case.