Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
# include <tuple>
# include <type_traits>
# include <utility>

// Check FMT_CPLUSPLUS to suppress a bogus warning in MSVC.
# if FMT_CPLUSPLUS >= 201703L
# if FMT_HAS_INCLUDE(<optional>)
# include <optional>
# endif
# endif
#endif

#include "format.h"
Expand Down Expand Up @@ -487,6 +494,12 @@ struct range_format_kind
is_range<T, Char>::value, detail::range_format_kind_<T>,
std::integral_constant<range_format, range_format::disabled>> {};

#if defined(__cpp_lib_optional_range_support)
template <typename T, typename Char>
struct range_format_kind<std::optional<T>, Char>
: std::integral_constant<range_format, range_format::disabled> {};
#endif

template <typename R, typename Char>
struct formatter<
R, Char,
Expand Down
12 changes: 12 additions & 0 deletions test/ranges-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# include <ranges>
#endif

#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<optional>)
# include <optional>
#endif

#include "fmt/format.h"
#include "gtest/gtest.h"

Expand Down Expand Up @@ -271,6 +275,14 @@ TEST(ranges_test, disabled_range_formatting_of_path) {
fmt::range_format::disabled);
}

# if defined(__cpp_lib_optional_range_support)
TEST(ranges_test, disabled_range_formatting_of_optional) {
// Range format of optional is disabled to avoid ambiguity with fmt/std.h.
EXPECT_EQ((fmt::range_format_kind<std::optional<int>, char>::value),
fmt::range_format_disabled);
}
#endif

struct vector_string : std::vector<char> {
using base = std::vector<char>;
using base::base;
Expand Down
Loading