File tree 2 files changed +20
-2
lines changed 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -1437,7 +1437,7 @@ template <typename EltTy, typename FirstTy> class first_or_second_type {
1437
1437
1438
1438
// / Given a container of pairs, return a range over the first elements.
1439
1439
template <typename ContainerTy> auto make_first_range (ContainerTy &&c) {
1440
- using EltTy = decltype ((* std::begin (c) ));
1440
+ using EltTy = decltype (* adl_begin (c ));
1441
1441
return llvm::map_range (std::forward<ContainerTy>(c),
1442
1442
[](EltTy elt) -> typename detail::first_or_second_type<
1443
1443
EltTy, decltype ((elt.first ))>::type {
@@ -1447,7 +1447,7 @@ template <typename ContainerTy> auto make_first_range(ContainerTy &&c) {
1447
1447
1448
1448
// / Given a container of pairs, return a range over the second elements.
1449
1449
template <typename ContainerTy> auto make_second_range (ContainerTy &&c) {
1450
- using EltTy = decltype ((* std::begin (c) ));
1450
+ using EltTy = decltype (* adl_begin (c ));
1451
1451
return llvm::map_range (
1452
1452
std::forward<ContainerTy>(c),
1453
1453
[](EltTy elt) ->
Original file line number Diff line number Diff line change @@ -421,6 +421,15 @@ void swap(some_struct &lhs, some_struct &rhs) {
421
421
rhs.swap_val = " rhs" ;
422
422
}
423
423
424
+ struct Pairs {
425
+ std::vector<std::pair<std::string, int >> data;
426
+ using const_iterator =
427
+ std::vector<std::pair<std::string, int >>::const_iterator;
428
+ };
429
+
430
+ Pairs::const_iterator begin (const Pairs &p) { return p.data .begin (); }
431
+ Pairs::const_iterator end (const Pairs &p) { return p.data .end (); }
432
+
424
433
struct requires_move {};
425
434
int *begin (requires_move &&) { return nullptr ; }
426
435
int *end (requires_move &&) { return nullptr ; }
@@ -504,6 +513,15 @@ TEST(STLExtrasTest, ConcatRange) {
504
513
EXPECT_EQ (Expected, Test);
505
514
}
506
515
516
+ TEST (STLExtrasTest, MakeFirstSecondRangeADL) {
517
+ // Make sure that we use the `begin`/`end` functions from `some_namespace`,
518
+ // using ADL.
519
+ some_namespace::Pairs Pairs;
520
+ Pairs.data = {{" foo" , 1 }, {" bar" , 2 }};
521
+ EXPECT_THAT (make_first_range (Pairs), ElementsAre (" foo" , " bar" ));
522
+ EXPECT_THAT (make_second_range (Pairs), ElementsAre (1 , 2 ));
523
+ }
524
+
507
525
template <typename T> struct Iterator {
508
526
int i = 0 ;
509
527
T operator *() const { return i; }
You can’t perform that action at this time.
0 commit comments