Add test/get_by_type(_cx).cpp, get_by_index_cx.cpp

This commit is contained in:
Peter Dimov
2017-05-30 02:08:31 +03:00
parent 781977a237
commit 07be071794
5 changed files with 342 additions and 5 deletions
+4 -4
View File
@@ -142,7 +142,7 @@ template<class U, class... T> constexpr U& get(variant<T...>& v)
static_assert( mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
constexpr auto I = mp_find<variant<T...>, U>::value;
return v.index() == I? v._get_impl( mp_size_t<I>() ): throw bad_variant_access();
return ( v.index() == I? (void)0: throw bad_variant_access() ), v._get_impl( mp_size_t<I>() );
}
template<class U, class... T> constexpr U&& get(variant<T...>&& v)
@@ -150,7 +150,7 @@ template<class U, class... T> constexpr U&& get(variant<T...>&& v)
static_assert( mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
constexpr auto I = mp_find<variant<T...>, U>::value;
return v.index() == I? std::move( v._get_impl( mp_size_t<I>() ) ): throw bad_variant_access();
return ( v.index() == I? (void)0: throw bad_variant_access() ), std::move( v._get_impl( mp_size_t<I>() ) );
}
template<class U, class... T> constexpr U const& get(variant<T...> const& v)
@@ -158,7 +158,7 @@ template<class U, class... T> constexpr U const& get(variant<T...> const& v)
static_assert( mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
constexpr auto I = mp_find<variant<T...>, U>::value;
return v.index() == I? v._get_impl( mp_size_t<I>() ): throw bad_variant_access();
return ( v.index() == I? (void)0: throw bad_variant_access() ), v._get_impl( mp_size_t<I>() );
}
template<class U, class... T> constexpr U const&& get(variant<T...> const&& v)
@@ -166,7 +166,7 @@ template<class U, class... T> constexpr U const&& get(variant<T...> const&& v)
static_assert( mp_count<variant<T...>, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" );
constexpr auto I = mp_find<variant<T...>, U>::value;
return v.index() == I? std::move( v._get_impl( mp_size_t<I>() ) ): throw bad_variant_access();
return ( v.index() == I? (void)0: throw bad_variant_access() ), std::move( v._get_impl( mp_size_t<I>() ) );
}
// get_if