Last active
July 14, 2018 18:14
-
-
Save jingzhehu/8f36d60a40fba6924cf987654932dc24 to your computer and use it in GitHub Desktop.
Scoped Enum (enum class)
This file contains 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
// item 10 - enum class | |
#include <iostream> | |
#include <string> | |
#include <thread> | |
#include <array> | |
template<typename E> | |
constexpr auto toUType(E enumerator) noexcept { | |
return static_cast<std::underlying_type_t<E>>(enumerator); | |
}; | |
int main (){ | |
using UserInfo = std::tuple<std::string, std::string, std::size_t>; | |
enum class UserInfoFields { uiName, uiEmail, uiReputation }; | |
UserInfo uInfo("Tester", "test@email.com", 190); | |
auto val = std::get<toUType(UserInfoFields::uiEmail)>(uInfo); | |
std::cout << val << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment