sel*_*ord 8 c++ boost optional
我开始将vc ++ 10/boost 1.48代码库移植到vc ++ 12/boost 1.57,我收到一个错误,boost :: optional无法转换为bool.我认为这是boost :: optional的一个特性,它被删除了吗?
例:
bool fizz(){
boost::optional<int32_t> buzz;
return buzz;
}
Run Code Online (Sandbox Code Playgroud)
给
Error 21 error C2440: 'return' : cannot convert from 'boost::optional<int32_t>' to 'bool'
Run Code Online (Sandbox Code Playgroud)
Bar*_*rry 10
是.Boost 1.55仍然使用了Safe Bool成语:
// implicit conversion to "bool"
// No-throw
operator unspecified_bool_type() const { return this->safe_bool() ; }
Run Code Online (Sandbox Code Playgroud)
Boost 1.56,Boost 1.57和Boost 1.58现在使用这个宏:
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
Run Code Online (Sandbox Code Playgroud)
这大致是:
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
explicit operator bool() const noexcept;
#else if !defined(BOOST_NO_UNSPECIFIED_BOOL)
operator boost::detail::unspecified_bool_type () const noexcept;
#else
operator bool () const noexcept;
#endif
Run Code Online (Sandbox Code Playgroud)
我猜你没有BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS定义 - 因为你的编译器支持显式转换运算符,你应该保持这种方式!
| 归档时间: |
|
| 查看次数: |
2793 次 |
| 最近记录: |