Skip to content

Commit

Permalink
add optimized 'variant_alternative' implementation usinh built-in `__…
Browse files Browse the repository at this point in the history
…type_pack_element` when available (clang++)
  • Loading branch information
artemp committed Oct 20, 2017
1 parent 3ffef95 commit ae19314
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/mapbox/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,15 @@ ResultType const& get_unchecked(T const& var)
template <std::size_t Index, typename T>
struct variant_alternative;

#if (__clang__)
#if (__has_builtin(__type_pack_element))
template <std::size_t Index, typename ...Types>
struct variant_alternative<Index, variant<Types...>>
{
using type = __type_pack_element<Index, Types...>;
};
#endif
#else
template <std::size_t Index, typename First, typename...Types>
struct variant_alternative<Index, variant<First, Types...>>
: variant_alternative<Index - 1, variant<Types...>>
Expand All @@ -1043,6 +1052,7 @@ struct variant_alternative<0, variant<First, Types...>>

template <size_t Index, typename T>
using variant_alternative_t = typename variant_alternative<Index, T>::type;
#endif

} // namespace util
} // namespace mapbox
Expand Down

0 comments on commit ae19314

Please sign in to comment.