Skip to content

Instantly share code, notes, and snippets.

@boustrophedon
Last active April 4, 2018 00:40
Show Gist options
  • Save boustrophedon/0b6fb84aa72b24a38ff04eedd506f2ce to your computer and use it in GitHub Desktop.
Save boustrophedon/0b6fb84aa72b24a38ff04eedd506f2ce to your computer and use it in GitHub Desktop.
g++ -std=c++17 vartest.cpp -o vartest && ./vartest; echo $?
#include <variant>
#include <string>
#include <cassert>
using std::string;
int main() {
std::variant<bool, string> v = "hello";
try {
std::get<string>(v);
return 0;
}
catch (const std::bad_variant_access&){
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment