|
Boost : |
Subject: Re: [boost] [variant] Opinion on boost::safe_get<> and default boost::get<> behavior
From: David Stone (david_at_[hidden])
Date: 2014-12-10 09:57:36
I see no reason to allow code that is always a bug.
There are two possibilities here:
1) The user is expecting the object of that type to be there, but used the
wrong type. This is the example Matt Calabrese gave: the variant contains
long but I accidentally used int. This is a bug.
2) The user is wondering whether the type is there and is trying to get it
if it is. Perhaps they are checking multiple types in sequence. However,
this is a performance bug if the compiler cannot remove the "never going to
work" code. Even if the compiler can remove the code, people reading it
might not be able to do so mentally. Now you have code that will never
execute, but all readers of your code assume it will (or why would you have
written it)? I have worked on code bases with lots of code like this, and I
have never once appreciated the misleading rabbit holes this sends me down
during debugging.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk