
On 12/9/2012 8:11 AM, Peter Dimov wrote:
Vicente J. Botet Escriba wrote:
Le 08/12/12 15:20, Peter Dimov a écrit :
Vicente J. Botet Escriba wrote:
Hi,
https://svn.boost.org/trac/boost/changeset/81780 " Use explicit >> operator bool when available; ..." introduces a breaking change on >> shared_ptr in Boost.Thread and Boost.Test at least.
What code does it break?
Code like
bool thread::joinable() const BOOST_NOEXCEPT { return get_thread_info(); // COMPILE ERROR }
Yes, this is a bit unfortunate side effect of the language specification of "explicit operator bool". It does not get invoked in return statements such as the one above, and it does not get invoked when calling a function that takes a bool. The second case makes sense pragmatically, but the first doesn't. Still, the principle behind the specification is that an explicit operator bool is only invoked when a language construct such as if, while, or operator! needs a bool, and the above case is not one of those situations.
Since all of the standard library in C++11, including std::shared_ptr, has been specified to use explicit operator bool, and since the committee did not display any enthusiasm for changing this status quo in some way so that the code above could continue to work, I think that we better get used to it. :-)
which I have replaced by
bool thread::joinable() const BOOST_NOEXCEPT { return get_thread_info()!=0; }
Is there a better way?
I think that this way is fine.
FWIW I use: bool thread::joinable() const BOOST_NOEXCEPT { return !!get_thread_info(); } Jeff