mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-25 03:39:56 +01:00
Consider ADL begin() and end() when joining ranges (#3824)
Closes #3813 Signed-off-by: Beat Bolli <dev@drbeat.li>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user