6#ifndef MIMICPP_PRINTING_FORMAT_HPP
7#define MIMICPP_PRINTING_FORMAT_HPP
14#ifndef MIMICPP_DETAIL_IS_MODULE
17 #include <type_traits>
20 #ifndef MIMICPP_CONFIG_USE_FMT
24 #if __has_include(<fmt/format.h>)
25 #include <fmt/format.h>
27 #error "The fmt formatting backend is explicitly enabled, but the include <fmt/format.h> can not be found."
40 template <
typename Pr
inter,
typename OutIter,
typename T>
42 &&
requires(OutIter out) {
44 Printer::print(out, std::declval<T&>())
45 } -> std::convertible_to<OutIter>;
49#ifndef MIMICPP_CONFIG_USE_FMT
54 #if !MIMICPP_DETAIL_USES_LIBCXX
59 using std::make_format_args;
61 using std::vformat_to;
69 using std::make_format_args;
71 using std::vformat_to;
73 template <
typename... Args>
77 return format::vformat(
79 std::make_format_args(args...));
82 template <
class OutputIt,
typename... Args>
83 OutputIt format_to(
const OutputIt out,
const StringViewT fmt, Args&&... args)
85 return format::vformat_to(
88 std::make_format_args(args...));
94namespace mimicpp::format::detail
96 template <
typename Char>
97 struct format_context;
99 template <
typename Char>
100 using format_context_t =
typename format_context<Char>::type;
103 struct format_context<char>
105 using type = std::format_context;
109 struct format_context<wchar_t>
111 using type = std::wformat_context;
124 template <
class T,
class Char>
125 concept formattable =
126 std::semiregular<std::formatter<std::remove_cvref_t<T>, Char>>
128 std::formatter<std::remove_cvref_t<T>, Char> formatter,
130 format_context_t<Char> formatContext,
131 std::basic_format_parse_context<Char> parseContext) {
132 { formatter.parse(parseContext) } -> std::same_as<typename std::basic_format_parse_context<Char>::iterator>;
134 std::as_const(formatter).format(t, formatContext)
135 } -> std::same_as<
typename std::remove_reference_t<
decltype(formatContext)>::iterator>;
145 using fmt::format_to;
146 using fmt::formatter;
147 using fmt::make_format_args;
149 using fmt::vformat_to;
152namespace mimicpp::format::detail
154 template <
class T,
class Char>
155 concept formattable = fmt::is_formattable<std::remove_reference_t<T>, Char>::value;
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition Format.hpp:35
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:392
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:391