Boost logo

Boost :

Subject: [boost] [variant] Opinion on boost::safe_get<> and default boost::get<> behavior
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-12-09 11:58:28


Hi all,

I'm in doubt and would like to hear opinions on the following issue.

boost::get for boost::variant was not making any compile time checks,
resulting in runtime errors where a compile time error must be:

boost::variant<int, string> v(100);
boost::get<bool>(&v); // returns NULL instead of compile time error
boost::get<bool>(v); // throws exception on runtime instead of compile
time error

Now we have an implementation of compile time checked get in a separate
branch at git:

boost::variant<int, string> v(100);

boost::safe_get<bool>(&v); // compile time error
boost::safe_get<bool>(v); // compile time error
boost::unsafe_get<bool>(&v); // returns NULL instead of compile time error
boost::unsafe_get<bool>(v); // throws exception on runtime instead of
compile time error

I'm in doubt, what the default behavior of boost::get must be:
* safe_get behavior is much closer to Standard Library behavior (just like
std::get for tuples) and allows to avoid errors in user code
* unsafe_get behavior is same as behavior of old boost::get and won't break
user's code if boost::get is used in some generic contexs

What's your opinion?

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk