方法声明后的xvalue和const引用

时间:2016-02-01 23:02:41

标签: c++

我在STL的可选(experimental/optional)实现中找到了以下代码:

template <class _Up>
_LIBCPP_INLINE_VISIBILITY
constexpr value_type value_or(_Up&& __v) const&
{
    static_assert(is_copy_constructible<value_type>::value,
                  "optional<T>::value_or: T must be copy constructible");
    static_assert(is_convertible<_Up, value_type>::value,
                  "optional<T>::value_or: U must be convertible to T");
    return this->__engaged_ ? this->__val_ :
                              static_cast<value_type>(_VSTD::forward<_Up>(__v));
}

template <class _Up>
_LIBCPP_INLINE_VISIBILITY
value_type value_or(_Up&& __v) &&
{
    static_assert(is_move_constructible<value_type>::value,
                  "optional<T>::value_or: T must be move constructible");
    static_assert(is_convertible<_Up, value_type>::value,
                  "optional<T>::value_or: U must be convertible to T");
    return this->__engaged_ ? _VSTD::move(this->__val_) :
                              static_cast<value_type>(_VSTD::forward<_Up>(__v));
}

具体而言,请注意const&&& 遵循方法规范的方式。我认为我从未见过以这种方式应用的那些,所以他们的意思是什么?

0 个答案:

没有答案
相关问题