FMT_CHAR -> char_t
diff --git a/include/fmt/color.h b/include/fmt/color.h
index b29ab08..5c9b049 100644
--- a/include/fmt/color.h
+++ b/include/fmt/color.h
@@ -556,7 +556,7 @@
}
} // namespace internal
-template <typename S, typename Char = typename internal::char_t<S>::type>
+template <typename S, typename Char = char_t<S> >
void vprint(std::FILE* f, const text_style& ts, const S& format,
basic_format_args<typename buffer_context<Char>::type> args) {
bool has_style = false;
@@ -587,13 +587,12 @@
fmt::print(fmt::emphasis::bold | fg(fmt::color::red),
"Elapsed time: {0:.2f} seconds", 1.23);
*/
-template <typename String, typename... Args,
- FMT_ENABLE_IF(internal::is_string<String>::value)>
-void print(std::FILE* f, const text_style& ts, const String& format_str,
+template <typename S, typename... Args,
+ FMT_ENABLE_IF(internal::is_string<S>::value)>
+void print(std::FILE* f, const text_style& ts, const S& format_str,
const Args&... args) {
internal::check_format_string<Args...>(format_str);
- typedef typename internal::char_t<String>::type char_t;
- typedef typename buffer_context<char_t>::type context_t;
+ typedef typename buffer_context<char_t<S> >::type context_t;
format_arg_store<context_t, Args...> as{args...};
vprint(f, ts, format_str, basic_format_args<context_t>(as));
}
@@ -605,14 +604,13 @@
fmt::print(fmt::emphasis::bold | fg(fmt::color::red),
"Elapsed time: {0:.2f} seconds", 1.23);
*/
-template <typename String, typename... Args,
- FMT_ENABLE_IF(internal::is_string<String>::value)>
-void print(const text_style& ts, const String& format_str,
- const Args&... args) {
+template <typename S, typename... Args,
+ FMT_ENABLE_IF(internal::is_string<S>::value)>
+void print(const text_style& ts, const S& format_str, const Args&... args) {
return print(stdout, ts, format_str, args...);
}
-template <typename S, typename Char = FMT_CHAR(S)>
+template <typename S, typename Char = char_t<S> >
inline std::basic_string<Char> vformat(
const text_style& ts, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
@@ -631,10 +629,9 @@
"The answer is {}", 42);
\endrst
*/
-template <typename S, typename... Args>
-inline std::basic_string<FMT_CHAR(S)> format(const text_style& ts,
- const S& format_str,
- const Args&... args) {
+template <typename S, typename... Args, typename Char = char_t<S> >
+inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
+ const Args&... args) {
return internal::vformat(ts, to_string_view(format_str),
{internal::make_args_checked(format_str, args...)});
}
diff --git a/include/fmt/core.h b/include/fmt/core.h
index e9cea57..3298b05 100644
--- a/include/fmt/core.h
+++ b/include/fmt/core.h
@@ -617,7 +617,7 @@
template <> struct is_string<std::FILE*>;
template <> struct is_string<const std::FILE*>;
-template <typename S> struct char_t {
+template <typename S> struct char_t_impl {
typedef decltype(to_string_view(std::declval<S>())) result;
typedef typename result::char_type type;
};
@@ -883,7 +883,7 @@
make_value(const S& val) {
// Handle adapted strings.
static_assert(std::is_same<typename C::char_type,
- typename internal::char_t<S>::type>::value,
+ typename internal::char_t_impl<S>::type>::value,
"mismatch between char-types of context and argument");
return to_string_view(val);
}
@@ -1311,8 +1311,7 @@
};
/** String's character type. */
-template <typename S> using char_t = typename internal::char_t<S>::type;
-#define FMT_CHAR(S) fmt::char_t<S>
+template <typename S> using char_t = typename internal::char_t_impl<S>::type;
namespace internal {
template <typename Context>
@@ -1353,8 +1352,8 @@
void check_format_string(S);
template <typename S, typename... Args,
- FMT_ENABLE_IF(internal::is_string<S>::value)>
-inline format_arg_store<typename buffer_context<FMT_CHAR(S)>::type, Args...>
+ typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
+inline format_arg_store<typename buffer_context<Char>::type, Args...>
make_args_checked(const S& format_str, const Args&... args) {
internal::check_format_string<Args...>(format_str);
return {args...};
@@ -1386,8 +1385,8 @@
fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23));
\endrst
*/
-template <typename S, typename T>
-inline internal::named_arg<T, FMT_CHAR(S)> arg(const S& name, const T& arg) {
+template <typename S, typename T, typename Char = char_t<S>>
+inline internal::named_arg<T, Char> arg(const S& name, const T& arg) {
static_assert(internal::is_string<S>::value, "");
return {name, arg};
}
@@ -1404,13 +1403,23 @@
template <typename Char>
struct is_contiguous<internal::buffer<Char>> : std::true_type {};
+template <typename OutputIt>
+struct is_contiguous_back_insert_iterator : std::false_type {};
+
+template <typename Container>
+struct is_contiguous_back_insert_iterator<std::back_insert_iterator<Container>>
+ : is_contiguous<Container> {};
+
/** Formats a string and writes the output to ``out``. */
-template <typename Container, typename S>
-typename std::enable_if<is_contiguous<Container>::value,
- std::back_insert_iterator<Container>>::type
-vformat_to(std::back_insert_iterator<Container> out, const S& format_str,
- basic_format_args<typename buffer_context<FMT_CHAR(S)>::type> args) {
- internal::container_buffer<Container> buf(internal::get_container(out));
+template <typename OutputIt, typename S,
+ typename Char = enable_if_t<
+ is_contiguous_back_insert_iterator<OutputIt>::value, char_t<S>>>
+OutputIt vformat_to(
+ OutputIt out, const S& format_str,
+ basic_format_args<typename buffer_context<Char>::type> args) {
+ using container = typename std::remove_reference<decltype(
+ internal::get_container(out))>::type;
+ internal::container_buffer<container> buf((internal::get_container(out)));
internal::vformat_to(buf, to_string_view(format_str), args);
return out;
}
@@ -1425,8 +1434,8 @@
{internal::make_args_checked(format_str, args...)});
}
-template <typename S, typename Char = FMT_CHAR(S),
- FMT_ENABLE_IF(internal::is_string<S>::value)>
+template <typename S,
+ typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline std::basic_string<Char> vformat(
const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
@@ -1443,11 +1452,12 @@
std::string message = fmt::format("The answer is {}", 42);
\endrst
*/
-// Pass fmt::char_t as a default template parameter instead of using
-// std::basic_string<fmt::char_t<S>> to reduce the symbol size.
+// Pass char_t as a default template parameter instead of using
+// std::basic_string<char_t<S>> to reduce the symbol size.
template <typename S, typename... Args,
typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
-inline std::basic_string<Char> format(const S& format_str, const Args&... args) {
+inline std::basic_string<Char> format(const S& format_str,
+ const Args&... args) {
return internal::vformat(to_string_view(format_str),
{internal::make_args_checked(format_str, args...)});
}
diff --git a/include/fmt/format.h b/include/fmt/format.h
index 42846f9..c8ce2f3 100644
--- a/include/fmt/format.h
+++ b/include/fmt/format.h
@@ -1805,10 +1805,11 @@
: offset_(view.data() - primary_string.data()), size_(view.size()) {}
FMT_CONSTEXPR string_view_metadata(std::size_t offset, std::size_t size)
: offset_(offset), size_(size) {}
- template <typename S, FMT_ENABLE_IF(internal::is_string<S>::value)>
- FMT_CONSTEXPR basic_string_view<FMT_CHAR(S)> to_view(S&& str) const {
+ template <typename S, typename Char = enable_if_t<
+ internal::is_string<S>::value, char_t<S>>>
+ FMT_CONSTEXPR basic_string_view<Char> to_view(S&& str) const {
const auto view = to_string_view(str);
- return basic_string_view<FMT_CHAR(S)>(view.data() + offset_, size_);
+ return basic_string_view<Char>(view.data() + offset_, size_);
}
std::size_t offset_;
@@ -3384,7 +3385,7 @@
args);
}
-template <typename S, typename Char = FMT_CHAR(S),
+template <typename S, typename Char = char_t<S>,
FMT_ENABLE_IF(internal::is_string<S>::value)>
inline typename buffer_context<Char>::type::iterator vformat_to(
internal::buffer<Char>& buf, const S& format_str,
@@ -3393,12 +3394,12 @@
}
template <typename S, typename... Args, std::size_t SIZE = inline_buffer_size,
- typename Char = typename internal::char_t<S>::type>
+ typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline typename buffer_context<Char>::type::iterator format_to(
basic_memory_buffer<Char, SIZE>& buf, const S& format_str,
const Args&... args) {
internal::check_format_string<Args...>(format_str);
- typedef typename buffer_context<Char>::type context;
+ using context = typename buffer_context<Char>::type;
format_arg_store<context, Args...> as{args...};
return internal::vformat_to(buf, to_string_view(format_str),
basic_format_args<context>(as));
@@ -3459,12 +3460,13 @@
type;
};
-template <typename String, typename OutputIt, typename... Args,
- FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value)>
+template <typename S, typename OutputIt, typename... Args,
+ FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value &&
+ !is_contiguous_back_insert_iterator<OutputIt>::value)>
inline OutputIt vformat_to(
- OutputIt out, const String& format_str,
- typename format_args_t<OutputIt, FMT_CHAR(String)>::type args) {
- typedef output_range<OutputIt, FMT_CHAR(String)> range;
+ OutputIt out, const S& format_str,
+ typename format_args_t<OutputIt, char_t<S>>::type args) {
+ typedef output_range<OutputIt, char_t<S>> range;
return vformat_to<arg_formatter<range>>(range(out),
to_string_view(format_str), args);
}
@@ -3481,13 +3483,13 @@
\endrst
*/
template <typename OutputIt, typename S, typename... Args>
-inline
- typename std::enable_if<internal::is_string<S>::value &&
- internal::is_output_iterator<OutputIt>::value,
- OutputIt>::type
- format_to(OutputIt out, const S& format_str, const Args&... args) {
+inline OutputIt format_to(OutputIt out, const S& format_str,
+ const Args&... args) {
+ static_assert(internal::is_output_iterator<OutputIt>::value &&
+ internal::is_string<S>::value,
+ "");
internal::check_format_string<Args...>(format_str);
- typedef typename format_context_t<OutputIt, FMT_CHAR(S)>::type context;
+ typedef typename format_context_t<OutputIt, char_t<S>>::type context;
format_arg_store<context, Args...> as{args...};
return vformat_to(out, to_string_view(format_str),
basic_format_args<context>(as));
@@ -3542,7 +3544,7 @@
const S& format_str,
const Args&... args) {
internal::check_format_string<Args...>(format_str);
- typedef FMT_CHAR(S) Char;
+ using Char = char_t<S>;
format_arg_store<typename format_to_n_context<OutputIt, Char>::type, Args...>
as(args...);
return vformat_to_n(out, n, to_string_view(format_str),
diff --git a/include/fmt/locale.h b/include/fmt/locale.h
index aeb3521..b6b4cf9 100644
--- a/include/fmt/locale.h
+++ b/include/fmt/locale.h
@@ -34,38 +34,39 @@
}
} // namespace internal
-template <typename S, typename Char = FMT_CHAR(S)>
+template <typename S, typename Char = char_t<S>>
inline std::basic_string<Char> vformat(
const std::locale& loc, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
return internal::vformat(loc, to_string_view(format_str), args);
}
-template <typename S, typename... Args>
-inline std::basic_string<FMT_CHAR(S)> format(const std::locale& loc,
- const S& format_str,
- const Args&... args) {
+template <typename S, typename... Args, typename Char = char_t<S>>
+inline std::basic_string<Char> format(const std::locale& loc,
+ const S& format_str,
+ const Args&... args) {
return internal::vformat(loc, to_string_view(format_str),
{internal::make_args_checked(format_str, args...)});
}
-template <typename String, typename OutputIt, typename... Args,
- FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value)>
-inline OutputIt vformat_to(
- OutputIt out, const std::locale& loc, const String& format_str,
- typename format_args_t<OutputIt, FMT_CHAR(String)>::type args) {
- typedef output_range<OutputIt, FMT_CHAR(String)> range;
+template <typename S, typename OutputIt, typename... Args,
+ typename Char = enable_if_t<
+ internal::is_output_iterator<OutputIt>::value, char_t<S>>>
+inline OutputIt vformat_to(OutputIt out, const std::locale& loc,
+ const S& format_str,
+ typename format_args_t<OutputIt, Char>::type args) {
+ using range = output_range<OutputIt, Char>;
return vformat_to<arg_formatter<range>>(
range(out), to_string_view(format_str), args, internal::locale_ref(loc));
}
template <typename OutputIt, typename S, typename... Args,
- FMT_ENABLE_IF(internal::is_string<S>::value&&
- internal::is_output_iterator<OutputIt>::value)>
+ FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value&&
+ internal::is_string<S>::value)>
inline OutputIt format_to(OutputIt out, const std::locale& loc,
const S& format_str, const Args&... args) {
internal::check_format_string<Args...>(format_str);
- typedef typename format_context_t<OutputIt, FMT_CHAR(S)>::type context;
+ using context = typename format_context_t<OutputIt, char_t<S>>::type;
format_arg_store<context, Args...> as{args...};
return vformat_to(out, loc, to_string_view(format_str),
basic_format_args<context>(as));
diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h
index 47d81a9..0399108 100644
--- a/include/fmt/ostream.h
+++ b/include/fmt/ostream.h
@@ -120,13 +120,13 @@
};
template <typename Char>
-inline void vprint(
- std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
- basic_format_args<typename buffer_context<Char>::type> args) {
+void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
+ basic_format_args<typename buffer_context<Char>::type> args) {
basic_memory_buffer<Char> buffer;
internal::vformat_to(buffer, format_str, args);
internal::write(os, buffer);
}
+
/**
\rst
Prints formatted data to the stream *os*.
@@ -137,8 +137,8 @@
\endrst
*/
template <typename S, typename... Args,
- FMT_ENABLE_IF(internal::is_string<S>::value)>
-inline void print(std::basic_ostream<FMT_CHAR(S)>& os, const S& format_str,
+ typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
+inline void print(std::basic_ostream<Char>& os, const S& format_str,
const Args&... args) {
vprint(os, to_string_view(format_str),
{internal::make_args_checked(format_str, args...)});
diff --git a/include/fmt/prepare.h b/include/fmt/prepare.h
index 7bfe73d..7f4ff08 100644
--- a/include/fmt/prepare.h
+++ b/include/fmt/prepare.h
@@ -185,8 +185,8 @@
template <typename Format, typename PreparedPartsProvider, typename... Args>
class prepared_format {
public:
- typedef FMT_CHAR(Format) char_type;
- typedef format_part<char_type> format_part_t;
+ using char_type = char_t<Format>;
+ using format_part_t = format_part<char_type>;
prepared_format(Format f)
: format_(std::move(f)), parts_provider_(to_string_view(format_)) {}
@@ -351,7 +351,7 @@
template <typename Format> class compiletime_prepared_parts_type_provider {
private:
- typedef FMT_CHAR(Format) char_type;
+ using char_type = char_t<Format>;
class count_handler {
private:
@@ -649,7 +649,7 @@
// Delegate preparing to preparator, to take advantage of a partial
// specialization.
template <typename Format, typename... Args> struct preparator {
- typedef parts_container<FMT_CHAR(Format)> container;
+ typedef parts_container<char_t<Format>> container;
typedef typename basic_prepared_format<Format, container, Args...>::type
prepared_format_type;
diff --git a/include/fmt/printf.h b/include/fmt/printf.h
index f879dc8..3dbf1fc 100644
--- a/include/fmt/printf.h
+++ b/include/fmt/printf.h
@@ -608,7 +608,7 @@
return {args...};
}
-template <typename S, typename Char = FMT_CHAR(S)>
+template <typename S, typename Char = char_t<S>>
inline std::basic_string<Char> vsprintf(
const S& format,
basic_format_args<
@@ -629,16 +629,14 @@
\endrst
*/
template <typename S, typename... Args,
- FMT_ENABLE_IF(internal::is_string<S>::value)>
-inline std::basic_string<FMT_CHAR(S)> sprintf(const S& format,
- const Args&... args) {
- typedef internal::buffer<FMT_CHAR(S)> buffer;
- typedef typename basic_printf_context_t<buffer>::type context;
+ typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
+inline std::basic_string<Char> sprintf(const S& format, const Args&... args) {
+ using context = typename basic_printf_context_t<internal::buffer<Char>>::type;
format_arg_store<context, Args...> as{args...};
return vsprintf(to_string_view(format), basic_format_args<context>(as));
}
-template <typename S, typename Char = FMT_CHAR(S)>
+template <typename S, typename Char = char_t<S>>
inline int vfprintf(
std::FILE* f, const S& format,
basic_format_args<
@@ -662,15 +660,14 @@
\endrst
*/
template <typename S, typename... Args,
- FMT_ENABLE_IF(internal::is_string<S>::value)>
+ typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline int fprintf(std::FILE* f, const S& format, const Args&... args) {
- typedef internal::buffer<FMT_CHAR(S)> buffer;
- typedef typename basic_printf_context_t<buffer>::type context;
+ using context = typename basic_printf_context_t<internal::buffer<Char>>::type;
format_arg_store<context, Args...> as{args...};
return vfprintf(f, to_string_view(format), basic_format_args<context>(as));
}
-template <typename S, typename Char = FMT_CHAR(S)>
+template <typename S, typename Char = char_t<S>>
inline int vprintf(
const S& format,
basic_format_args<
@@ -692,13 +689,13 @@
FMT_ENABLE_IF(internal::is_string<S>::value)>
inline int printf(const S& format_str, const Args&... args) {
internal::check_format_string<Args...>(format_str);
- typedef internal::buffer<FMT_CHAR(S)> buffer;
- typedef typename basic_printf_context_t<buffer>::type context;
+ using buffer = internal::buffer<char_t<S>>;
+ using context = typename basic_printf_context_t<buffer>::type;
format_arg_store<context, Args...> as{args...};
return vprintf(to_string_view(format_str), basic_format_args<context>(as));
}
-template <typename S, typename Char = FMT_CHAR(S)>
+template <typename S, typename Char = char_t<S>>
inline int vfprintf(
std::basic_ostream<Char>& os, const S& format,
basic_format_args<
@@ -731,13 +728,11 @@
fmt::fprintf(cerr, "Don't %s!", "panic");
\endrst
*/
-template <typename S, typename... Args,
- FMT_ENABLE_IF(internal::is_string<S>::value)>
-inline int fprintf(std::basic_ostream<FMT_CHAR(S)>& os, const S& format_str,
+template <typename S, typename... Args, typename Char = char_t<S>>
+inline int fprintf(std::basic_ostream<Char>& os, const S& format_str,
const Args&... args) {
internal::check_format_string<Args...>(format_str);
- typedef internal::buffer<FMT_CHAR(S)> buffer;
- typedef typename basic_printf_context_t<buffer>::type context;
+ using context = typename basic_printf_context_t<internal::buffer<Char>>::type;
format_arg_store<context, Args...> as{args...};
return vfprintf(os, to_string_view(format_str),
basic_format_args<context>(as));