Skip to content

Instantly share code, notes, and snippets.

@jingzhehu
Last active July 14, 2018 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jingzhehu/8f36d60a40fba6924cf987654932dc24 to your computer and use it in GitHub Desktop.
Save jingzhehu/8f36d60a40fba6924cf987654932dc24 to your computer and use it in GitHub Desktop.
Scoped Enum (enum class)
// 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