[all-commits] [llvm/llvm-project] b07c88: [Support] Add format object for interleaved ranges...
Jakub Kuderski via All-commits
all-commits at lists.llvm.org
Tue Apr 15 20:44:56 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b07c88563febdb62b82daad0480d7b6131bc54d4
https://github.com/llvm/llvm-project/commit/b07c88563febdb62b82daad0480d7b6131bc54d4
Author: Jakub Kuderski <jakub at nod-labs.com>
Date: 2025-04-15 (Tue, 15 Apr 2025)
Changed paths:
A llvm/include/llvm/Support/InterleavedRange.h
M llvm/unittests/Support/CMakeLists.txt
A llvm/unittests/Support/InterleavedRangeTest.cpp
Log Message:
-----------
[Support] Add format object for interleaved ranges (#135517)
Add two new format functions for printing ranges: `interleaved` and
`interleaved_array`.
This is meant to improve the ergonomics of printing ranges. Before this
patch, we have to either use `llvm::interleave` or write a for loop by
hand. For example:
Before:
```c++
ArrayRef<Type> types = ...;
ArrayRef<Values> values = ...;
LLVM_DEBUG({
llvm::dbgs() << "Types: ";
llvm::interleave_comma(llvm::dbgs(), types);
llvm::dbgs() << "\n";
llvm::dbgs() << "Values: [";
llvm::interleave_comma(llvm::dbgs(), values);
llvm::dbgs() << "]\n";
}):
```
After:
```c++
ArrayRef<Type> types = ...;
ArrayRef<Values> values = ...;
LLVM_DEBUG(llvm::dbgs() << "Types: " << interleaved(types) << "\n");
LLVM_DEBUG(llvm::dbgs() << "Values: " << interleaved_array(values) << "\n");
```
The separator and the prefix/suffix strings are customizable.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list