Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Apr 5, 2023
1 parent 20fab74 commit 4fa0607
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions include/SSVOpenHexagon/Utils/TinyVariant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
#include <initializer_list> // TODO: remove dependency?
#include <new> // TODO: remove dependency?

#if !__has_builtin(__make_integer_seq) && !__has_builtin(__integer_pack)
#if __has_builtin(__make_integer_seq)
#define TINYVARIANT_USE_MAKE_INTEGER_SEQ
#elif __has_builtin(__integer_pack)
#define TINYVARIANT_USE_INTEGER_PACK
#else
#define TINYVARIANT_USE_STD_INDEX_SEQUENCE
#endif

#ifdef TINYVARIANT_USE_STD_INDEX_SEQUENCE
#include <utility>
#endif

Expand Down Expand Up @@ -38,7 +46,7 @@ struct common_type_between<T, U, Rest...>

using sz_t = decltype(sizeof(int));

#if !__has_builtin(__make_integer_seq) && !__has_builtin(__integer_pack)
#ifdef TINYVARIANT_USE_STD_INDEX_SEQUENCE

template <sz_t... Is>
using index_sequence = std::index_sequence<Is...>;
Expand All @@ -51,7 +59,7 @@ struct index_sequence

#endif

#if __has_builtin(__make_integer_seq)
#ifdef TINYVARIANT_USE_MAKE_INTEGER_SEQ

template <typename, sz_t... X>
struct index_sequence_helper
Expand All @@ -63,16 +71,20 @@ template <sz_t N>
using index_sequence_up_to =
typename __make_integer_seq<index_sequence_helper, sz_t, N>::type;

#elif __has_builtin(__integer_pack)
#elif defined(TINYVARIANT_USE_INTEGER_PACK)

template <sz_t N>
using index_sequence_up_to = index_sequence<__integer_pack(N)...>;

#else
#elif defined(TINYVARIANT_USE_STD_INDEX_SEQUENCE

template <sz_t N>
using index_sequence_up_to = std::make_index_sequence<N>;

#else

#error "No integer sequence generation available."

#endif

template <typename, typename>
Expand Down Expand Up @@ -711,4 +723,8 @@ class [[nodiscard]] tinyvariant
#undef TINYVARIANT_DO_WITH_CURRENT_INDEX
#undef TINYVARIANT_STATIC_ASSERT_INDEX_VALIDITY

#undef TINYVARIANT_USE_STD_INDEX_SEQUENCE
#undef TINYVARIANT_USE_INTEGER_PACK
#undef TINYVARIANT_USE_MAKE_INTEGER_SEQ

} // namespace vittorioromeo

0 comments on commit 4fa0607

Please sign in to comment.