FMT_CHAR -> char_t

This commit is contained in:
Victor Zverovich committed 2019-06-02 15:03:37 -07:00
1 parent 56d2b91108
commit 4d4b8c238d
7 files changed
+99 -94

No files matched your search

+29 -19
View File
@@ -617,7 +617,7 @@ struct is_string
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 @@ FMT_CONSTEXPR11 init<C, basic_string_view<typename C::char_type>, string_type>
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 @@ struct wformat_args : basic_format_args<wformat_context> {
};
/** 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 @@ template <typename... Args, typename S,
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 @@ typename buffer_context<Char>::type::iterator vformat_to(
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 @@ struct is_contiguous<std::basic_string<Char>> : std::true_type {};
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 @@ inline std::back_insert_iterator<Container> format_to(
{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 @@ inline std::basic_string<Char> vformat(
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...)});
}