Little library to support access to C++17 type-safe union types - std::variant and std::any.
Library provides two macros:
typeswitch([variant|any])- analogue to C++switch. Break statement works but you should not use it to prevent fallthrough (this library does not support this feature of C++ switch).typecase(type, name)- If type is holdednameis reference to holded type and code after is executed. Should be followed by single statement or compound statement.
std::variant<int, std::string> variant;
typeswitch (variant) {
typecase(int, val): std::cout << "I'm holding int of value: " << val << '\n';
typecase(std::string, str):
std::cout << "I'm holding std::string of value: " << std::quoted(str) << '\n';
}- add constexpr compatibility for std::variant access
This code is distributed under the MIT license. See LICENSE for details.