【问题标题】:What are the differences between libfmt and std::format?libfmt 和 std::format 有什么区别?
【发布时间】:2020-08-25 20:39:09
【问题描述】:

我知道 c++20 格式提案是 libfmt parts 的形式化,并且 libfmt 是该形式化的兼容实现。但是,据我了解,libfmt 提供了超出 c++20 标准中指定的附加功能。有哪些附加功能?

另外,主要的编译器供应商是简单地包含 libfmt 的子集还是重新实现它?

【问题讨论】:

    标签: c++ c++20 fmt


    【解决方案1】:

    libfmt 中有一堆不是 C++20 格式的东西:

    • fmt::print() 直接打印到标准输出。这是在P2093 中提出的。 fmt::printf() 也存在,但未在该论文中提出。
    • fmt::memory_buffer 基本上是一个动态大小的容器,您可以通过 fmt::format_to(buf, ...) 格式化。
    • 支持格式化ranges and tuples,包括fmt::join()
    • 支持named arguments 喜欢fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23);
    • 通过FMT_COMPILE 编译时格式字符串

    【讨论】:

    • 我不认为fmt::color and fmt::emphasis 在 C++20 中,但我很想错。 :-)
    • C++20 是否允许编译时 string_view 文字代替 FMT_COMPILE
    • 或者换一种说法,当 string_view 文字作为格式字符串传递时,C++20 实现是否可以执行与 FMT_COMPILE 相同的优化?
    猜你喜欢
    • 1970-01-01
    • 2019-10-17
    • 2014-07-22
    • 2023-04-09
    • 2020-10-16
    • 2020-09-30
    • 2021-10-16
    • 2015-07-18
    • 2019-02-26
    相关资源
    最近更新 更多