c++ - 将 std::web_view 工具引入标准有什么好处?

标签 c++ c++20

根据 The Library Evolution Incubator 的最新 session ,获得大力支持的设施之一是 std::web_view

提案在 P1108R2 中描述并将用于

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>";

从我提出的示例中可以看出,该设计基本上会发出 JavaScript/HMTL 代码。

我没有正确理解这种方法会产生什么好处。有人可以更深入地了解该设施吗?

最佳答案

我将首先以正确的 StackExchange 方式回答这个问题。您链接的文档在简介部分中非常清楚地说明了其动机:

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.

因此,简而言之,C++ 社区没有足够的资源(人员和专业知识)来实现完整的 GUI 和高级服务库。毕竟,我自己只能提到一个在功能上可以与 HTML+JS 匹敌的 C++ GUI 库,这就是 Qt 库。

现在我还想在答案中添加更多自以为是的部分,因为这个问题有点自问自答。即使没有 JavaScript,HTML 和 CSS 在几行代码中显示您想要的内容方面也非常强大。他们提出了一个广为人知的展示事物的框架。在大多数其他 GUI 框架中,您还会在“HTML 面板”中遇到 HTML,通常是在尝试呈现格式化文本时。

HTML+JavaScript 可以让初学者在编程一段时间后获得视觉上有趣的结果,这一点也很重要。在没有编程知识的情况下使用 C++ 启动 GUI 应用程序并不容易 - 您需要获取并构建一个 GUI 框架。如果我们让初学者能够通过 HTML 呈现他们用 C++ 编写的程序,社区可能会发展壮大。

关于c++ - 将 std::web_view 工具引入标准有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57126253/

相关文章:

c++ - C++中形状的并集和相交

c++ - 堆栈溢出使用 libzip 创建存档

c++ - 'SiteList' 的构造函数必须显式初始化没有默认构造函数的成员 'sites'

c++ - 使用 Visual Studio 2010 对嵌入式 C++ 代码进行单元测试

C++20 格式 sys_time,精度为毫秒

c++ - 如何从 C++20 中的范围创建一个新字符串?

c++ - 如何只读取文件.txt 中的数字?

c++ - 在现代 C++ 中,是否有等效于来自 python 的基于范围的 `enumerate` 循环?

c++ - 如何在cpp20实验中导入C断言

c++ - 这个类是否满足分配器要求?