You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tinyformat.h 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. // tinyformat.h
  2. // Copyright (C) 2011, Chris Foster [chris42f (at) gmail (d0t) com]
  3. //
  4. // Boost Software License - Version 1.0
  5. //
  6. // Permission is hereby granted, free of charge, to any person or organization
  7. // obtaining a copy of the software and accompanying documentation covered by
  8. // this license (the "Software") to use, reproduce, display, distribute,
  9. // execute, and transmit the Software, and to prepare derivative works of the
  10. // Software, and to permit third-parties to whom the Software is furnished to
  11. // do so, all subject to the following:
  12. //
  13. // The copyright notices in the Software and this entire statement, including
  14. // the above license grant, this restriction and the following disclaimer,
  15. // must be included in all copies of the Software, in whole or in part, and
  16. // all derivative works of the Software, unless such copies or derivative
  17. // works are solely in the form of machine-executable object code generated by
  18. // a source language processor.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  23. // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  24. // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  25. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  26. // DEALINGS IN THE SOFTWARE.
  27. //------------------------------------------------------------------------------
  28. // Tinyformat: A minimal type safe printf replacement
  29. //
  30. // tinyformat.h is a type safe printf replacement library in a single C++
  31. // header file. Design goals include:
  32. //
  33. // * Type safety and extensibility for user defined types.
  34. // * C99 printf() compatibility, to the extent possible using std::ostream
  35. // * Simplicity and minimalism. A single header file to include and distribute
  36. // with your projects.
  37. // * Augment rather than replace the standard stream formatting mechanism
  38. // * C++98 support, with optional C++11 niceties
  39. //
  40. //
  41. // Main interface example usage
  42. // ----------------------------
  43. //
  44. // To print a date to std::cout:
  45. //
  46. // std::string weekday = "Wednesday";
  47. // const char* month = "July";
  48. // size_t day = 27;
  49. // long hour = 14;
  50. // int min = 44;
  51. //
  52. // tfm::printf("%s, %s %d, %.2d:%.2d\n", weekday, month, day, hour, min);
  53. //
  54. // The strange types here emphasize the type safety of the interface; it is
  55. // possible to print a std::string using the "%s" conversion, and a
  56. // size_t using the "%d" conversion. A similar result could be achieved
  57. // using either of the tfm::format() functions. One prints on a user provided
  58. // stream:
  59. //
  60. // tfm::format(std::cerr, "%s, %s %d, %.2d:%.2d\n",
  61. // weekday, month, day, hour, min);
  62. //
  63. // The other returns a std::string:
  64. //
  65. // std::string date = tfm::format("%s, %s %d, %.2d:%.2d\n",
  66. // weekday, month, day, hour, min);
  67. // std::cout << date;
  68. //
  69. // These are the three primary interface functions.
  70. //
  71. //
  72. // User defined format functions
  73. // -----------------------------
  74. //
  75. // Simulating variadic templates in C++98 is pretty painful since it requires
  76. // writing out the same function for each desired number of arguments. To make
  77. // this bearable tinyformat comes with a set of macros which are used
  78. // internally to generate the API, but which may also be used in user code.
  79. //
  80. // The three macros TINYFORMAT_ARGTYPES(n), TINYFORMAT_VARARGS(n) and
  81. // TINYFORMAT_PASSARGS(n) will generate a list of n argument types,
  82. // type/name pairs and argument names respectively when called with an integer
  83. // n between 1 and 16. We can use these to define a macro which generates the
  84. // desired user defined function with n arguments. To generate all 16 user
  85. // defined function bodies, use the macro TINYFORMAT_FOREACH_ARGNUM. For an
  86. // example, see the implementation of printf() at the end of the source file.
  87. //
  88. //
  89. // Additional API information
  90. // --------------------------
  91. //
  92. // Error handling: Define TINYFORMAT_ERROR to customize the error handling for
  93. // format strings which are unsupported or have the wrong number of format
  94. // specifiers (calls assert() by default).
  95. //
  96. // User defined types: Uses operator<< for user defined types by default.
  97. // Overload formatValue() for more control.
  98. #ifndef TINYFORMAT_H_INCLUDED
  99. #define TINYFORMAT_H_INCLUDED
  100. namespace tinyformat {}
  101. //------------------------------------------------------------------------------
  102. // Config section. Customize to your liking!
  103. // Namespace alias to encourage brevity
  104. namespace tfm = tinyformat;
  105. // Error handling; calls assert() by default.
  106. #define TINYFORMAT_ERROR(reasonString) throw std::runtime_error(reasonString)
  107. // Define for C++11 variadic templates which make the code shorter & more
  108. // general. If you don't define this, C++11 support is autodetected below.
  109. // #define TINYFORMAT_USE_VARIADIC_TEMPLATES
  110. //------------------------------------------------------------------------------
  111. // Implementation details.
  112. #include <cassert>
  113. #include <iostream>
  114. #include <sstream>
  115. #include <stdexcept>
  116. #ifndef TINYFORMAT_ERROR
  117. # define TINYFORMAT_ERROR(reason) assert(0 && reason)
  118. #endif
  119. #if !defined(TINYFORMAT_USE_VARIADIC_TEMPLATES) && !defined(TINYFORMAT_NO_VARIADIC_TEMPLATES)
  120. # ifdef __GXX_EXPERIMENTAL_CXX0X__
  121. # define TINYFORMAT_USE_VARIADIC_TEMPLATES
  122. # endif
  123. #endif
  124. #ifdef __GNUC__
  125. # define TINYFORMAT_NOINLINE __attribute__((noinline))
  126. #elif defined(_MSC_VER)
  127. # define TINYFORMAT_NOINLINE __declspec(noinline)
  128. #else
  129. # define TINYFORMAT_NOINLINE
  130. #endif
  131. #if defined(__GLIBCXX__) && __GLIBCXX__ < 20080201
  132. // std::showpos is broken on old libstdc++ as provided with OSX. See
  133. // http://gcc.gnu.org/ml/libstdc++/2007-11/msg00075.html
  134. # define TINYFORMAT_OLD_LIBSTDCPLUSPLUS_WORKAROUND
  135. #endif
  136. namespace tinyformat {
  137. //------------------------------------------------------------------------------
  138. namespace detail {
  139. // Test whether type T1 is convertible to type T2
  140. template <typename T1, typename T2>
  141. struct is_convertible
  142. {
  143. private:
  144. // two types of different size
  145. struct fail { char dummy[2]; };
  146. struct succeed { char dummy; };
  147. // Try to convert a T1 to a T2 by plugging into tryConvert
  148. static fail tryConvert(...);
  149. static succeed tryConvert(const T2&);
  150. static const T1& makeT1();
  151. public:
  152. # ifdef _MSC_VER
  153. // Disable spurious loss of precision warnings in tryConvert(makeT1())
  154. # pragma warning(push)
  155. # pragma warning(disable:4244)
  156. # pragma warning(disable:4267)
  157. # endif
  158. // Standard trick: the (...) version of tryConvert will be chosen from
  159. // the overload set only if the version taking a T2 doesn't match.
  160. // Then we compare the sizes of the return types to check which
  161. // function matched. Very neat, in a disgusting kind of way :)
  162. static const bool value =
  163. sizeof(tryConvert(makeT1())) == sizeof(succeed);
  164. # ifdef _MSC_VER
  165. # pragma warning(pop)
  166. # endif
  167. };
  168. // Detect when a type is not a wchar_t string
  169. template<typename T> struct is_wchar { typedef int tinyformat_wchar_is_not_supported; };
  170. template<> struct is_wchar<wchar_t*> {};
  171. template<> struct is_wchar<const wchar_t*> {};
  172. template<int n> struct is_wchar<const wchar_t[n]> {};
  173. template<int n> struct is_wchar<wchar_t[n]> {};
  174. // Format the value by casting to type fmtT. This default implementation
  175. // should never be called.
  176. template<typename T, typename fmtT, bool convertible = is_convertible<T, fmtT>::value>
  177. struct formatValueAsType
  178. {
  179. static void invoke(std::ostream& /*out*/, const T& /*value*/) { assert(0); }
  180. };
  181. // Specialized version for types that can actually be converted to fmtT, as
  182. // indicated by the "convertible" template parameter.
  183. template<typename T, typename fmtT>
  184. struct formatValueAsType<T,fmtT,true>
  185. {
  186. static void invoke(std::ostream& out, const T& value)
  187. { out << static_cast<fmtT>(value); }
  188. };
  189. #ifdef TINYFORMAT_OLD_LIBSTDCPLUSPLUS_WORKAROUND
  190. template<typename T, bool convertible = is_convertible<T, int>::value>
  191. struct formatZeroIntegerWorkaround
  192. {
  193. static bool invoke(std::ostream& /**/, const T& /**/) { return false; }
  194. };
  195. template<typename T>
  196. struct formatZeroIntegerWorkaround<T,true>
  197. {
  198. static bool invoke(std::ostream& out, const T& value)
  199. {
  200. if (static_cast<int>(value) == 0 && out.flags() & std::ios::showpos)
  201. {
  202. out << "+0";
  203. return true;
  204. }
  205. return false;
  206. }
  207. };
  208. #endif // TINYFORMAT_OLD_LIBSTDCPLUSPLUS_WORKAROUND
  209. // Convert an arbitrary type to integer. The version with convertible=false
  210. // throws an error.
  211. template<typename T, bool convertible = is_convertible<T,int>::value>
  212. struct convertToInt
  213. {
  214. static int invoke(const T& /*value*/)
  215. {
  216. TINYFORMAT_ERROR("tinyformat: Cannot convert from argument type to "
  217. "integer for use as variable width or precision");
  218. return 0;
  219. }
  220. };
  221. // Specialization for convertToInt when conversion is possible
  222. template<typename T>
  223. struct convertToInt<T,true>
  224. {
  225. static int invoke(const T& value) { return static_cast<int>(value); }
  226. };
  227. } // namespace detail
  228. //------------------------------------------------------------------------------
  229. // Variable formatting functions. May be overridden for user-defined types if
  230. // desired.
  231. // Format a value into a stream. Called from format() for all types by default.
  232. //
  233. // Users may override this for their own types. When this function is called,
  234. // the stream flags will have been modified according to the format string.
  235. // The format specification is provided in the range [fmtBegin, fmtEnd).
  236. //
  237. // By default, formatValue() uses the usual stream insertion operator
  238. // operator<< to format the type T, with special cases for the %c and %p
  239. // conversions.
  240. template<typename T>
  241. inline void formatValue(std::ostream& out, const char* /*fmtBegin*/,
  242. const char* fmtEnd, const T& value)
  243. {
  244. #ifndef TINYFORMAT_ALLOW_WCHAR_STRINGS
  245. // Since we don't support printing of wchar_t using "%ls", make it fail at
  246. // compile time in preference to printing as a void* at runtime.
  247. typedef typename detail::is_wchar<T>::tinyformat_wchar_is_not_supported DummyType;
  248. (void) DummyType(); // avoid unused type warning with gcc-4.8
  249. #endif
  250. // The mess here is to support the %c and %p conversions: if these
  251. // conversions are active we try to convert the type to a char or const
  252. // void* respectively and format that instead of the value itself. For the
  253. // %p conversion it's important to avoid dereferencing the pointer, which
  254. // could otherwise lead to a crash when printing a dangling (const char*).
  255. const bool canConvertToChar = detail::is_convertible<T,char>::value;
  256. const bool canConvertToVoidPtr = detail::is_convertible<T, const void*>::value;
  257. if(canConvertToChar && *(fmtEnd-1) == 'c')
  258. detail::formatValueAsType<T, char>::invoke(out, value);
  259. else if(canConvertToVoidPtr && *(fmtEnd-1) == 'p')
  260. detail::formatValueAsType<T, const void*>::invoke(out, value);
  261. #ifdef TINYFORMAT_OLD_LIBSTDCPLUSPLUS_WORKAROUND
  262. else if(detail::formatZeroIntegerWorkaround<T>::invoke(out, value)) /**/;
  263. #endif
  264. else
  265. out << value;
  266. }
  267. // Overloaded version for char types to support printing as an integer
  268. #define TINYFORMAT_DEFINE_FORMATVALUE_CHAR(charType) \
  269. inline void formatValue(std::ostream& out, const char* /*fmtBegin*/, \
  270. const char* fmtEnd, charType value) \
  271. { \
  272. switch(*(fmtEnd-1)) \
  273. { \
  274. case 'u': case 'd': case 'i': case 'o': case 'X': case 'x': \
  275. out << static_cast<int>(value); break; \
  276. default: \
  277. out << value; break; \
  278. } \
  279. }
  280. // per 3.9.1: char, signed char and unsigned char are all distinct types
  281. TINYFORMAT_DEFINE_FORMATVALUE_CHAR(char)
  282. TINYFORMAT_DEFINE_FORMATVALUE_CHAR(signed char)
  283. TINYFORMAT_DEFINE_FORMATVALUE_CHAR(unsigned char)
  284. #undef TINYFORMAT_DEFINE_FORMATVALUE_CHAR
  285. //------------------------------------------------------------------------------
  286. // Tools for emulating variadic templates in C++98. The basic idea here is
  287. // stolen from the boost preprocessor metaprogramming library and cut down to
  288. // be just general enough for what we need.
  289. #define TINYFORMAT_ARGTYPES(n) TINYFORMAT_ARGTYPES_ ## n
  290. #define TINYFORMAT_VARARGS(n) TINYFORMAT_VARARGS_ ## n
  291. #define TINYFORMAT_PASSARGS(n) TINYFORMAT_PASSARGS_ ## n
  292. #define TINYFORMAT_PASSARGS_TAIL(n) TINYFORMAT_PASSARGS_TAIL_ ## n
  293. // To keep it as transparent as possible, the macros below have been generated
  294. // using python via the excellent cog.py code generation script. This avoids
  295. // the need for a bunch of complex (but more general) preprocessor tricks as
  296. // used in boost.preprocessor.
  297. //
  298. // To rerun the code generation in place, use `cog.py -r tinyformat.h`
  299. // (see http://nedbatchelder.com/code/cog). Alternatively you can just create
  300. // extra versions by hand.
  301. /*[[[cog
  302. maxParams = 16
  303. def makeCommaSepLists(lineTemplate, elemTemplate, startInd=1):
  304. for j in range(startInd,maxParams+1):
  305. list = ', '.join([elemTemplate % {'i':i} for i in range(startInd,j+1)])
  306. cog.outl(lineTemplate % {'j':j, 'list':list})
  307. makeCommaSepLists('#define TINYFORMAT_ARGTYPES_%(j)d %(list)s',
  308. 'class T%(i)d')
  309. cog.outl()
  310. makeCommaSepLists('#define TINYFORMAT_VARARGS_%(j)d %(list)s',
  311. 'const T%(i)d& v%(i)d')
  312. cog.outl()
  313. makeCommaSepLists('#define TINYFORMAT_PASSARGS_%(j)d %(list)s', 'v%(i)d')
  314. cog.outl()
  315. cog.outl('#define TINYFORMAT_PASSARGS_TAIL_1')
  316. makeCommaSepLists('#define TINYFORMAT_PASSARGS_TAIL_%(j)d , %(list)s',
  317. 'v%(i)d', startInd = 2)
  318. cog.outl()
  319. cog.outl('#define TINYFORMAT_FOREACH_ARGNUM(m) \\\n ' +
  320. ' '.join(['m(%d)' % (j,) for j in range(1,maxParams+1)]))
  321. ]]]*/
  322. #define TINYFORMAT_ARGTYPES_1 class T1
  323. #define TINYFORMAT_ARGTYPES_2 class T1, class T2
  324. #define TINYFORMAT_ARGTYPES_3 class T1, class T2, class T3
  325. #define TINYFORMAT_ARGTYPES_4 class T1, class T2, class T3, class T4
  326. #define TINYFORMAT_ARGTYPES_5 class T1, class T2, class T3, class T4, class T5
  327. #define TINYFORMAT_ARGTYPES_6 class T1, class T2, class T3, class T4, class T5, class T6
  328. #define TINYFORMAT_ARGTYPES_7 class T1, class T2, class T3, class T4, class T5, class T6, class T7
  329. #define TINYFORMAT_ARGTYPES_8 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8
  330. #define TINYFORMAT_ARGTYPES_9 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9
  331. #define TINYFORMAT_ARGTYPES_10 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10
  332. #define TINYFORMAT_ARGTYPES_11 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11
  333. #define TINYFORMAT_ARGTYPES_12 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12
  334. #define TINYFORMAT_ARGTYPES_13 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13
  335. #define TINYFORMAT_ARGTYPES_14 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13, class T14
  336. #define TINYFORMAT_ARGTYPES_15 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13, class T14, class T15
  337. #define TINYFORMAT_ARGTYPES_16 class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13, class T14, class T15, class T16
  338. #define TINYFORMAT_VARARGS_1 const T1& v1
  339. #define TINYFORMAT_VARARGS_2 const T1& v1, const T2& v2
  340. #define TINYFORMAT_VARARGS_3 const T1& v1, const T2& v2, const T3& v3
  341. #define TINYFORMAT_VARARGS_4 const T1& v1, const T2& v2, const T3& v3, const T4& v4
  342. #define TINYFORMAT_VARARGS_5 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5
  343. #define TINYFORMAT_VARARGS_6 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6
  344. #define TINYFORMAT_VARARGS_7 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7
  345. #define TINYFORMAT_VARARGS_8 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8
  346. #define TINYFORMAT_VARARGS_9 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9
  347. #define TINYFORMAT_VARARGS_10 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9, const T10& v10
  348. #define TINYFORMAT_VARARGS_11 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9, const T10& v10, const T11& v11
  349. #define TINYFORMAT_VARARGS_12 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9, const T10& v10, const T11& v11, const T12& v12
  350. #define TINYFORMAT_VARARGS_13 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9, const T10& v10, const T11& v11, const T12& v12, const T13& v13
  351. #define TINYFORMAT_VARARGS_14 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9, const T10& v10, const T11& v11, const T12& v12, const T13& v13, const T14& v14
  352. #define TINYFORMAT_VARARGS_15 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9, const T10& v10, const T11& v11, const T12& v12, const T13& v13, const T14& v14, const T15& v15
  353. #define TINYFORMAT_VARARGS_16 const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5, const T6& v6, const T7& v7, const T8& v8, const T9& v9, const T10& v10, const T11& v11, const T12& v12, const T13& v13, const T14& v14, const T15& v15, const T16& v16
  354. #define TINYFORMAT_PASSARGS_1 v1
  355. #define TINYFORMAT_PASSARGS_2 v1, v2
  356. #define TINYFORMAT_PASSARGS_3 v1, v2, v3
  357. #define TINYFORMAT_PASSARGS_4 v1, v2, v3, v4
  358. #define TINYFORMAT_PASSARGS_5 v1, v2, v3, v4, v5
  359. #define TINYFORMAT_PASSARGS_6 v1, v2, v3, v4, v5, v6
  360. #define TINYFORMAT_PASSARGS_7 v1, v2, v3, v4, v5, v6, v7
  361. #define TINYFORMAT_PASSARGS_8 v1, v2, v3, v4, v5, v6, v7, v8
  362. #define TINYFORMAT_PASSARGS_9 v1, v2, v3, v4, v5, v6, v7, v8, v9
  363. #define TINYFORMAT_PASSARGS_10 v1, v2, v3, v4, v5, v6, v7, v8, v9, v10
  364. #define TINYFORMAT_PASSARGS_11 v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11
  365. #define TINYFORMAT_PASSARGS_12 v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12
  366. #define TINYFORMAT_PASSARGS_13 v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13
  367. #define TINYFORMAT_PASSARGS_14 v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14
  368. #define TINYFORMAT_PASSARGS_15 v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15
  369. #define TINYFORMAT_PASSARGS_16 v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16
  370. #define TINYFORMAT_PASSARGS_TAIL_1
  371. #define TINYFORMAT_PASSARGS_TAIL_2 , v2
  372. #define TINYFORMAT_PASSARGS_TAIL_3 , v2, v3
  373. #define TINYFORMAT_PASSARGS_TAIL_4 , v2, v3, v4
  374. #define TINYFORMAT_PASSARGS_TAIL_5 , v2, v3, v4, v5
  375. #define TINYFORMAT_PASSARGS_TAIL_6 , v2, v3, v4, v5, v6
  376. #define TINYFORMAT_PASSARGS_TAIL_7 , v2, v3, v4, v5, v6, v7
  377. #define TINYFORMAT_PASSARGS_TAIL_8 , v2, v3, v4, v5, v6, v7, v8
  378. #define TINYFORMAT_PASSARGS_TAIL_9 , v2, v3, v4, v5, v6, v7, v8, v9
  379. #define TINYFORMAT_PASSARGS_TAIL_10 , v2, v3, v4, v5, v6, v7, v8, v9, v10
  380. #define TINYFORMAT_PASSARGS_TAIL_11 , v2, v3, v4, v5, v6, v7, v8, v9, v10, v11
  381. #define TINYFORMAT_PASSARGS_TAIL_12 , v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12
  382. #define TINYFORMAT_PASSARGS_TAIL_13 , v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13
  383. #define TINYFORMAT_PASSARGS_TAIL_14 , v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14
  384. #define TINYFORMAT_PASSARGS_TAIL_15 , v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15
  385. #define TINYFORMAT_PASSARGS_TAIL_16 , v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16
  386. #define TINYFORMAT_FOREACH_ARGNUM(m) \
  387. m(1) m(2) m(3) m(4) m(5) m(6) m(7) m(8) m(9) m(10) m(11) m(12) m(13) m(14) m(15) m(16)
  388. //[[[end]]]
  389. namespace detail {
  390. // Class holding current position in format string and an output stream into
  391. // which arguments are formatted.
  392. class FormatIterator
  393. {
  394. public:
  395. // Flags for features not representable with standard stream state
  396. enum ExtraFormatFlags
  397. {
  398. Flag_None = 0,
  399. Flag_TruncateToPrecision = 1<<0, // truncate length to stream precision()
  400. Flag_SpacePadPositive = 1<<1, // pad positive values with spaces
  401. Flag_VariableWidth = 1<<2, // variable field width in arg list
  402. Flag_VariablePrecision = 1<<3 // variable field precision in arg list
  403. };
  404. // out is the output stream, fmt is the full format string
  405. FormatIterator(std::ostream& out, const char* fmt)
  406. : m_out(out),
  407. m_fmt(fmt),
  408. m_extraFlags(Flag_None),
  409. m_wantWidth(false),
  410. m_wantPrecision(false),
  411. m_variableWidth(0),
  412. m_variablePrecision(0),
  413. m_origWidth(out.width()),
  414. m_origPrecision(out.precision()),
  415. m_origFlags(out.flags()),
  416. m_origFill(out.fill())
  417. { }
  418. // Print remaining part of format string.
  419. void finish()
  420. {
  421. // It would be nice if we could do this from the destructor, but we
  422. // can't if TINFORMAT_ERROR is used to throw an exception!
  423. m_fmt = printFormatStringLiteral(m_out, m_fmt);
  424. if(*m_fmt != '\0')
  425. TINYFORMAT_ERROR("tinyformat: Too many conversion specifiers in format string");
  426. }
  427. ~FormatIterator()
  428. {
  429. // Restore stream state
  430. m_out.width(m_origWidth);
  431. m_out.precision(m_origPrecision);
  432. m_out.flags(m_origFlags);
  433. m_out.fill(m_origFill);
  434. }
  435. template<typename T>
  436. void accept(const T& value);
  437. private:
  438. // Parse and return an integer from the string c, as atoi()
  439. // On return, c is set to one past the end of the integer.
  440. static int parseIntAndAdvance(const char*& c)
  441. {
  442. int i = 0;
  443. for(;*c >= '0' && *c <= '9'; ++c)
  444. i = 10*i + (*c - '0');
  445. return i;
  446. }
  447. // Format at most truncLen characters of a C string to the given
  448. // stream. Return true if formatting proceeded (generic version always
  449. // returns false)
  450. template<typename T>
  451. static bool formatCStringTruncate(std::ostream& /*out*/, const T& /*value*/,
  452. std::streamsize /*truncLen*/)
  453. {
  454. return false;
  455. }
  456. # define TINYFORMAT_DEFINE_FORMAT_C_STRING_TRUNCATE(type) \
  457. static bool formatCStringTruncate(std::ostream& out, type* value, \
  458. std::streamsize truncLen) \
  459. { \
  460. std::streamsize len = 0; \
  461. while(len < truncLen && value[len] != 0) \
  462. ++len; \
  463. out.write(value, len); \
  464. return true; \
  465. }
  466. // Overload for const char* and char*. Could overload for signed &
  467. // unsigned char too, but these are technically unneeded for printf
  468. // compatibility.
  469. TINYFORMAT_DEFINE_FORMAT_C_STRING_TRUNCATE(const char)
  470. TINYFORMAT_DEFINE_FORMAT_C_STRING_TRUNCATE(char)
  471. # undef TINYFORMAT_DEFINE_FORMAT_C_STRING_TRUNCATE
  472. // Print literal part of format string and return next format spec
  473. // position.
  474. //
  475. // Skips over any occurrences of '%%', printing a literal '%' to the
  476. // output. The position of the first % character of the next
  477. // nontrivial format spec is returned, or the end of string.
  478. static const char* printFormatStringLiteral(std::ostream& out,
  479. const char* fmt)
  480. {
  481. const char* c = fmt;
  482. for(; true; ++c)
  483. {
  484. switch(*c)
  485. {
  486. case '\0':
  487. out.write(fmt, static_cast<std::streamsize>(c - fmt));
  488. return c;
  489. case '%':
  490. out.write(fmt, static_cast<std::streamsize>(c - fmt));
  491. if(*(c+1) != '%')
  492. return c;
  493. // for "%%", tack trailing % onto next literal section.
  494. fmt = ++c;
  495. break;
  496. }
  497. }
  498. }
  499. static const char* streamStateFromFormat(std::ostream& out,
  500. unsigned int& extraFlags,
  501. const char* fmtStart,
  502. int variableWidth,
  503. int variablePrecision);
  504. // Private copy & assign: Kill gcc warnings with -Weffc++
  505. FormatIterator(const FormatIterator&);
  506. FormatIterator& operator=(const FormatIterator&);
  507. // Stream, current format string & state
  508. std::ostream& m_out;
  509. const char* m_fmt;
  510. unsigned int m_extraFlags;
  511. // State machine info for handling of variable width & precision
  512. bool m_wantWidth;
  513. bool m_wantPrecision;
  514. int m_variableWidth;
  515. int m_variablePrecision;
  516. // Saved stream state
  517. std::streamsize m_origWidth;
  518. std::streamsize m_origPrecision;
  519. std::ios::fmtflags m_origFlags;
  520. char m_origFill;
  521. };
  522. // Accept a value for formatting into the internal stream.
  523. template<typename T>
  524. TINYFORMAT_NOINLINE // < greatly reduces bloat in optimized builds
  525. void FormatIterator::accept(const T& value)
  526. {
  527. // Parse the format string
  528. const char* fmtEnd = 0;
  529. if(m_extraFlags == Flag_None && !m_wantWidth && !m_wantPrecision)
  530. {
  531. m_fmt = printFormatStringLiteral(m_out, m_fmt);
  532. fmtEnd = streamStateFromFormat(m_out, m_extraFlags, m_fmt, 0, 0);
  533. m_wantWidth = (m_extraFlags & Flag_VariableWidth) != 0;
  534. m_wantPrecision = (m_extraFlags & Flag_VariablePrecision) != 0;
  535. }
  536. // Consume value as variable width and precision specifier if necessary
  537. if(m_extraFlags & (Flag_VariableWidth | Flag_VariablePrecision))
  538. {
  539. if(m_wantWidth || m_wantPrecision)
  540. {
  541. int v = convertToInt<T>::invoke(value);
  542. if(m_wantWidth)
  543. {
  544. m_variableWidth = v;
  545. m_wantWidth = false;
  546. }
  547. else if(m_wantPrecision)
  548. {
  549. m_variablePrecision = v;
  550. m_wantPrecision = false;
  551. }
  552. return;
  553. }
  554. // If we get here, we've set both the variable precision and width as
  555. // required and we need to rerun the stream state setup to insert these.
  556. fmtEnd = streamStateFromFormat(m_out, m_extraFlags, m_fmt,
  557. m_variableWidth, m_variablePrecision);
  558. }
  559. // Format the value into the stream.
  560. if(!(m_extraFlags & (Flag_SpacePadPositive | Flag_TruncateToPrecision)))
  561. formatValue(m_out, m_fmt, fmtEnd, value);
  562. else
  563. {
  564. // The following are special cases where there's no direct
  565. // correspondence between stream formatting and the printf() behaviour.
  566. // Instead, we simulate the behaviour crudely by formatting into a
  567. // temporary string stream and munging the resulting string.
  568. std::ostringstream tmpStream;
  569. tmpStream.copyfmt(m_out);
  570. if(m_extraFlags & Flag_SpacePadPositive)
  571. tmpStream.setf(std::ios::showpos);
  572. // formatCStringTruncate is required for truncating conversions like
  573. // "%.4s" where at most 4 characters of the c-string should be read.
  574. // If we didn't include this special case, we might read off the end.
  575. if(!( (m_extraFlags & Flag_TruncateToPrecision) &&
  576. formatCStringTruncate(tmpStream, value, m_out.precision()) ))
  577. {
  578. // Not a truncated c-string; just format normally.
  579. formatValue(tmpStream, m_fmt, fmtEnd, value);
  580. }
  581. std::string result = tmpStream.str(); // allocates... yuck.
  582. if(m_extraFlags & Flag_SpacePadPositive)
  583. {
  584. for(size_t i = 0, iend = result.size(); i < iend; ++i)
  585. if(result[i] == '+')
  586. result[i] = ' ';
  587. }
  588. if((m_extraFlags & Flag_TruncateToPrecision) &&
  589. (int)result.size() > (int)m_out.precision())
  590. m_out.write(result.c_str(), m_out.precision());
  591. else
  592. m_out << result;
  593. }
  594. m_extraFlags = Flag_None;
  595. m_fmt = fmtEnd;
  596. }
  597. // Parse a format string and set the stream state accordingly.
  598. //
  599. // The format mini-language recognized here is meant to be the one from C99,
  600. // with the form "%[flags][width][.precision][length]type".
  601. //
  602. // Formatting options which can't be natively represented using the ostream
  603. // state are returned in the extraFlags parameter which is a bitwise
  604. // combination of values from the ExtraFormatFlags enum.
  605. inline const char* FormatIterator::streamStateFromFormat(std::ostream& out,
  606. unsigned int& extraFlags,
  607. const char* fmtStart,
  608. int variableWidth,
  609. int variablePrecision)
  610. {
  611. if(*fmtStart != '%')
  612. {
  613. TINYFORMAT_ERROR("tinyformat: Not enough conversion specifiers in format string");
  614. return fmtStart;
  615. }
  616. // Reset stream state to defaults.
  617. out.width(0);
  618. out.precision(6);
  619. out.fill(' ');
  620. // Reset most flags; ignore irrelevant unitbuf & skipws.
  621. out.unsetf(std::ios::adjustfield | std::ios::basefield |
  622. std::ios::floatfield | std::ios::showbase | std::ios::boolalpha |
  623. std::ios::showpoint | std::ios::showpos | std::ios::uppercase);
  624. extraFlags = Flag_None;
  625. bool precisionSet = false;
  626. bool widthSet = false;
  627. const char* c = fmtStart + 1;
  628. // 1) Parse flags
  629. for(;; ++c)
  630. {
  631. switch(*c)
  632. {
  633. case '#':
  634. out.setf(std::ios::showpoint | std::ios::showbase);
  635. continue;
  636. case '0':
  637. // overridden by left alignment ('-' flag)
  638. if(!(out.flags() & std::ios::left))
  639. {
  640. // Use internal padding so that numeric values are
  641. // formatted correctly, eg -00010 rather than 000-10
  642. out.fill('0');
  643. out.setf(std::ios::internal, std::ios::adjustfield);
  644. }
  645. continue;
  646. case '-':
  647. out.fill(' ');
  648. out.setf(std::ios::left, std::ios::adjustfield);
  649. continue;
  650. case ' ':
  651. // overridden by show positive sign, '+' flag.
  652. if(!(out.flags() & std::ios::showpos))
  653. extraFlags |= Flag_SpacePadPositive;
  654. continue;
  655. case '+':
  656. out.setf(std::ios::showpos);
  657. extraFlags &= ~Flag_SpacePadPositive;
  658. continue;
  659. }
  660. break;
  661. }
  662. // 2) Parse width
  663. if(*c >= '0' && *c <= '9')
  664. {
  665. widthSet = true;
  666. out.width(parseIntAndAdvance(c));
  667. }
  668. if(*c == '*')
  669. {
  670. widthSet = true;
  671. if(variableWidth < 0)
  672. {
  673. // negative widths correspond to '-' flag set
  674. out.fill(' ');
  675. out.setf(std::ios::left, std::ios::adjustfield);
  676. variableWidth = -variableWidth;
  677. }
  678. out.width(variableWidth);
  679. extraFlags |= Flag_VariableWidth;
  680. ++c;
  681. }
  682. // 3) Parse precision
  683. if(*c == '.')
  684. {
  685. ++c;
  686. int precision = 0;
  687. if(*c == '*')
  688. {
  689. ++c;
  690. extraFlags |= Flag_VariablePrecision;
  691. precision = variablePrecision;
  692. }
  693. else
  694. {
  695. if(*c >= '0' && *c <= '9')
  696. precision = parseIntAndAdvance(c);
  697. else if(*c == '-') // negative precisions ignored, treated as zero.
  698. parseIntAndAdvance(++c);
  699. }
  700. out.precision(precision);
  701. precisionSet = true;
  702. }
  703. // 4) Ignore any C99 length modifier
  704. while(*c == 'l' || *c == 'h' || *c == 'L' ||
  705. *c == 'j' || *c == 'z' || *c == 't')
  706. ++c;
  707. // 5) We're up to the conversion specifier character.
  708. // Set stream flags based on conversion specifier (thanks to the
  709. // boost::format class for forging the way here).
  710. bool intConversion = false;
  711. switch(*c)
  712. {
  713. case 'u': case 'd': case 'i':
  714. out.setf(std::ios::dec, std::ios::basefield);
  715. intConversion = true;
  716. break;
  717. case 'o':
  718. out.setf(std::ios::oct, std::ios::basefield);
  719. intConversion = true;
  720. break;
  721. case 'X':
  722. out.setf(std::ios::uppercase);
  723. case 'x': case 'p':
  724. out.setf(std::ios::hex, std::ios::basefield);
  725. intConversion = true;
  726. break;
  727. case 'E':
  728. out.setf(std::ios::uppercase);
  729. case 'e':
  730. out.setf(std::ios::scientific, std::ios::floatfield);
  731. out.setf(std::ios::dec, std::ios::basefield);
  732. break;
  733. case 'F':
  734. out.setf(std::ios::uppercase);
  735. case 'f':
  736. out.setf(std::ios::fixed, std::ios::floatfield);
  737. break;
  738. case 'G':
  739. out.setf(std::ios::uppercase);
  740. case 'g':
  741. out.setf(std::ios::dec, std::ios::basefield);
  742. // As in boost::format, let stream decide float format.
  743. out.flags(out.flags() & ~std::ios::floatfield);
  744. break;
  745. case 'a': case 'A':
  746. TINYFORMAT_ERROR("tinyformat: the %a and %A conversion specs "
  747. "are not supported");
  748. break;
  749. case 'c':
  750. // Handled as special case inside formatValue()
  751. break;
  752. case 's':
  753. if(precisionSet)
  754. extraFlags |= Flag_TruncateToPrecision;
  755. // Make %s print booleans as "true" and "false"
  756. out.setf(std::ios::boolalpha);
  757. break;
  758. case 'n':
  759. // Not supported - will cause problems!
  760. TINYFORMAT_ERROR("tinyformat: %n conversion spec not supported");
  761. break;
  762. case '\0':
  763. TINYFORMAT_ERROR("tinyformat: Conversion spec incorrectly "
  764. "terminated by end of string");
  765. return c;
  766. }
  767. if(intConversion && precisionSet && !widthSet)
  768. {
  769. // "precision" for integers gives the minimum number of digits (to be
  770. // padded with zeros on the left). This isn't really supported by the
  771. // iostreams, but we can approximately simulate it with the width if
  772. // the width isn't otherwise used.
  773. out.width(out.precision());
  774. out.setf(std::ios::internal, std::ios::adjustfield);
  775. out.fill('0');
  776. }
  777. return c+1;
  778. }
  779. //------------------------------------------------------------------------------
  780. // Private format function on top of which the public interface is implemented.
  781. // We enforce a mimimum of one value to be formatted to prevent bugs looking like
  782. //
  783. // const char* myStr = "100% broken";
  784. // printf(myStr); // Parses % as a format specifier
  785. #ifdef TINYFORMAT_USE_VARIADIC_TEMPLATES
  786. template<typename T1>
  787. void format(FormatIterator& fmtIter, const T1& value1)
  788. {
  789. fmtIter.accept(value1);
  790. fmtIter.finish();
  791. }
  792. // General version for C++11
  793. template<typename T1, typename... Args>
  794. void format(FormatIterator& fmtIter, const T1& value1, const Args&... args)
  795. {
  796. fmtIter.accept(value1);
  797. format(fmtIter, args...);
  798. }
  799. #else
  800. inline void format(FormatIterator& fmtIter)
  801. {
  802. fmtIter.finish();
  803. }
  804. // General version for C++98
  805. #define TINYFORMAT_MAKE_FORMAT_DETAIL(n) \
  806. template<TINYFORMAT_ARGTYPES(n)> \
  807. void format(detail::FormatIterator& fmtIter, TINYFORMAT_VARARGS(n)) \
  808. { \
  809. fmtIter.accept(v1); \
  810. format(fmtIter TINYFORMAT_PASSARGS_TAIL(n)); \
  811. }
  812. TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMAT_DETAIL)
  813. #undef TINYFORMAT_MAKE_FORMAT_DETAIL
  814. #endif // End C++98 variadic template emulation for format()
  815. } // namespace detail
  816. //------------------------------------------------------------------------------
  817. // Implement all the main interface functions here in terms of detail::format()
  818. #ifdef TINYFORMAT_USE_VARIADIC_TEMPLATES
  819. // C++11 - the simple case
  820. template<typename T1, typename... Args>
  821. void format(std::ostream& out, const char* fmt, const T1& v1, const Args&... args)
  822. {
  823. detail::FormatIterator fmtIter(out, fmt);
  824. format(fmtIter, v1, args...);
  825. }
  826. template<typename T1, typename... Args>
  827. std::string format(const char* fmt, const T1& v1, const Args&... args)
  828. {
  829. std::ostringstream oss;
  830. format(oss, fmt, v1, args...);
  831. return oss.str();
  832. }
  833. template<typename T1, typename... Args>
  834. std::string format(const std::string &fmt, const T1& v1, const Args&... args)
  835. {
  836. std::ostringstream oss;
  837. format(oss, fmt.c_str(), v1, args...);
  838. return oss.str();
  839. }
  840. template<typename T1, typename... Args>
  841. void printf(const char* fmt, const T1& v1, const Args&... args)
  842. {
  843. format(std::cout, fmt, v1, args...);
  844. }
  845. #else
  846. // C++98 - define the interface functions using the wrapping macros
  847. #define TINYFORMAT_MAKE_FORMAT_FUNCS(n) \
  848. \
  849. template<TINYFORMAT_ARGTYPES(n)> \
  850. void format(std::ostream& out, const char* fmt, TINYFORMAT_VARARGS(n)) \
  851. { \
  852. tinyformat::detail::FormatIterator fmtIter(out, fmt); \
  853. tinyformat::detail::format(fmtIter, TINYFORMAT_PASSARGS(n)); \
  854. } \
  855. \
  856. template<TINYFORMAT_ARGTYPES(n)> \
  857. std::string format(const char* fmt, TINYFORMAT_VARARGS(n)) \
  858. { \
  859. std::ostringstream oss; \
  860. tinyformat::format(oss, fmt, TINYFORMAT_PASSARGS(n)); \
  861. return oss.str(); \
  862. } \
  863. \
  864. template<TINYFORMAT_ARGTYPES(n)> \
  865. std::string format(const std::string &fmt, TINYFORMAT_VARARGS(n)) \
  866. { \
  867. std::ostringstream oss; \
  868. tinyformat::format(oss, fmt.c_str(), TINYFORMAT_PASSARGS(n)); \
  869. return oss.str(); \
  870. } \
  871. \
  872. template<TINYFORMAT_ARGTYPES(n)> \
  873. void printf(const char* fmt, TINYFORMAT_VARARGS(n)) \
  874. { \
  875. tinyformat::format(std::cout, fmt, TINYFORMAT_PASSARGS(n)); \
  876. }
  877. TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMAT_FUNCS)
  878. #undef TINYFORMAT_MAKE_FORMAT_FUNCS
  879. #endif
  880. //------------------------------------------------------------------------------
  881. // Define deprecated wrapping macro for backward compatibility in tinyformat
  882. // 1.x. Will be removed in version 2!
  883. #define TINYFORMAT_WRAP_FORMAT_EXTRA_ARGS
  884. #define TINYFORMAT_WRAP_FORMAT_N(n, returnType, funcName, funcDeclSuffix, \
  885. bodyPrefix, streamName, bodySuffix) \
  886. template<TINYFORMAT_ARGTYPES(n)> \
  887. returnType funcName(TINYFORMAT_WRAP_FORMAT_EXTRA_ARGS const char* fmt, \
  888. TINYFORMAT_VARARGS(n)) funcDeclSuffix \
  889. { \
  890. bodyPrefix \
  891. tinyformat::format(streamName, fmt, TINYFORMAT_PASSARGS(n)); \
  892. bodySuffix \
  893. } \
  894. #define TINYFORMAT_WRAP_FORMAT(returnType, funcName, funcDeclSuffix, \
  895. bodyPrefix, streamName, bodySuffix) \
  896. inline \
  897. returnType funcName(TINYFORMAT_WRAP_FORMAT_EXTRA_ARGS const char* fmt \
  898. ) funcDeclSuffix \
  899. { \
  900. bodyPrefix \
  901. tinyformat::detail::FormatIterator(streamName, fmt).finish(); \
  902. bodySuffix \
  903. } \
  904. TINYFORMAT_WRAP_FORMAT_N(1 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  905. TINYFORMAT_WRAP_FORMAT_N(2 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  906. TINYFORMAT_WRAP_FORMAT_N(3 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  907. TINYFORMAT_WRAP_FORMAT_N(4 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  908. TINYFORMAT_WRAP_FORMAT_N(5 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  909. TINYFORMAT_WRAP_FORMAT_N(6 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  910. TINYFORMAT_WRAP_FORMAT_N(7 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  911. TINYFORMAT_WRAP_FORMAT_N(8 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  912. TINYFORMAT_WRAP_FORMAT_N(9 , returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  913. TINYFORMAT_WRAP_FORMAT_N(10, returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  914. TINYFORMAT_WRAP_FORMAT_N(11, returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  915. TINYFORMAT_WRAP_FORMAT_N(12, returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  916. TINYFORMAT_WRAP_FORMAT_N(13, returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  917. TINYFORMAT_WRAP_FORMAT_N(14, returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  918. TINYFORMAT_WRAP_FORMAT_N(15, returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  919. TINYFORMAT_WRAP_FORMAT_N(16, returnType, funcName, funcDeclSuffix, bodyPrefix, streamName, bodySuffix) \
  920. } // namespace tinyformat
  921. #define strprintf tfm::format
  922. #endif // TINYFORMAT_H_INCLUDED