[all-commits] [llvm/llvm-project] 8fdec5: [Support][Casting] Add predicates for `isa*` funct...
Jakub Kuderski via All-commits
all-commits at lists.llvm.org
Wed Mar 6 06:45:20 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 8fdec5d3badb94807d757c0c58a3900704320919
https://github.com/llvm/llvm-project/commit/8fdec5d3badb94807d757c0c58a3900704320919
Author: Jakub Kuderski <jakub at nod-labs.com>
Date: 2024-03-06 (Wed, 06 Mar 2024)
Changed paths:
M llvm/include/llvm/Support/Casting.h
M llvm/unittests/Support/Casting.cpp
Log Message:
-----------
[Support][Casting] Add predicates for `isa*` functions (#83753)
Expose function objects that call into `llvm::isa` and
`llvm::isa_and_present`, such that these type checks can be used as
predicates in generic algorithms.
Before this change, `llvm::isa*` functions cannot be easily used without
knowing both the argument type and the checked types, which leads to
them being wrapped in lambdas. For example:
```c++
llvm::all_of(myTypes,
[](auto type) { return llvm::isa<VectorType>(type); });
```
With this PR the example above becomes:
```c++
llvm::all_of(myTypes, llvm::IsaPred<VectorType>);
```
As an alternative solution, I considered redefining `isa*` as function
objects, but I decided against doing that because it would create
asymmetry with other cast *functions* and could break code that depends
on them being actual functions.
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