Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <thread>
- #include <functional>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <cassert>
- #include <sstream>
- struct Value {
- virtual std::string ToString() const = 0;
- virtual ~Value() {}
- };
- struct Int : public Value {
- Int(int value) : value(value) {}
- std::string ToString() const override {
- return std::to_string(value);
- }
- int value;
- };
- struct List : public Value {
- std::string ToString() const override {
- std::stringstream ss;
- ss << "[";
- for (const auto& e : list) {
- ss << e->ToString() << ", ";
- }
- ss << "]";
- return ss.str();
- }
- std::vector<std::unique_ptr<Value>> list;
- };
- int main() {
- auto l1 = std::make_unique<List>();
- l1->list.emplace_back(std::make_unique<Int>(5));
- auto l2 = std::make_unique<List>();
- l2->list.emplace_back(std::make_unique<Int>(2));
- l2->list.emplace_back(std::move(l1));
- std::cout << l2->ToString() << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement