这是相关代码:
// 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)))
{
}
Run Code Online (Sandbox Code Playgroud)
据我所知,可以使用复制构造函数从const &&构造.我使用boost 1.55.0.
这是对https://svn.boost.org/trac/boost/ticket/9215的修复:
any
调用构造函数时的无限循环const any&&
Run Code Online (Sandbox Code Playgroud)#include <boost/any.hpp> #include <string> const boost::any getBoolVal() { return false; } int main() { boost::any vals[] = {1.0, std::string("1m"), getBoolVal()}; }
所以看起来意图是any const&&
从转发构造函数中排除; 它排除所有const
rvalues 这一事实是副作用,无害,因为它们将由ValueType const&
复制构造函数处理.
就个人而言,我本来会去的
typename disable_if<is_same<any,
typename remove_cv<typename remove_reference<ValueType>::type>::type>>::type
Run Code Online (Sandbox Code Playgroud)
这也正确地处理了volatile
右撇子 - 而不是我见过的其中一个肉体.
归档时间: |
|
查看次数: |
149 次 |
最近记录: |