Skip to content

Commit

Permalink
universal-references: template <typename T> variant(T && val) {}
Browse files Browse the repository at this point in the history
it turned out we don't need a separate converting copy ctor (fixes windows compiler)
  • Loading branch information
artemp committed Sep 4, 2014
1 parent 54e1dfe commit 82df4ed
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,22 +514,13 @@ class variant
VARIANT_INLINE variant(no_init)
: type_index(detail::invalid_value) {}

// http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
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
}
Expand Down

0 comments on commit 82df4ed

Please sign in to comment.