Skip to content

Commit

Permalink
Parameterize core functions on the type of the format string.
Browse files Browse the repository at this point in the history
Take #1 of n

Signed-off-by: Daniela Engert <dani@ngrt.de>
  • Loading branch information
DanielaE committed Sep 27, 2018
1 parent e864acf commit 6206649
Showing 1 changed file with 31 additions and 39 deletions.
70 changes: 31 additions & 39 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1341,26 +1341,20 @@ typename std::enable_if<
return out;
}

template <typename Container, typename... Args>
inline typename std::enable_if<
is_contiguous<Container>::value, std::back_insert_iterator<Container>>::type
format_to(std::back_insert_iterator<Container> out,
string_view format_str, const Args &... args) {
format_arg_store<format_context, Args...> as{args...};
return vformat_to(out, format_str, as);
}

template <typename Container, typename... Args>
#define FMT_CHAR(Str) typename internal::format_string_traits<Str>::char_type
template <typename Container, typename String, typename... Args>
inline typename std::enable_if<
is_contiguous<Container>::value, std::back_insert_iterator<Container>>::type
is_contiguous<Container>::value && internal::is_format_string<String>::value,
std::back_insert_iterator<Container>>::type
format_to(std::back_insert_iterator<Container> out,
wstring_view format_str, const Args &... args) {
return vformat_to(out, format_str,
make_format_args<wformat_context>(args...));
const String &format_str, const Args &... args) {
internal::check_format_string<Args...>(format_str);
typedef typename buffer_context< FMT_CHAR(String) >::type context_t;
format_arg_store<context_t, Args...> as{args...};
return vformat_to(out, basic_string_view< FMT_CHAR(String) >(format_str),
basic_format_args<context_t>(as));
}

#define FMT_CHAR(Str) typename internal::format_string_traits<Str>::char_type

template <typename String, typename Char = FMT_CHAR(String) >
inline std::basic_string<Char> vformat(
const String &format_str,
Expand Down Expand Up @@ -1402,21 +1396,21 @@ FMT_API void vprint(std::FILE *f, wstring_view format_str, wformat_args args);
**Example**::
fmt::print(stderr, "Don't {}!", "panic");
\endrst
*/
template <typename... Args>
inline void print(std::FILE *f, string_view format_str, const Args &... args) {
format_arg_store<format_context, Args...> as(args...);
vprint(f, format_str, as);
}
/**
Prints formatted data to the file *f* which should be in wide-oriented mode
**Hint**::
for wide format strings, *f* should be in wide-oriented mode
set via ``fwide(f, 1)`` or ``_setmode(_fileno(f), _O_U8TEXT)`` on Windows.
\endrst
*/
template <typename... Args>
inline void print(std::FILE *f, wstring_view format_str, const Args &... args) {
format_arg_store<wformat_context, Args...> as(args...);
vprint(f, format_str, as);
template <typename String, typename... Args>
inline typename std::enable_if<internal::is_format_string<String>::value>::type
print(std::FILE *f, const String &format_str, const Args &... args) {
internal::check_format_string<Args...>(format_str);
typedef typename buffer_context< FMT_CHAR(String) >::type context_t;
format_arg_store<context_t, Args...> as{ args... };
vprint(f, basic_string_view< FMT_CHAR(String) >(format_str),
basic_format_args<context_t>(as));
}

FMT_API void vprint(string_view format_str, format_args args);
Expand All @@ -1431,16 +1425,14 @@ FMT_API void vprint(wstring_view format_str, wformat_args args);
fmt::print("Elapsed time: {0:.2f} seconds", 1.23);
\endrst
*/
template <typename... Args>
inline void print(string_view format_str, const Args &... args) {
format_arg_store<format_context, Args...> as{args...};
vprint(format_str, as);
}

template <typename... Args>
inline void print(wstring_view format_str, const Args &... args) {
format_arg_store<wformat_context, Args...> as(args...);
vprint(format_str, as);
template <typename String, typename... Args>
inline typename std::enable_if<internal::is_format_string<String>::value>::type
print(const String &format_str, const Args &... args) {
internal::check_format_string<Args...>(format_str);
typedef typename buffer_context< FMT_CHAR(String) >::type context_t;
format_arg_store<context_t, Args...> as{ args... };
vprint(basic_string_view< FMT_CHAR(String) >(format_str),
basic_format_args<context_t>(as));
}
FMT_END_NAMESPACE

Expand Down

0 comments on commit 6206649

Please sign in to comment.