Fix formatting of ranges with begin()&/end()&

C++20 allows ranges to have lvalue-qualified begin() and end() member functions. fmt correctly handles this if begin() and end() are additionally const-qualifed (i.e. begin() const&), but not in the non-const case. For example:

https://godbolt.org/z/YfxaYz5r7

This patch fixes fmt's range detection to handle this case by testing calls to detail::ranges_begin()/end() with an lvalue T&, matching the behaviour in the const case.
This commit is contained in:
Tristan Brindle
2024-01-10 19:17:28 +00:00
committed by Victor Zverovich
parent 6f5d53ce08
commit 2595bf57b3
2 changed files with 13 additions and 2 deletions

View File

@@ -132,8 +132,8 @@ struct has_const_begin_end<
template <typename T>
struct has_mutable_begin_end<
T, void_t<decltype(detail::range_begin(std::declval<T>())),
decltype(detail::range_end(std::declval<T>())),
T, void_t<decltype(detail::range_begin(std::declval<T&>())),
decltype(detail::range_end(std::declval<T&>())),
// the extra int here is because older versions of MSVC don't
// SFINAE properly unless there are distinct types
int>> : std::true_type {};