gpt4 book ai didi

c++ - boost::is_nothrow_move_constructible 实现

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:20:37 24 4
gpt4 key购买 nike

我正在试用新的 VS 2015 预览版,但我在使用 Boost 时遇到了一些问题。但是在跟踪问题之后,我不明白它是如何任何编译器上工作的。

我有一个 unordered_map<K, boost::variant<std::unordered_map<int, std::unique_ptr<T>>>> .这无法编译,因为 boost::variant显然试图复制构建 unordered_map在里面——基于 boost::is_nothrow_move_constructible 的结果特质,这确实是 boost::false_type .

这揭示了 boost::is_nothrow_move_constructible 的定义作为

template <class T>
struct is_nothrow_move_constructible_imp{
BOOST_STATIC_CONSTANT(bool, value =(
::boost::type_traits::ice_and<
::boost::type_traits::ice_or<
::boost::has_trivial_move_constructor<T>::value,
::boost::has_nothrow_copy<T>::value
>::value,
::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value
>::value));
};

呃,像很多很多类一样,非平凡的 noexcept 移动构造函数怎么样?这个定义如何在其他编译器上起作用?

最佳答案

事实证明,这里真正令人困惑的是它从未在 Visual Studio 上运行过。我想这一定只是 optional 而不是 variant 我之前使用的是 move-only 类型。对于任何当前版本,variant 似乎无法有效地支持 Visual Studio 上的仅移动类型,而且我对它在 VS2013 上工作的内存显然是错误的。

我最终只是针对我正在使用的类型专门化了特征。 Hacky 但实用。

关于c++ - boost::is_nothrow_move_constructible 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26897879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com