Fix ambiguous formatter<std::optional<T>> between fmt/std.h and fmt/ranges.h on C++26 (P3168R2) (#4761)

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov
2026-05-03 19:37:46 +05:00
committed by GitHub
parent 5a9a184448
commit 9cb8c0f92b
2 changed files with 27 additions and 2 deletions
+17
View File
@@ -271,6 +271,23 @@ TEST(ranges_test, disabled_range_formatting_of_path) {
fmt::range_format::disabled);
}
template <typename T> struct optional_like {
auto begin() const -> const T*;
auto end() const -> const T*;
bool has_value() const noexcept;
T& value() &;
const T& value() const&;
T&& value() &&;
const T&& value() const&&;
};
TEST(ranges_test, disabled_range_formatting_of_optional) {
// (C++26) Has a range support for std::optional.
EXPECT_EQ((fmt::range_format_kind<optional_like<int>, char>::value),
fmt::range_format::disabled);
}
struct vector_string : std::vector<char> {
using base = std::vector<char>;
using base::base;