Skip to content

Commit

Permalink
#821: util: call the helper function properly
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed May 22, 2020
1 parent 73521c7 commit 04161a5
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/vt/utils/adt/union.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct Aligner<T> {

///////////////////////////////////////////////////////////////////////////////

/// Assert that \c T is included in \c Us
/// Used to assert that \c T is included in \c Us
template <typename T, typename... Us>
struct MustBe;

Expand All @@ -97,8 +97,16 @@ struct MustBe<T> {
};

///////////////////////////////////////////////////////////////////////////////
// Turn a pack into a \c char and indicates order in the pack for selection

template <typename... Us>
struct GetPlace {
static constexpr char const value = sizeof...(Us) + 1;
};

///////////////////////////////////////////////////////////////////////////////
/// Find the place of a given \c T inside a pack \c U, Us...

/// Turn a pack into a \c char that indicates which one is active
template <typename T, typename U, typename... Us>
struct Which;

Expand All @@ -118,12 +126,6 @@ struct WhichImpl<T, U, typename std::enable_if_t<not std::is_same<T,U>::value>,
template <typename T, typename U, typename... Us>
struct Which : WhichImpl<T, U, void, Us...> { };

///////////////////////////////////////////////////////////////////////////////

template <typename U, typename... Us>
struct GetPlace {
static constexpr char const value = sizeof...(Us) + 1;
};

///////////////////////////////////////////////////////////////////////////////

Expand All @@ -132,7 +134,7 @@ template <typename T, typename... Ts>
struct Deallocate {
template <typename U>
static void apply(char which, U* u) {
if (which == static_cast<char>(sizeof...(Ts) + 1)) {
if (which == GetPlace<Ts...>::value) {
u->template deallocateAs<T>();
} else {
Deallocate<Ts...>::apply(which, u);
Expand All @@ -158,7 +160,7 @@ struct Deallocate<T> {
template <typename T, typename... Ts>
struct Copy {
static void apply(char which, char const* from, char* to) {
if (which == static_cast<char>(sizeof...(Ts) + 1)) {
if (which == GetPlace<Ts...>::value) {
new (to) T{*reinterpret_cast<T const*>(from)};
} else {
Copy<Ts...>::apply(which, from, to);
Expand All @@ -183,7 +185,7 @@ struct Copy<T> {
template <typename T, typename... Ts>
struct Move {
static void apply(char which, char* from, char* to) {
if (which == static_cast<char>(sizeof...(Ts) + 1)) {
if (which == GetPlace<Ts...>::value) {
new (reinterpret_cast<T*>(to)) T{std::move(*reinterpret_cast<T*>(from))};
} else {
Move<Ts...>::apply(which, from, to);
Expand Down

0 comments on commit 04161a5

Please sign in to comment.