Skip to content

Instantly share code, notes, and snippets.

@asit-dhal
Created December 4, 2020 21:29
Show Gist options
  • Save asit-dhal/7f0b2215c01ac5db4606b8cc84eb797a to your computer and use it in GitHub Desktop.
Save asit-dhal/7f0b2215c01ac5db4606b8cc84eb797a to your computer and use it in GitHub Desktop.
template<std::size_t idx> auto get(const B &b)
{
static_assert (idx < 4);
if constexpr (idx == 0) {
return b.a;
} else if constexpr (idx == 1) {
return b.c;
} else if constexpr (idx == 2) {
return b.d;
} else {
return b.e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment