[llvm] [llvm][ADT] Use ADL to find begin()/end() in interleave* (PR #87669)

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 4 12:56:26 PDT 2024


================
@@ -2151,15 +2151,15 @@ template <typename Container, typename UnaryFunctor, typename NullaryFunctor,
               !std::is_constructible<StringRef, NullaryFunctor>::value>>
 inline void interleave(const Container &c, UnaryFunctor each_fn,
                        NullaryFunctor between_fn) {
-  interleave(c.begin(), c.end(), each_fn, between_fn);
+  interleave(adl_begin(c), adl_end(c), each_fn, between_fn);
----------------
jroelofs wrote:

IIUC `adl_begin` just puts a name on the pattern:

```
using std::begin;
begin(Container);
```

to suggest to the reader that Argument Dependent Lookup is happening. You should expect it to match against a free function with the right type named `begin()`, or fall back on `std::begin` which would either give you the pointer to the beginning of the array, or call `.begin()` as appropriate.

https://github.com/llvm/llvm-project/pull/87669


More information about the llvm-commits mailing list