Dedup ADL begin/end lookup

This commit is contained in:
Victor Zverovich
2024-04-22 15:45:20 -07:00
parent a3e0931ea2
commit 400f6a8ee2
2 changed files with 11 additions and 29 deletions

View File

@@ -462,18 +462,16 @@ TEST(ranges_test, join_range) {
}
namespace adl {
struct vec : std::vector<int> {
using std::vector<int>::vector; // inherit all constructors
struct vec {
int n[2] = {42, 43};
};
// 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; }
auto begin(const vec& v) -> const int* { return v.n; }
auto end(const vec& v) -> const int* { return v.n + 2; }
}
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");
EXPECT_EQ(fmt::format("{}", fmt::join(adl::vec(), "/")), "42/43");
}
#endif // FMT_RANGES_TEST_ENABLE_JOIN