Consider ADL begin() and end() when joining ranges (#3824)

Closes #3813

Signed-off-by: Beat Bolli <dev@drbeat.li>
This commit is contained in:
Beat Bolli
2024-01-22 16:39:33 +01:00
committed by GitHub
parent 2caf1b3b91
commit e1832bcf00
2 changed files with 35 additions and 2 deletions

View File

@@ -455,6 +455,22 @@ TEST(ranges_test, join_range) {
"0,1,2,3,4");
# endif
}
namespace adl {
struct vec : std::vector<int> {
using std::vector<int>::vector; // inherit all constructors
};
// ADL-found begin() and end() skip the first and last element
auto begin(vec& v) -> typename vec::iterator { return v.begin() + 1; }
auto end(vec& v) -> typename vec::iterator { return v.end() - 1; }
}
TEST(ranges_test, format_join_adl_begin_end) {
auto v = adl::vec{41, 42, 43, 44};
EXPECT_EQ(fmt::format("{}", fmt::join(v, "/")), "42/43");
}
#endif // FMT_RANGES_TEST_ENABLE_JOIN
#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 202302L