mcpp index

fmtlib.fmt

import

A modern formatting library for C++, exposed as C++23 module fmt

import fmt;
mcpp add fmtlib.fmt@12.2.0

用法

來自本倉庫自己的測試專案 —— CI 真的編譯並執行過,不是為了網站寫的。

// Behavioral test: consume {fmt}'s compiled implementation through the C++23
// module `fmt` (`import fmt;`, no #include) and assert the results. Exercises
// src/format.cc via the module unit's tail includes — not just header inlines.
// Returns non-zero on any mismatch.
import std;
import fmt;

int main() {
    std::string a = fmt::format("{} + {} = {}", 2, 3, 2 + 3);
    std::string b = fmt::format("{:08.3f}", 3.14159);
    std::string c = fmt::format("{0}-{1}-{0}", "x", "y");
    std::string d = fmt::format("{:#x}", 255);

    bool ok = a == "2 + 3 = 5"
              && b == "0003.142"
              && c == "x-y-x"
              && d == "0xff";
    return ok ? 0 : 1;
}

tests/examples/fmtlib.fmt/tests/format_test.cpp · 專案 tests/examples/fmtlib.fmt

建置

modules
fmt
targets
fmt (lib)
language
c++23
import std
yes
include dirs
*/include, */src

原始檔 (1)

  • mcpp_generated/fmt_module.cppm

產生的檔案

  • mcpp_generated/fmt_module.cppm

版本

版本平台 鏡像sha256
12.2.0 最新 LinuxWindowsmacOS 來源 8b852bb5aa6e…