1

boost::any has a perfect forward constructor declared as:

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)))
{}

The is_const<> SFINAE exclusion forces const types to the regular copy constructor:

template<typename ValueType>
any(const ValueType & value)
  : content(new holder<
        BOOST_DEDUCED_TYPENAME remove_cv<BOOST_DEDUCED_TYPENAME decay<const ValueType>::type>::type
    >(value))
{}

What is different about how the regular copy constructor treats a const value than what the perfect forward constructor would do if the is_const<> exclusion were removed?

tukra
  • 921
  • 8
  • 13

1 Answers1

0

The first one is specifically for rvalue refs (the enable_if ensures it).

The static_cast is synonymous for using std::move, so it would move.

sehe
  • 374,641
  • 47
  • 450
  • 633