惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
SecWiki News
SecWiki News
博客园 - Franky
V
V2EX
罗磊的独立博客
美团技术团队
大猫的无限游戏
大猫的无限游戏
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
C
Cyber Attacks, Cyber Crime and Cyber Security
Hugging Face - Blog
Hugging Face - Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Attack and Defense Labs
Attack and Defense Labs
WordPress大学
WordPress大学
Webroot Blog
Webroot Blog
N
News | PayPal Newsroom
博客园 - 司徒正美
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cloudbric
Cloudbric
AI
AI
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
N
News and Events Feed by Topic
Recent Commits to openclaw:main
Recent Commits to openclaw:main
月光博客
月光博客
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
Project Zero
Project Zero
Schneier on Security
Schneier on Security
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
P
Privacy & Cybersecurity Law Blog
博客园_首页
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
J
Java Code Geeks
P
Proofpoint News Feed

Lobsters

CIFSwitch: a non-universal Linux local root vulnerability RIPE NCC session fixation: poaching logins with an Atlas probe GNOME 2.20 but its Web Components Agentic Search for Context Engineering – Leonie Monigatti Garnix is shutting down [not OC] akashina.tngl.sh/jjc Concerning Emacs (and Jazz) Nitpicking the shell history scene in ‘Tron: Legacy’ What's cooking on SourceHut? Q2 2026 The tenth OpenPGP email summit Package managers that package package managers Clojure on Fennel part three: parsing WordPress at 23 Finding Miscompiles for Fun, Not Profit GitHub - creusot-rs/creusot: Creusot helps you prove your Rust code is correct. Announcing Rust 1.96.0 | Rust Blog A Love Letter to Neovim sqlite AGENTS.md Am I a Bad Friend? CSS vs. JavaScript • Josh W. Comeau Erlang Ecosystem Foundation - Supporting the BEAM community A brief note about slot access cost in Common Lisp Keyboard latency probe Rethinking the GNOME clipboard issues Back to the Building Blocks’ Building Blocks Tech Notes: Theseus: translating win32 to wasm Fast is better than slow Content-addressed Rust builds (or, what kache actually caches) Intent to Prototype: Embedding API Canada’s Bill C-22 and the security cost of collecting more data 5 PostgreSQL locking behaviors that trip people up okmij.org Stop advertising in your commits! | AksDev GitHub - mplsllc/macsurf: A modern web browser for Classic Mac OS 9 PowerPC. Real CSS3, ES5 JavaScript, native HTTPS — built with CodeWarrior on the Carbon API. Introducing DoomBench - Can Your Data Stack Run DOOM? What are some of your favourite developer tools? Building a Scalable Ingestion Pipeline with Temporal (Part 1) Converting shallow Git bundles into normal repositories Are you a member of any professional associations? What is a harmonic? An interactive comic about additive synthesis How Virtual Tables Work in the Itanium C++ ABI Using SwiftUI to Build a Mac-assed App in 2026 Rust (and Slint) on a jailbroken Kindle. ~jack/lambda-on-lambda - Serverless Haskell on AWS - sourcehut git Human proof for FOSS contributions Extremely simple internet radio controlled via IRC Announcing BABLR Splitting Konsole views from Helix to run tools | AksDev GitHub - yugr/rust-slides Serving files over HTTP three ways: synchronous, epoll, and io_uring update docs with information about building with build.py (#979) · astral-sh/python-build-standalone@c9c40c5 A Simple Makefile Tutorial On C extensions, portability, and alternative compilers Switching to Colemak | Pedro Alves Just How Bad Was The Intel IAPX432? Nix's Substituter List Is Not a Routing Table Accelerating copy_if using SIMD Lambda on Lambda: Serverless Haskell on AWS | Blog Announcing feed-repeat v1.0 Scaling Akvorado BMP RIB with sharding EYG news: A host of CLI improvements, new guides and new effects The social contract of writing JS Crossword C array types are weird; and related topics Flatpak will depend on systemd – OSnews Migrating from Go to Rust | corrode Rust Consulting A portentous reunion Vivado Licensing Options How my minimal, memory-safe Go rsync steers clear of vulnerabilities the entropy layer of a wavelet codec, on its own GitHub - nferhat/fht-compositor: A dynamic tiling Wayland compositor. Debian SE Linux and PinTheft Does bulk memmove speed up std::remove_if? (No.) 声明式部分更新 | Blog | Chrome for Developers Fully in-browser container builds Dianne Skoll's Web Site - Remind The Architecture of Open Source Applications (Volume 1)Berkeley DB Pardon MIE? - ironPeak Blog “Long-Term Support” doesn’t mean what you think Jira IS Turing-Complete May I recommend thinking of Emacs as your Fortress of Solitude hershey Floodgap Gopher-HTTP gateway gopher://thelambdalab.xyz/1cuneiforth/ HP QuickWeb, Singular And Pointless That one time I used Go panics for flow control A new suite of modern tools coming for editing and publishing RFCs From the Tabletop… The Digital Antiquarian Building a Host-Tuned GCC to Make GCC Compile Faster Are we self-sovereign PKI yet? Claw Patrol: an open-source security firewall for agents | Deno Revised^7 Report on Scheme, Large: Procedural Fascicle Draft is now public A Network Allow-List Won't Stop Exfiltration — André Graf From AFSK to Goertzel – µArt.cz Software For My New Home Server Introducing Neptune: Direct3D virtualization for QEMU AI Agent Bankrupted Their Operator While Trying to Scan DN42 - Lan Tian @ Blog mimalloc: A new, high-performance, scalable memory allocator for the modern era Making wl_shm fast The Soul of Maintaining a New Machine - Third Draft | Books in Progress What is Git made of?
Improvements to std::format in C++26
Marius Bancila · 2026-06-21 · via Lobsters

The C++26 standard features a series of improvements to the format library. In this article, we will look at the most important of them.

Printing an empty line

Prior to C++26, printing an empty line had to be done like this:

std::print("\n");

In C++26, std::println has an overload without any parameters that prints a new line to the console.

std::print();

Formatting pointers

Formatting pointer types was not available directly, it required a hack: reinterpreting the pointer type as an integer type in order to print it.

int i = 0;
const void* p = &i;

std::println("{:#018x}", reinterpret_cast<uintptr_t>(p));

In C++26, the formatting library supports formatting of pointer types directly:

  • implicitly, no specifier is required
  • explicitly, with wither the p (for lowercase) or P (for uppercase) specifiers

Null pointers are formatted as 0x0 (unless padding is specified).

Here are several examples of formatting pointers:

int i = 0;
const void* p = &i;
    
std::println("{}",     p);       // lowercase, the default           => 0x7fffb2715a54
std::println("{:p}",   p);       // explicit, same as none           => 0x7fffb2715a54
std::println("{:P}",   p);       // uppercase                        => 0X7FFFB2715A54
std::println("{:018}", p);       // zero-padded to width 18          => 0x00007fffb2715a54
std::println("{:>20}", p);       // right-aligned in a 20-wide field =>       0x7fffb2715a54
std::println("{}", nullptr);     //                                  => 0x0
std::println("{:016}", nullptr); //                                  => 0x00000000000000

Formatting paths

Another feature that required a workaround was printing paths from the std::filesystem namespace. You could use path::string() to get the string representation of a path.

namespace fs = std::filesystem;

fs::path p = "/usr/local/bin/clang++";
std::println("{}", p.string());

However, this prints the path unquoted. On the other hand, using the << operator would print the path in quotes:

std::cout << p << '\n';

C++26 adds a std::formatter for std::filesystem::path, which makes it easier to format paths.

  • by default, paths are formatted unquoted
  • the ? option defines a debug form which gives an escaped representation (in quotes)
  • the g option forces generic (forward-slash) separators (which mainly shows up on Windows)
fs::path p = "/usr/local/bin/clang++";
std::println("{}",  p);   // /usr/local/bin/clang++
std::println("{:?}", p);  // "/usr/local/bin/clang++"
fs::path p = R"(C:\Users\marius\file.txt)";
std::println("{}",    w);  // C:\Users\marius\file.txt    (native separators)
std::println("{:g}",  w);  // C:/Users/marius/file.txt    (generic)
std::println("{:g?}", w);  // "C:/Users/marius/file.txt"  (generic + escaped)

A related issue solved along was Windows string representation of paths. std::filesystem::path stores its text in wchar_t encoded as UTF-16 (Windows native). But p.string() narrows it down to the active code page, rather than UTF-8 which is what the formatting library expects. The result was a non-ASCII path could get transcoded to gibberish. The C++26 std::formatter<std::filesystem::path> converts Windows native UTC-16 to UTF-8 using Unicode transcoding and avoiding code pages, therefore solving the problem. Ill-formed UTF-16 is replaced with U+FFFD by default, or escaped under {:?}.

constexpr std::format

In C++26, the formatting functions std::format, std::vformat, std::format_to, std::format_to_n, std::formatted_size, and their wide variants, plus the underlying pieces (the format context, std::basic_format_arg, std::basic_format_string, and the format member of the standard formatters) are constexpr.

This makes it possible to use static_assert for instance with std::format such as in the following examples:

static_assert(std::format("{} {}", 1, 2) == "1 2");

static_assert(sizeof(void*) == 8,
              std::format("expected 64-bit, pointer is {} bytes", sizeof(void*)));

This works because it relies on to_chars() overloads which have been made constexpr, but only for integral types. So it can be used with strings, integer types, bool, char, and pointers. But there are several limitations to this feature. The following are not supported:

  • floating-point types
  • chrono types
  • locale-aware formatting (using the L specifier – as in {:L}, makes the call non-constant)

For now, compile-time std::format covers integers, strings, and diagnostics well, with floating-point support waiting on a separate paper (P3652) to make the floating-point <charconv> functions constexpr.

std::runtime_format becomes std::dynamic_format

The format string of std::format or std::print must be a constant expression. For instance, you can write this:

std::println("{} = {}", "x", 13);

But you cannot write the following:

std::string strf = "{} = {}";
std::println(strf, "x", 13);

This is ill-formed because strf is only known at runtime, and therefore is not a constant expression. The workaround is to use std::vformat:

const char* key = "y";
int val = 13;
std::string strf = "{} = {}";

std::string s = std::vformat(strf, std::make_format_args(key, val));
std::println("{}", s);

There is a workaround for the workaround (it’s basically syntactic sugar for std::vformat), the formally known as std::runtime_format function, that returns an object that stores a dynamic format string directly usable in user-oriented formatting functions and can be implicitly converted to std::basic_format_string.

std::string strf = "{} = {}";
std::println(std::runtime_format(strf), "x", 13);

In the final version of C++26, this has been simply renamed to std::dynamic_format (although at this time the compilers that do support it still use the previous name). Therefore, the snippet above now becomes:

std::string strf = "{} = {}";
std::println(std::dynamic_format(strf), "x", 13);

std::dynamic_format is constexpr, which means it can be used in constant-evaluation contexts, such as in the following example:

constexpr auto make_string = [](std::string_view f) {
    return std::format(std::dynamic_format(f), 1, 2);
};
static_assert(make_string("{}+{}") == "1+2");

See more

You can learn more about these changes from the following articles: