diff --git a/include/fmt/format.h b/include/fmt/format.h index 165c22ae..a556a6d6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -586,14 +586,34 @@ extern template int char_traits::format_float( int precision, long double value); #endif +#if FMT_SECURE_SCL +template +struct pointer { typedef stdext::checked_array_iterator type; }; +// Returns pointer value. +template +static T *get(typename pointer::type p) { return p.base(); } +template +static typename pointer::type make_pointer(T* p, std::size_t n) { + return {p, n}; +} +#else +template +struct pointer { typedef T *type; }; +template +static T *get(T *p) { return p; } +template +static T *make_pointer(T *p, std::size_t) { return p; } +#endif + template inline typename std::enable_if< - is_contiguous::value, typename Container::value_type*>::type + is_contiguous::value, + typename pointer::type>::type reserve(std::back_insert_iterator &it, std::size_t n) { Container &c = internal::get_container(it); std::size_t size = c.size(); c.resize(size + n); - return &c[size]; + return make_pointer(&c[size], n); } template @@ -927,7 +947,8 @@ class add_thousands_sep { explicit add_thousands_sep(basic_string_view sep) : sep_(sep), digit_index_(0) {} - void operator()(Char *&buffer) { + template + void operator()(BufChar *&buffer) { if (++digit_index_ % 3 != 0) return; buffer -= sep_.size(); @@ -971,10 +992,10 @@ inline Char *format_decimal(Char *buffer, UInt value, unsigned num_digits, template inline Iterator format_decimal( - Iterator out, UInt value, unsigned num_digits, ThousandsSep) { + Iterator out, UInt value, unsigned num_digits, ThousandsSep sep) { // Buffer should be large enough to hold all digits (digits10 + 1) and null. char buffer[std::numeric_limits::digits10 + 2]; - format_decimal(buffer, value, num_digits, no_thousands_sep()); + format_decimal(buffer, value, num_digits, sep); return std::copy_n(buffer, num_digits, out); } @@ -2299,15 +2320,6 @@ class basic_writer { FMT_DISALLOW_COPY_AND_ASSIGN(basic_writer); -#if FMT_SECURE_SCL - typedef stdext::checked_array_iterator pointer_type; - // Returns pointer value. - static char_type *get(pointer_type p) { return p.base(); } -#else - typedef char_type* pointer_type; - static char_type *get(char_type *p) { return p; } -#endif - iterator out() const { return out_; } // Attempts to reserve space for n extra characters in the output range.