Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of introducing std::web_view facility into the standard?

Tags:

c++

c++20

According to latest meeting of The Library Evolution Incubator, one of the facilities which gain strong support is std::web_view.

The proposal is described in P1108R2 and will be used to

enables modern, natural, multimodal user interaction by leveraging existing web standards and technologies.

std::web_view w("web_view test app");
  w.set_uri_scheme_handler("wv", [&](const std::string &uri, std::ostream &os) {
    std::cout << "request: " << uri << "\n";
    os << "<html><head><title>" << uri << "</title></head><body><p>" << uri << "</p><table>";
    for (auto &a : args)
      os << "<tr><td>" << a << "</td></tr>" << "\n"; // we need some kind of "to_html" utility function.
    os << "</table>";
    os << "<p><a href=\"" << uri << "/more.html" << "\">more</a></p>";
    os << "<ul id='dl'></ul>";
    os << "</body></html>";

From what I can see from proposed example, the design will basically emits JavaScript/HMTL code.

I don't have a proper understanding of what benefits this approach will generate. Can somebody offer a more in-depth view of this facility?

like image 818
bogdan tudose Avatar asked Nov 06 '22 15:11

bogdan tudose


1 Answers

I will first answer this question in the correct, StackExchange manner. The document you linked states its motivations quite clearly in the Introduction section:

Reality is that most users do not interact with applications using a command prompt (i.e., console I/O), but rather, use some graphical user interface. The C++ standard, however, provides no useful facilities in this regard, and as a result, users either need to make use of system-specific APIs, third-party libraries, or move to a different programming language.

[...]

Unfortunately, this committee has neither the time nor the expertise to address this problem by directly creating some sufficiently-comprehensive API. [...] The only feasible way forward is to reach out to the large and vibrant community tackling this issue, creating portable standards in this space, and make direct use of their efforts.

So, in short, C++ community does not have enough resources (people and expertise) to implement complete GUI and high-level services library. After all, I myself can only mention one C++ GUI library that rivals power of HTML+JS in terms of features, which is the Qt library.

Now I would like to also like to add more opinionated part of the answer, since the question kinda asked for it. Even without JavaScript, HTML and CSS are quite powerful in terms of displaying what you want in a few lines of code. They present a widely known framework of displaying things. In most other GUI frameworks, you will also encounter HTML in "HTML Panels", usually when trying to render formatted text.

The fact that HTML+JavaScript allow beginners to have a visually interesting result after programming just for a while is also quite important. Starting a GUI application in C++ without previous knowledge of programming is not easy - you need to get and build a GUI framework. If we made it possible for beginners to render their programs written in C++ through HTML, the community might grow.

like image 99
Tomáš Zato - Reinstate Monica Avatar answered Nov 15 '22 05:11

Tomáš Zato - Reinstate Monica