Skip to content

soldat13/ccHS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Xisor hide

int main() { std::variant<int, float> v, w; v = 12; // v contains int int i = std::get(v); w = std::get(v); w = std::get<0>(v); // same effect as the previous line w = v; // same effect as the previous line

// std::get(v); // error: no double in [int, float] // std::get<3>(v); // error: valid index values are 0 and 1

try {
  std::get<float>(w); // w contains int, not float: will throw
}
catch (const std::bad_variant_access&) {}

std::variant<std::string> x("abc"); // converting constructors work when unambiguous
x = "def"; // converting assignment also works when unambiguous

std::variant<std::string, bool> y("abc"); // casts to bool when passed a char const *
assert(std::holds_alternative<bool>(y)); // succeeds
y = "xyz"s;
assert(std::holds_alternative<std::string>(y)); //succeeds

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published