boost::optional对布尔值的隐式投射是否消失了?
Did boost::optional's implicit cast to bool go away?
我开始移植vc++10/boost 1.48代码库到vc++12/boost 1.57,我得到一个错误,boost::optional不能转换为bool。我以为这是boost::可选的功能,它被删除了吗?
的例子:
bool fizz(){
boost::optional<int32_t> buzz;
return buzz;
}
为
Error 21 error C2440: 'return' : cannot convert from 'boost::optional<int32_t>' to 'bool'
是。Boost 1.55仍然使用安全Bool习惯用法:
// implicit conversion to "bool"
// No-throw
operator unspecified_bool_type() const { return this->safe_bool() ; }
Boost 1.56, Boost 1.57和Boost 1.58现在使用这个宏:
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
大致是:
#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
我猜你没有定义BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
-因为你的编译器支持显式转换操作符,你应该保持这种方式!
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- cmath 是否借用了 math.h 的实现
- 检查是否安装了 windows10 C++
- sprintf(b, "%" ) 是否定义了?
- 它是否定义了哪些算法可以接受可变 lambda 的实现?
- std::bind 是否实现了 std::ref 和 std::cref 来消除函数调用的歧义?
- VS2017 是否更改了 C++ 中访问 C# 命名空间的方式?
- C++编译器是否优化了顺序静态变量读取?
- 我是否漏了记忆?
- 我是否访问了已释放的内存,或者在这种情况下DrMemory报告不正确?
- 如何检查是否定义了固定宽度的整数
- 如何检查用户是否输入了元音字符?
- 这是否错失了优化机会
- 如何检查在编译时是否调用了模板化方法?
- 是否启用了 SSE2 指令?
- c++标准是否指定了运算符&&(内置)的求值顺序?
- 检查cpp文件中是否使用了变量
- 流::seekoff 是否更新了输入序列
- 检测 Visual Studio 项目的属性中是否启用了英特尔 MKL
- boost::optional对布尔值的隐式投射是否消失了?