Last active
December 5, 2020 01:38
-
-
Save asit-dhal/b594b5ca0c56df7ca60920f2e1b77e78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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