Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaE committed Oct 1, 2018
1 parent 419ab43 commit f7cd995
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3569,19 +3569,31 @@ inline format_to_n_result<OutputIt> vformat_to_n(
end of the output range.
\endrst
*/
template <typename OutputIt, typename... Args>
inline format_to_n_result<OutputIt> format_to_n(
OutputIt out, std::size_t n, string_view format_str, const Args &... args) {
return vformat_to_n<OutputIt>(
out, n, format_str, make_format_to_n_args<OutputIt>(args...));
template <typename OutputIt, typename String, typename... Args>
inline typename std::enable_if<
internal::is_format_string<String>::value &&
std::is_same<FMT_CHAR(String), char>::value,
format_to_n_result<OutputIt>>::type format_to_n(
OutputIt out, std::size_t n, const String &format_str, const Args &... args) {
internal::check_format_string<Args...>(format_str);
typedef FMT_CHAR(String) char_t;
typedef format_to_n_context<OutputIt> context_t;
format_arg_store<context_t, Args...> as{ args... };
return vformat_to_n<OutputIt>(out, n, basic_string_view<char_t>(format_str), as);
}
template <typename OutputIt, typename... Args>
inline format_to_n_result<OutputIt> format_to_n(
OutputIt out, std::size_t n, wstring_view format_str,
const Args &... args) {

template <typename OutputIt, typename String, typename... Args>
inline typename std::enable_if<
internal::is_format_string<String>::value &&
!std::is_same<FMT_CHAR(String), char>::value,
format_to_n_result<OutputIt>>::type format_to_n(
OutputIt out, std::size_t n, const String &format_str, const Args &... args) {
internal::check_format_string<Args...>(format_str);
typedef FMT_CHAR(String) char_t;
typedef internal::truncating_iterator<OutputIt> It;
auto it = vformat_to(It(out, n), format_str,
make_format_args<typename format_context_t<It, wchar_t>::type>(args...));
typedef typename format_context_t<It, char_t>::type context_t;
format_arg_store<context_t, Args...> as{ args... };
auto it = vformat_to(It(out, n), basic_string_view<char_t>(format_str), as);
return {it.base(), it.count()};
}

Expand Down

0 comments on commit f7cd995

Please sign in to comment.