Enough TMP to write a variant

Denis Yaroshevskiy

So what's this about?

tinyurl.com/enoughtmp2022

std::variant usage

std::variant usage

variant pseudocode

          
template <typename ...Ts>
struct variant {
  union { Ts ... elems; } data;

  index_type idx;
};

auto visit(auto&& vis, auto&& ... vs) {
  switch ( ... )  {
    case 0: return vis(get<0>(vs) ....);
    case 1: ...
    ...
  }
};
          
        

TMP utilities

find_type_idx

uint_at_least

get_type_t

instance_of

FWD

union_

union_

switch_

switch_ (goal)

switch_ (v1)

switch_ (v2 idea)

switch_ (v2)

switch_ (v3)

Visit Runtime

Goal

c_array_math

Visit signature

  • return type
  • noexcept
  • concept friendliness

concept friendliness

common_type_t

one case result

visit result/visit

variant

Total Godbolt

Links