Take a look at this snippet:
#include <iostream>
#include <string>
using namespace std;
template<const char* tag>
struct html_element {
string s;
template<typename... Args>
html_element(Args... args) : s((... + (string)args)) {}
operator string() { return string("<") + tag + ">" + s + "</" + tag + ">"; }
};
const char html_c[] = "html";
const char body_c[] = "body";
const char h2_c[] = "h2";
using html = html_element<html_c>;
using body = html_element<body_c>;
using h2 = html_element<h2_c>;
int main() {
string doc{
html{
body{
h2{ "hello" },
h2{ "world" }
}
}
};
cout << doc << '\n';
}
Thank you for your attention