May 2017
Intermediate to advanced
590 pages
17h 18m
English
Use the following operations to work with std::variant:
struct foo { int value; explicit foo(int const i) : value(i) {} }; std::variant<int, std::string, foo> v = 42; // holds int v.emplace<foo>(42); // holds foo
std::variant<int, double, std::string> v = 42; auto i1 = std::get<int>(v); auto i2 = std::get<0>(v); try { auto f = std::get<double>(v); } catch (std::bad_variant_access const & e) { std::cout << e.what() << std::endl; // Unexpected index }
std::variant<int, double, std::string> ...
Read now
Unlock full access