Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <variant>
- #include <vector>
- struct Node;
- using Value=std::variant<std::nullptr_t,int, std::string, std::vector<Node>>;
- struct Node {
- Value value{};
- };
- std::ostream& operator<<(std::ostream& out, Value const& v) {
- if (std::holds_alternative<int>(v)) {
- out << std::get<int>(v);
- } else {
- out << "some text";
- }
- return out;
- }
- auto main() -> int {
- Node root;
- std::vector<Node*> stack{&root};
- int val = 42;
- auto& GetVal = stack.back();
- if (!std::holds_alternative<std::nullptr_t>(GetVal->value)) {
- throw std::logic_error("oi - vei! vse propalo!!");
- }
- GetVal->value = val;
- stack.pop_back();
- std::cout << root.value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement