Here is the relevant code:
// Perfect forwarding of ValueType
template<typename ValueType>
any(ValueType&& value
, typename boost::disable_if<boost::is_same<any&, ValueType> >::type* = 0 // disable if value has type `any&`
, typename boost::disable_if<boost::is_const<ValueType> >::type* = 0) // disable if value has type `const ValueType&&`
: content(new holder< typename decay<ValueType>::type >(static_cast<ValueType&&>(value)))
{
}
For all I know, a copy constructor could be used to construct from a const&&. I use boost 1.55.0.
This is a fix for https://svn.boost.org/trac/boost/ticket/9215:
Infinite loop when
any
constructor called forconst any&&
#include <boost/any.hpp> #include <string> const boost::any getBoolVal() { return false; } int main() { boost::any vals[] = {1.0, std::string("1m"), getBoolVal()}; }
So it looks like the intent is to exclude any const&&
from the forwarding constructor; the fact that it excludes all const
rvalues is a side effect, harmless because those will be handled by the ValueType const&
copying constructor.
Personally, I would have gone for
typename disable_if<is_same<any,
typename remove_cv<typename remove_reference<ValueType>::type>::type>>::type
which correctly handles volatile
rvalues as well - not that I've ever seen one of those in the flesh.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With