Wpis z mikrobloga

mam strukture:

template
struct tagged_struct {
constexpr static auto S_TAG = TAG_VALUE;
};

oraz tuple struktur:

std::tuple, tagged_struct<15>> structs;
etc. I teraz chce policzyc w czasie kompilacji index w tupli na podstawie taga, cos takiego:

tag_to_index<15, decltype(structs)>::value
finalnie uzyc z get'em zeby pobrac element po tagu a nie indeksie:

std::get::value>(structs);
jakies pomysly jak do tego podejsc?

#programowanie #cpp
  • 8
  • Odpowiedz
@nargil: mam:
nie umiem formatowac kodu na wykopie :D kod tu dla potomnych: http://ideone.com/UwVu73

template::value - 1>
struct tag_to_index {
constexpr static auto value = std::tuple_element::type::S_TAG == TAG ? I : tag_to_index::value;
};

template
struct tag_to_index { constexpr static auto value = -1; };
  • Odpowiedz