@@ -147,7 +147,7 @@ namespace detail {
147
147
// Test whether type T1 is convertible to type T2
148
148
template <typename T1, typename T2>
149
149
struct is_convertible {
150
- private:
150
+ private:
151
151
// two types of different size
152
152
struct fail {
153
153
char dummy[2 ];
@@ -160,7 +160,7 @@ struct is_convertible {
160
160
static succeed tryConvert (const T2 &);
161
161
static const T1 &makeT1 ();
162
162
163
- public:
163
+ public:
164
164
// Standard trick: the (...) version of tryConvert will be chosen from
165
165
// the overload set only if the version taking a T2 doesn't match.
166
166
// Then we compare the sizes of the return types to check which
@@ -170,7 +170,8 @@ struct is_convertible {
170
170
171
171
// Format the value by casting to type fmtT. This default implementation
172
172
// should never be called.
173
- template <typename T, typename fmtT,
173
+ template <typename T,
174
+ typename fmtT,
174
175
bool convertible = is_convertible<T, fmtT>::value>
175
176
struct formatValueAsType {
176
177
static void invoke (std::ostream & /* out*/ , const T & /* value*/ ) { assert (0 ); }
@@ -240,8 +241,11 @@ TINYFORMAT_DEFINE_FORMAT_TRUNCATED_CSTR(char)
240
241
// / operator<< to format the type T, with special cases for the %c and %p
241
242
// / conversions.
242
243
template <typename T>
243
- inline void formatValue (std::ostream &out, const char * /* fmtBegin*/ ,
244
- const char *fmtEnd, int ntrunc, const T &value) {
244
+ inline void formatValue (std::ostream &out,
245
+ const char * /* fmtBegin*/ ,
246
+ const char *fmtEnd,
247
+ int ntrunc,
248
+ const T &value) {
245
249
// The mess here is to support the %c and %p conversions: if these
246
250
// conversions are active we try to convert the type to a char or const
247
251
// void* respectively and format that instead of the value itself. For the
@@ -263,22 +267,25 @@ inline void formatValue(std::ostream &out, const char * /*fmtBegin*/,
263
267
}
264
268
265
269
// Overloaded version for char types to support printing as an integer
266
- #define TINYFORMAT_DEFINE_FORMATVALUE_CHAR (charType ) \
267
- inline void formatValue (std::ostream &out, const char * /* fmtBegin*/ , \
268
- const char *fmtEnd, int /* */ , charType value) { \
269
- switch (*(fmtEnd - 1 )) { \
270
- case ' u' : \
271
- case ' d' : \
272
- case ' i' : \
273
- case ' o' : \
274
- case ' X' : \
275
- case ' x' : \
276
- out << static_cast <int >(value); \
277
- break ; \
278
- default : \
279
- out << value; \
280
- break ; \
281
- } \
270
+ #define TINYFORMAT_DEFINE_FORMATVALUE_CHAR (charType ) \
271
+ inline void formatValue (std::ostream &out, \
272
+ const char * /* fmtBegin*/ , \
273
+ const char *fmtEnd, \
274
+ int /* */ , \
275
+ charType value) { \
276
+ switch (*(fmtEnd - 1 )) { \
277
+ case ' u' : \
278
+ case ' d' : \
279
+ case ' i' : \
280
+ case ' o' : \
281
+ case ' X' : \
282
+ case ' x' : \
283
+ out << static_cast <int >(value); \
284
+ break ; \
285
+ default : \
286
+ out << value; \
287
+ break ; \
288
+ } \
282
289
}
283
290
// per 3.9.1: char, signed char and unsigned char are all distinct types
284
291
TINYFORMAT_DEFINE_FORMATVALUE_CHAR (char )
@@ -475,7 +482,7 @@ namespace detail {
475
482
// each argument to be allocated as a homogenous array inside FormatList
476
483
// whereas a naive implementation based on inheritance does not.
477
484
class FormatArg {
478
- public:
485
+ public:
479
486
FormatArg () {}
480
487
481
488
template <typename T>
@@ -484,17 +491,22 @@ class FormatArg {
484
491
m_formatImpl (&formatImpl<T>),
485
492
m_toIntImpl(&toIntImpl<T>) {}
486
493
487
- void format (std::ostream &out, const char *fmtBegin, const char *fmtEnd,
494
+ void format (std::ostream &out,
495
+ const char *fmtBegin,
496
+ const char *fmtEnd,
488
497
int ntrunc) const {
489
498
m_formatImpl (out, fmtBegin, fmtEnd, ntrunc, m_value);
490
499
}
491
500
492
501
int toInt () const { return m_toIntImpl (m_value); }
493
502
494
- private:
503
+ private:
495
504
template <typename T>
496
- static void formatImpl (std::ostream &out, const char *fmtBegin,
497
- const char *fmtEnd, int ntrunc, const void *value) {
505
+ static void formatImpl (std::ostream &out,
506
+ const char *fmtBegin,
507
+ const char *fmtEnd,
508
+ int ntrunc,
509
+ const void *value) {
498
510
formatValue (out, fmtBegin, fmtEnd, ntrunc, *static_cast <const T *>(value));
499
511
}
500
512
@@ -504,8 +516,11 @@ class FormatArg {
504
516
}
505
517
506
518
const void *m_value;
507
- void (*m_formatImpl)(std::ostream &out, const char *fmtBegin,
508
- const char *fmtEnd, int ntrunc, const void *value);
519
+ void (*m_formatImpl)(std::ostream &out,
520
+ const char *fmtBegin,
521
+ const char *fmtEnd,
522
+ int ntrunc,
523
+ const void *value);
509
524
int (*m_toIntImpl)(const void *value);
510
525
};
511
526
@@ -554,10 +569,12 @@ inline const char *printFormatStringLiteral(std::ostream &out,
554
569
// necessary to pull out variable width and precision . The function returns a
555
570
// pointer to the character after the end of the current format spec.
556
571
inline const char *streamStateFromFormat (std::ostream &out,
557
- bool &spacePadPositive, int &ntrunc,
572
+ bool &spacePadPositive,
573
+ int &ntrunc,
558
574
const char *fmtStart,
559
575
const detail::FormatArg *formatters,
560
- int &argIndex, int numFormatters) {
576
+ int &argIndex,
577
+ int numFormatters) {
561
578
if (*fmtStart != ' %' ) {
562
579
TINYFORMAT_ERROR (
563
580
" tinyformat: Not enough conversion specifiers in format string" );
@@ -733,8 +750,10 @@ inline const char *streamStateFromFormat(std::ostream &out,
733
750
}
734
751
735
752
// ------------------------------------------------------------------------------
736
- inline void formatImpl (std::ostream &out, const char *fmt,
737
- const detail::FormatArg *formatters, int numFormatters) {
753
+ inline void formatImpl (std::ostream &out,
754
+ const char *fmt,
755
+ const detail::FormatArg *formatters,
756
+ int numFormatters) {
738
757
// Saved stream state
739
758
std::streamsize origWidth = out.width ();
740
759
std::streamsize origPrecision = out.precision ();
@@ -746,9 +765,13 @@ inline void formatImpl(std::ostream &out, const char *fmt,
746
765
fmt = printFormatStringLiteral (out, fmt);
747
766
bool spacePadPositive = false ;
748
767
int ntrunc = -1 ;
749
- const char *fmtEnd =
750
- streamStateFromFormat (out, spacePadPositive, ntrunc, fmt, formatters,
751
- argIndex, numFormatters);
768
+ const char *fmtEnd = streamStateFromFormat (out,
769
+ spacePadPositive,
770
+ ntrunc,
771
+ fmt,
772
+ formatters,
773
+ argIndex,
774
+ numFormatters);
752
775
if (argIndex >= numFormatters) {
753
776
// Check args remain after reading any variable width/precision
754
777
TINYFORMAT_ERROR (" tinyformat: Not enough format arguments" );
@@ -797,14 +820,15 @@ inline void formatImpl(std::ostream &out, const char *fmt,
797
820
// / information has been stripped from the arguments, leaving just enough of a
798
821
// / common interface to perform formatting as required.
799
822
class FormatList {
800
- public:
823
+ public:
801
824
FormatList (detail::FormatArg *formatters, int N)
802
825
: m_formatters(formatters), m_N(N) {}
803
826
804
- friend void vformat (std::ostream &out, const char *fmt,
827
+ friend void vformat (std::ostream &out,
828
+ const char *fmt,
805
829
const FormatList &list);
806
830
807
- private:
831
+ private:
808
832
const detail::FormatArg *m_formatters;
809
833
int m_N;
810
834
};
@@ -817,22 +841,22 @@ namespace detail {
817
841
// Format list subclass with fixed storage to avoid dynamic allocation
818
842
template <int N>
819
843
class FormatListN : public FormatList {
820
- public:
844
+ public:
821
845
template <typename ... Args>
822
846
FormatListN (const Args &... args)
823
847
: FormatList(&m_formatterStore[0 ], N),
824
848
m_formatterStore{FormatArg (args)...} {
825
849
static_assert (sizeof ...(args) == N, " Number of args must be N" );
826
850
}
827
851
828
- private:
852
+ private:
829
853
FormatArg m_formatterStore[N];
830
854
};
831
855
832
856
// Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard
833
857
template <>
834
858
class FormatListN <0 > : public FormatList {
835
- public:
859
+ public:
836
860
FormatListN () : FormatList(0 , 0 ) {}
837
861
};
838
862
0 commit comments