Skip to content

Commit d95a629

Browse files
committed
Consolidate implementation details
1 parent 7bb6fcb commit d95a629

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

include/fmt/std.h

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# include <type_traits>
2424
# include <typeinfo>
2525
# include <utility>
26-
# include <vector>
2726

2827
// Check FMT_CPLUSPLUS to suppress a bogus warning in MSVC.
2928
# if FMT_CPLUSPLUS >= 201703L
@@ -79,11 +78,11 @@
7978
# endif
8079
#endif
8180

82-
#if FMT_CPP_LIB_FILESYSTEM
8381
FMT_BEGIN_NAMESPACE
84-
8582
namespace detail {
8683

84+
#if FMT_CPP_LIB_FILESYSTEM
85+
8786
template <typename Char, typename PathChar>
8887
auto get_path_string(const std::filesystem::path& p,
8988
const std::basic_string<PathChar>& native) {
@@ -111,8 +110,49 @@ void write_escaped_path(basic_memory_buffer<Char>& quoted,
111110
}
112111
}
113112

113+
<<<<<<< HEAD
114+
# endif // FMT_CPP_LIB_FILESYSTEM
115+
116+
# if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT
117+
template <typename Char, typename OutputIt, typename T>
118+
auto write_escaped_alternative(OutputIt out, const T& v) -> OutputIt {
119+
if constexpr (has_to_string_view<T>::value)
120+
return write_escaped_string<Char>(out, detail::to_string_view(v));
121+
if constexpr (std::is_same_v<T, Char>) return write_escaped_char(out, v);
122+
return write<Char>(out, v);
123+
}
124+
# endif
125+
126+
# if FMT_CPP_LIB_VARIANT
127+
128+
template <typename T>
129+
using variant_index_sequence =
130+
std::make_index_sequence<std::variant_size<T>::value>;
131+
132+
template <typename> struct is_variant_like_ : std::false_type {};
133+
template <typename... Types>
134+
struct is_variant_like_<std::variant<Types...>> : std::true_type {};
135+
136+
// formattable element check.
137+
template <typename T, typename C> class is_variant_formattable_ {
138+
template <std::size_t... Is>
139+
static std::conjunction<
140+
is_formattable<std::variant_alternative_t<Is, T>, C>...>
141+
check(std::index_sequence<Is...>);
142+
143+
public:
144+
static constexpr const bool value =
145+
decltype(check(variant_index_sequence<T>{}))::value;
146+
};
147+
148+
# endif // FMT_CPP_LIB_VARIANT
149+
150+
=======
151+
>>>>>>> parent of 1e5d643e (Consolidate implementation details)
114152
} // namespace detail
115153

154+
#if FMT_CPP_LIB_FILESYSTEM
155+
116156
template <typename Char> struct formatter<std::filesystem::path, Char> {
117157
private:
118158
format_specs specs_;
@@ -177,10 +217,8 @@ class path : public std::filesystem::path {
177217
auto generic_system_string() const -> std::string { return generic_string(); }
178218
};
179219

180-
FMT_END_NAMESPACE
181220
#endif // FMT_CPP_LIB_FILESYSTEM
182221

183-
FMT_BEGIN_NAMESPACE
184222
template <std::size_t N, typename Char>
185223
struct formatter<std::bitset<N>, Char>
186224
: nested_formatter<basic_string_view<Char>, Char> {
@@ -209,10 +247,8 @@ struct formatter<std::bitset<N>, Char>
209247

210248
template <typename Char>
211249
struct formatter<std::thread::id, Char> : basic_ostream_formatter<Char> {};
212-
FMT_END_NAMESPACE
213250

214251
#ifdef __cpp_lib_optional
215-
FMT_BEGIN_NAMESPACE
216252
template <typename T, typename Char>
217253
struct formatter<std::optional<T>, Char,
218254
std::enable_if_t<is_formattable<T, Char>::value>> {
@@ -251,7 +287,6 @@ struct formatter<std::optional<T>, Char,
251287
return detail::write(out, ')');
252288
}
253289
};
254-
FMT_END_NAMESPACE
255290
#endif // __cpp_lib_optional
256291

257292
#if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT
@@ -273,8 +308,6 @@ FMT_END_NAMESPACE
273308
#endif
274309

275310
#ifdef __cpp_lib_expected
276-
FMT_BEGIN_NAMESPACE
277-
278311
template <typename T, typename E, typename Char>
279312
struct formatter<std::expected<T, E>, Char,
280313
std::enable_if_t<(std::is_void<T>::value ||
@@ -301,11 +334,9 @@ struct formatter<std::expected<T, E>, Char,
301334
return out;
302335
}
303336
};
304-
FMT_END_NAMESPACE
305337
#endif // __cpp_lib_expected
306338

307339
#ifdef __cpp_lib_source_location
308-
FMT_BEGIN_NAMESPACE
309340
template <> struct formatter<std::source_location> {
310341
FMT_CONSTEXPR auto parse(parse_context<>& ctx) { return ctx.begin(); }
311342

@@ -323,34 +354,9 @@ template <> struct formatter<std::source_location> {
323354
return out;
324355
}
325356
};
326-
FMT_END_NAMESPACE
327357
#endif
328358

329359
#if FMT_CPP_LIB_VARIANT
330-
FMT_BEGIN_NAMESPACE
331-
namespace detail {
332-
333-
template <typename T>
334-
using variant_index_sequence =
335-
std::make_index_sequence<std::variant_size<T>::value>;
336-
337-
template <typename> struct is_variant_like_ : std::false_type {};
338-
template <typename... Types>
339-
struct is_variant_like_<std::variant<Types...>> : std::true_type {};
340-
341-
// formattable element check.
342-
template <typename T, typename C> class is_variant_formattable_ {
343-
template <std::size_t... Is>
344-
static std::conjunction<
345-
is_formattable<std::variant_alternative_t<Is, T>, C>...>
346-
check(std::index_sequence<Is...>);
347-
348-
public:
349-
static constexpr const bool value =
350-
decltype(check(variant_index_sequence<T>{}))::value;
351-
};
352-
353-
} // namespace detail
354360

355361
template <typename T> struct is_variant_like {
356362
static constexpr const bool value = detail::is_variant_like_<T>::value;
@@ -402,10 +408,9 @@ struct formatter<
402408
return out;
403409
}
404410
};
405-
FMT_END_NAMESPACE
411+
406412
#endif // FMT_CPP_LIB_VARIANT
407413

408-
FMT_BEGIN_NAMESPACE
409414
template <> struct formatter<std::error_code> {
410415
private:
411416
format_specs specs_;
@@ -543,7 +548,7 @@ struct formatter<std::type_info, Char // DEPRECATED! Mixing code unit types.
543548
return detail::write_demangled_name<Char>(ctx.out(), ti);
544549
}
545550
};
546-
#endif
551+
#endif // FMT_USE_RTTI
547552

548553
template <typename T, typename Char>
549554
struct formatter<

0 commit comments

Comments
 (0)