::type* = 0 // disable if value has type `any&` , typename boost::disable_if<boost::is_const<ValueType> >::type* =
Hi, boost::any has a perfect forward constructor declared as: template<typename ValueType> any(ValueType&& value , typename boost::disable_if<boost::is_same<any&, ValueType> 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 constant value than what the perfect forward construct would do if the is_const exclusion were removed? Thanks, David
2016-02-16 0:31 GMT+03:00 David <list@aue.org>:
Hi,
boost::any has a perfect forward constructor declared as:
::type* = 0 // disable if value has type `any&` , typename boost::disable_if<boost::is_const<ValueType> >::type* =
template<typename ValueType> any(ValueType&& value , typename boost::disable_if<boost::is_same<any&, ValueType> 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 constant value than what the perfect forward construct would do if the is_const exclusion were removed?
Regular copy constructor has been there before the perfect forwarding constructor. When perfect forwarding constructor was added, the idea was to enable it *only* when the value could be moved (to avoid ambiguity). So it was disabled for all the const ValueType&& and const ValueType. The difference with regular copy constructor is in remove_cv. -- Best regards, Antony Polukhin
participants (2)
-
Antony Polukhin
-
David