Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <initializer_list>
- #include <vector>
- #include <tuple>
- struct Tag;
- struct Tag {
- Tag(const std::string& name, const std::string& text): name(name), text(text) {
- }
- Tag(const std::string& name, std::vector<Tag> children): name(name), children(children) {
- }
- std::vector<Tag> children;
- std::string name;
- std::string text;
- };
- std::ostream& operator<<(std::ostream& os, const Tag& tag) {
- os << "<" << tag.name << ">" << tag.text;
- for (const auto& child: tag.children) {
- os << child;
- }
- os << "</" << tag.name << ">";
- return os;
- }
- struct P: Tag {
- P(const std::string& text): Tag("p", text) {};
- P(std::initializer_list<Tag> tags): Tag{"p", tags} {};
- };
- int main() {
- Tag root = P {
- P {
- P {
- "Hello"
- }
- }
- };
- std::cout << root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement