boost::is_nothrow_move_constructible implementation

boost::is_nothrow_move_constructible implementation

本文关键字:constructible implementation move nothrow is boost      更新时间:2023-10-16

我正在尝试新的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,我以前使用的是仅移动类型。variant似乎无法有效地支持Visual Studio上任何当前版本的仅移动类型,我对它在VS2013上工作的记忆显然是不正确的。

我最终只是针对我使用的类型专门化了这个特性。粗糙但实用。