remove copy converting ctor and fix converting move constuctor to use 'universal reference' and perfect forwarding
( re : http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers)
This commit is contained in:
parent
c52994ff8b
commit
0985cc907d
1 changed files with 3 additions and 13 deletions
|
@ -541,21 +541,11 @@ public:
|
|||
: type_index(detail::invalid_value) {}
|
||||
|
||||
template <typename T, class = typename std::enable_if<
|
||||
detail::is_valid_type<T, Types...>::value>::type>
|
||||
VARIANT_INLINE explicit variant(T const& val) noexcept
|
||||
: type_index(detail::value_traits<T, Types...>::index)
|
||||
{
|
||||
constexpr std::size_t index = sizeof...(Types) - detail::value_traits<T, Types...>::index - 1;
|
||||
using target_type = typename detail::select_type<index, Types...>::type;
|
||||
new (&data) target_type(val);
|
||||
}
|
||||
|
||||
template <typename T, class = typename std::enable_if<
|
||||
detail::is_valid_type<T, Types...>::value>::type>
|
||||
detail::is_valid_type<typename std::remove_reference<T>::type, Types...>::value>::type>
|
||||
VARIANT_INLINE variant(T && val) noexcept
|
||||
: type_index(detail::value_traits<T, Types...>::index)
|
||||
: type_index(detail::value_traits<typename std::remove_reference<T>::type, Types...>::index)
|
||||
{
|
||||
constexpr std::size_t index = sizeof...(Types) - detail::value_traits<T, Types...>::index - 1;
|
||||
constexpr std::size_t index = sizeof...(Types) - detail::value_traits<typename std::remove_reference<T>::type, Types...>::index - 1;
|
||||
using target_type = typename detail::select_type<index, Types...>::type;
|
||||
new (&data) target_type(std::forward<T>(val)); // nothrow
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue