[llvm] [ADT] Introduce a `static_cast_to` (PR #165803)
Yanzuo Liu via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 18:48:10 PDT 2025
================
@@ -1704,6 +1704,11 @@ auto sum_of(R &&Range, E Init = E{0}) {
return accumulate(std::forward<R>(Range), std::move(Init));
}
+/// Return a range where each value of `R` is static_cast to `T`
+template <typename T, typename R> auto static_cast_to(R &&Range) {
+ return map_range(Range, [](const auto &V) { return static_cast<T>(V); });
----------------
zwuis wrote:
```cpp
[](auto &V) -> decltype(auto) { return static_cast<T>(V); }
```
Perheps `-> decltype(auto)` is needed to allow returning reference.
https://github.com/llvm/llvm-project/pull/165803
More information about the llvm-commits
mailing list