@@ -421,6 +421,16 @@ void swap(some_struct &lhs, some_struct &rhs) {
421
421
rhs.swap_val = " rhs" ;
422
422
}
423
423
424
+ struct List {
425
+ std::list<int > data;
426
+ };
427
+
428
+ std::list<int >::const_iterator begin (const List &list) {
429
+ return list.data .begin ();
430
+ }
431
+
432
+ std::list<int >::const_iterator end (const List &list) { return list.data .end (); }
433
+
424
434
struct requires_move {};
425
435
int *begin (requires_move &&) { return nullptr ; }
426
436
int *end (requires_move &&) { return nullptr ; }
@@ -981,6 +991,13 @@ TEST(STLExtrasTest, hasNItems) {
981
991
EXPECT_TRUE (hasNItems (V3.begin (), V3.end (), 3 , [](int x) { return x < 10 ; }));
982
992
EXPECT_TRUE (hasNItems (V3.begin (), V3.end (), 0 , [](int x) { return x > 10 ; }));
983
993
EXPECT_TRUE (hasNItems (V3.begin (), V3.end (), 2 , [](int x) { return x < 5 ; }));
994
+
995
+ // Make sure that we use the `begin`/`end` functions from `some_namespace`,
996
+ // using ADL.
997
+ some_namespace::List L;
998
+ L.data = {0 , 1 , 2 };
999
+ EXPECT_FALSE (hasNItems (L, 2 ));
1000
+ EXPECT_TRUE (hasNItems (L, 3 ));
984
1001
}
985
1002
986
1003
TEST (STLExtras, hasNItemsOrMore) {
@@ -1003,6 +1020,13 @@ TEST(STLExtras, hasNItemsOrMore) {
1003
1020
hasNItemsOrMore (V3.begin (), V3.end (), 3 , [](int x) { return x > 10 ; }));
1004
1021
EXPECT_TRUE (
1005
1022
hasNItemsOrMore (V3.begin (), V3.end (), 2 , [](int x) { return x < 5 ; }));
1023
+
1024
+ // Make sure that we use the `begin`/`end` functions from `some_namespace`,
1025
+ // using ADL.
1026
+ some_namespace::List L;
1027
+ L.data = {0 , 1 , 2 };
1028
+ EXPECT_TRUE (hasNItemsOrMore (L, 1 ));
1029
+ EXPECT_FALSE (hasNItems (L, 4 ));
1006
1030
}
1007
1031
1008
1032
TEST (STLExtras, hasNItemsOrLess) {
@@ -1036,6 +1060,13 @@ TEST(STLExtras, hasNItemsOrLess) {
1036
1060
hasNItemsOrLess (V3.begin (), V3.end (), 5 , [](int x) { return x < 5 ; }));
1037
1061
EXPECT_FALSE (
1038
1062
hasNItemsOrLess (V3.begin (), V3.end (), 2 , [](int x) { return x < 10 ; }));
1063
+
1064
+ // Make sure that we use the `begin`/`end` functions from `some_namespace`,
1065
+ // using ADL.
1066
+ some_namespace::List L;
1067
+ L.data = {0 , 1 , 2 };
1068
+ EXPECT_FALSE (hasNItemsOrLess (L, 1 ));
1069
+ EXPECT_TRUE (hasNItemsOrLess (L, 4 ));
1039
1070
}
1040
1071
1041
1072
TEST (STLExtras, MoveRange) {
0 commit comments