Skip to content

Instantly share code, notes, and snippets.

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