numeric_utils.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_SPIRIT_KARMA_NUMERIC_UTILS_FEB_23_2007_0841PM)
  6. #define BOOST_SPIRIT_KARMA_NUMERIC_UTILS_FEB_23_2007_0841PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/config.hpp>
  11. #include <boost/config/no_tr1/cmath.hpp>
  12. #include <boost/limits.hpp>
  13. #include <boost/type_traits/is_integral.hpp>
  14. #include <boost/spirit/home/support/char_class.hpp>
  15. #include <boost/spirit/home/support/unused.hpp>
  16. #include <boost/spirit/home/support/numeric_traits.hpp>
  17. #include <boost/spirit/home/support/detail/pow10.hpp>
  18. #include <boost/spirit/home/karma/detail/generate_to.hpp>
  19. #include <boost/spirit/home/karma/detail/string_generate.hpp>
  20. #include <boost/core/cmath.hpp>
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. // The value BOOST_KARMA_NUMERICS_LOOP_UNROLL specifies, how to unroll the
  24. // integer string generation loop (see below).
  25. //
  26. // Set the value to some integer in between 0 (no unrolling) and the
  27. // largest expected generated integer string length (complete unrolling).
  28. // If not specified, this value defaults to 6.
  29. //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. #if !defined(BOOST_KARMA_NUMERICS_LOOP_UNROLL)
  32. #define BOOST_KARMA_NUMERICS_LOOP_UNROLL 6
  33. #endif
  34. #if BOOST_KARMA_NUMERICS_LOOP_UNROLL < 0
  35. #error "Please set the BOOST_KARMA_NUMERICS_LOOP_UNROLL to a non-negative value!"
  36. #endif
  37. namespace boost { namespace spirit { namespace traits
  38. {
  39. ///////////////////////////////////////////////////////////////////////
  40. //
  41. // return the absolute value from a given number, avoiding over- and
  42. // underflow
  43. //
  44. ///////////////////////////////////////////////////////////////////////
  45. template <typename T, typename Enable/* = void*/>
  46. struct absolute_value
  47. {
  48. typedef T type;
  49. static T call (T n)
  50. {
  51. // allow for ADL to find the correct overloads for fabs
  52. using namespace std;
  53. return fabs(n);
  54. }
  55. };
  56. #define BOOST_SPIRIT_ABSOLUTE_VALUE(signedtype, unsignedtype) \
  57. template <> \
  58. struct absolute_value<signedtype> \
  59. { \
  60. typedef unsignedtype type; \
  61. static type call(signedtype n) \
  62. { \
  63. /* implementation is well-defined for one's complement, */ \
  64. /* two's complement, and signed magnitude architectures */ \
  65. /* by the C++ Standard. [conv.integral] [expr.unary.op] */ \
  66. return (n >= 0) ? static_cast<type>(n) \
  67. : -static_cast<type>(n); \
  68. } \
  69. } \
  70. /**/
  71. #define BOOST_SPIRIT_ABSOLUTE_VALUE_UNSIGNED(unsignedtype) \
  72. template <> \
  73. struct absolute_value<unsignedtype> \
  74. { \
  75. typedef unsignedtype type; \
  76. static type call(unsignedtype n) \
  77. { \
  78. return n; \
  79. } \
  80. } \
  81. /**/
  82. #if defined(BOOST_MSVC)
  83. # pragma warning(push)
  84. // unary minus operator applied to unsigned type, result still unsigned
  85. # pragma warning(disable: 4146)
  86. #endif
  87. BOOST_SPIRIT_ABSOLUTE_VALUE(signed char, unsigned char);
  88. BOOST_SPIRIT_ABSOLUTE_VALUE(char, unsigned char);
  89. BOOST_SPIRIT_ABSOLUTE_VALUE(short, unsigned short);
  90. BOOST_SPIRIT_ABSOLUTE_VALUE(int, unsigned int);
  91. BOOST_SPIRIT_ABSOLUTE_VALUE(long, unsigned long);
  92. BOOST_SPIRIT_ABSOLUTE_VALUE_UNSIGNED(unsigned char);
  93. BOOST_SPIRIT_ABSOLUTE_VALUE_UNSIGNED(unsigned short);
  94. BOOST_SPIRIT_ABSOLUTE_VALUE_UNSIGNED(unsigned int);
  95. BOOST_SPIRIT_ABSOLUTE_VALUE_UNSIGNED(unsigned long);
  96. #ifdef BOOST_HAS_LONG_LONG
  97. BOOST_SPIRIT_ABSOLUTE_VALUE(boost::long_long_type, boost::ulong_long_type);
  98. BOOST_SPIRIT_ABSOLUTE_VALUE_UNSIGNED(boost::ulong_long_type);
  99. #endif
  100. #if defined(BOOST_MSVC)
  101. # pragma warning(pop)
  102. #endif
  103. #undef BOOST_SPIRIT_ABSOLUTE_VALUE
  104. #undef BOOST_SPIRIT_ABSOLUTE_VALUE_UNSIGNED
  105. template <>
  106. struct absolute_value<float>
  107. {
  108. typedef float type;
  109. static type call(float n)
  110. {
  111. return (std::fabs)(n);
  112. }
  113. };
  114. template <>
  115. struct absolute_value<double>
  116. {
  117. typedef double type;
  118. static type call(double n)
  119. {
  120. return (std::fabs)(n);
  121. }
  122. };
  123. template <>
  124. struct absolute_value<long double>
  125. {
  126. typedef long double type;
  127. static type call(long double n)
  128. {
  129. return (std::fabs)(n);
  130. }
  131. };
  132. // specialization for pointers
  133. template <typename T>
  134. struct absolute_value<T*>
  135. {
  136. typedef std::size_t type;
  137. static type call (T* p)
  138. {
  139. return std::size_t(p);
  140. }
  141. };
  142. template <typename T>
  143. inline typename absolute_value<T>::type
  144. get_absolute_value(T n)
  145. {
  146. return absolute_value<T>::call(n);
  147. }
  148. ///////////////////////////////////////////////////////////////////////
  149. template <typename T, typename Enable/* = void*/>
  150. struct is_negative
  151. {
  152. static bool call(T n)
  153. {
  154. return (n < 0) ? true : false;
  155. }
  156. };
  157. template <>
  158. struct is_negative<float>
  159. {
  160. static bool call(float n)
  161. {
  162. return (core::signbit)(n) ? true : false;
  163. }
  164. };
  165. template <>
  166. struct is_negative<double>
  167. {
  168. static bool call(double n)
  169. {
  170. return (core::signbit)(n) ? true : false;
  171. }
  172. };
  173. template <>
  174. struct is_negative<long double>
  175. {
  176. static bool call(long double n)
  177. {
  178. return (core::signbit)(n) ? true : false;
  179. }
  180. };
  181. template <typename T>
  182. inline bool test_negative(T n)
  183. {
  184. return is_negative<T>::call(n);
  185. }
  186. ///////////////////////////////////////////////////////////////////////
  187. template <typename T, typename Enable/* = void*/>
  188. struct is_zero
  189. {
  190. static bool call(T n)
  191. {
  192. return (n == 0) ? true : false;
  193. }
  194. };
  195. template <>
  196. struct is_zero<float>
  197. {
  198. static bool call(float n)
  199. {
  200. return (core::fpclassify)(n) == core::fp_zero;
  201. }
  202. };
  203. template <>
  204. struct is_zero<double>
  205. {
  206. static bool call(double n)
  207. {
  208. return (core::fpclassify)(n) == core::fp_zero;
  209. }
  210. };
  211. template <>
  212. struct is_zero<long double>
  213. {
  214. static bool call(long double n)
  215. {
  216. return (core::fpclassify)(n) == core::fp_zero;
  217. }
  218. };
  219. template <typename T>
  220. inline bool test_zero(T n)
  221. {
  222. return is_zero<T>::call(n);
  223. }
  224. ///////////////////////////////////////////////////////////////////////
  225. template <typename T, typename Enable/* = void*/>
  226. struct is_nan
  227. {
  228. static bool call(T n)
  229. {
  230. // NaN numbers are not equal to anything
  231. return (n != n) ? true : false;
  232. }
  233. };
  234. template <>
  235. struct is_nan<float>
  236. {
  237. static bool call(float n)
  238. {
  239. return (core::fpclassify)(n) == core::fp_nan;
  240. }
  241. };
  242. template <>
  243. struct is_nan<double>
  244. {
  245. static bool call(double n)
  246. {
  247. return (core::fpclassify)(n) == core::fp_nan;
  248. }
  249. };
  250. template <>
  251. struct is_nan<long double>
  252. {
  253. static bool call(long double n)
  254. {
  255. return (core::fpclassify)(n) == core::fp_nan;
  256. }
  257. };
  258. template <typename T>
  259. inline bool test_nan(T n)
  260. {
  261. return is_nan<T>::call(n);
  262. }
  263. ///////////////////////////////////////////////////////////////////////
  264. template <typename T, typename Enable/* = void*/>
  265. struct is_infinite
  266. {
  267. static bool call(T n)
  268. {
  269. return std::numeric_limits<T>::has_infinity
  270. && n == std::numeric_limits<T>::infinity();
  271. }
  272. };
  273. template <>
  274. struct is_infinite<float>
  275. {
  276. static bool call(float n)
  277. {
  278. return (core::fpclassify)(n) == core::fp_infinite;
  279. }
  280. };
  281. template <>
  282. struct is_infinite<double>
  283. {
  284. static bool call(double n)
  285. {
  286. return (core::fpclassify)(n) == core::fp_infinite;
  287. }
  288. };
  289. template <>
  290. struct is_infinite<long double>
  291. {
  292. static bool call(long double n)
  293. {
  294. return (core::fpclassify)(n) == core::fp_infinite;
  295. }
  296. };
  297. template <typename T>
  298. inline bool test_infinite(T n)
  299. {
  300. return is_infinite<T>::call(n);
  301. }
  302. ///////////////////////////////////////////////////////////////////////
  303. struct cast_to_long
  304. {
  305. static long call(float n, mpl::false_)
  306. {
  307. return static_cast<long>(std::floor(n));
  308. }
  309. static long call(double n, mpl::false_)
  310. {
  311. return static_cast<long>(std::floor(n));
  312. }
  313. static long call(long double n, mpl::false_)
  314. {
  315. return static_cast<long>(std::floor(n));
  316. }
  317. template <typename T>
  318. static long call(T n, mpl::false_)
  319. {
  320. // allow for ADL to find the correct overload for floor and
  321. // lround
  322. using namespace std;
  323. return lround(floor(n));
  324. }
  325. template <typename T>
  326. static long call(T n, mpl::true_)
  327. {
  328. return static_cast<long>(n);
  329. }
  330. template <typename T>
  331. static long call(T n)
  332. {
  333. return call(n, mpl::bool_<is_integral<T>::value>());
  334. }
  335. };
  336. ///////////////////////////////////////////////////////////////////////
  337. struct truncate_to_long
  338. {
  339. static long call(float n, mpl::false_)
  340. {
  341. return test_negative(n) ? static_cast<long>(std::ceil(n)) :
  342. static_cast<long>(std::floor(n));
  343. }
  344. static long call(double n, mpl::false_)
  345. {
  346. return test_negative(n) ? static_cast<long>(std::ceil(n)) :
  347. static_cast<long>(std::floor(n));
  348. }
  349. static long call(long double n, mpl::false_)
  350. {
  351. return test_negative(n) ? static_cast<long>(std::ceil(n)) :
  352. static_cast<long>(std::floor(n));
  353. }
  354. template <typename T>
  355. static long call(T n, mpl::false_)
  356. {
  357. // allow for ADL to find the correct overloads for ltrunc
  358. using namespace std;
  359. return ltrunc(n);
  360. }
  361. template <typename T>
  362. static long call(T n, mpl::true_)
  363. {
  364. return static_cast<long>(n);
  365. }
  366. template <typename T>
  367. static long call(T n)
  368. {
  369. return call(n, mpl::bool_<is_integral<T>::value>());
  370. }
  371. };
  372. ///////////////////////////////////////////////////////////////////////
  373. //
  374. // Traits class for radix specific number conversion
  375. //
  376. // Convert a digit from binary representation to character
  377. // representation:
  378. //
  379. // static int call(unsigned n);
  380. //
  381. ///////////////////////////////////////////////////////////////////////
  382. namespace detail
  383. {
  384. template <typename CharEncoding, typename Tag, bool radix_less_than_10>
  385. struct convert_digit
  386. {
  387. static int call(unsigned n)
  388. {
  389. if (n <= 9)
  390. return n + '0';
  391. using spirit::char_class::convert;
  392. return convert<CharEncoding>::to(Tag(), n - 10 + 'a');
  393. }
  394. };
  395. template <>
  396. struct convert_digit<unused_type, unused_type, false>
  397. {
  398. static int call(unsigned n)
  399. {
  400. if (n <= 9)
  401. return n + '0';
  402. return n - 10 + 'a';
  403. }
  404. };
  405. template <typename CharEncoding, typename Tag>
  406. struct convert_digit<CharEncoding, Tag, true>
  407. {
  408. static int call(unsigned n)
  409. {
  410. return n + '0';
  411. }
  412. };
  413. }
  414. template <unsigned Radix, typename CharEncoding, typename Tag>
  415. struct convert_digit
  416. : detail::convert_digit<CharEncoding, Tag, (Radix <= 10) ? true : false>
  417. {};
  418. ///////////////////////////////////////////////////////////////////////
  419. template <unsigned Radix>
  420. struct divide
  421. {
  422. template <typename T>
  423. static T call(T& n, mpl::true_)
  424. {
  425. return n / Radix;
  426. }
  427. template <typename T>
  428. static T call(T& n, mpl::false_)
  429. {
  430. // Allow ADL to find the correct overload for floor
  431. using namespace std;
  432. return floor(n / Radix);
  433. }
  434. template <typename T>
  435. static T call(T& n, T const&, int)
  436. {
  437. return call(n, mpl::bool_<is_integral<T>::value>());
  438. }
  439. template <typename T>
  440. static T call(T& n)
  441. {
  442. return call(n, mpl::bool_<is_integral<T>::value>());
  443. }
  444. };
  445. // specialization for division by 10
  446. template <>
  447. struct divide<10>
  448. {
  449. template <typename T>
  450. static T call(T& n, T, int, mpl::true_)
  451. {
  452. return n / 10;
  453. }
  454. template <typename T>
  455. static T call(T, T& num, int exp, mpl::false_)
  456. {
  457. // Allow ADL to find the correct overload for floor
  458. using namespace std;
  459. return floor(num / spirit::traits::pow10<T>(exp));
  460. }
  461. template <typename T>
  462. static T call(T& n, T& num, int exp)
  463. {
  464. return call(n, num, exp, mpl::bool_<is_integral<T>::value>());
  465. }
  466. template <typename T>
  467. static T call(T& n)
  468. {
  469. return call(n, n, 1, mpl::bool_<is_integral<T>::value>());
  470. }
  471. };
  472. ///////////////////////////////////////////////////////////////////////
  473. template <unsigned Radix>
  474. struct remainder
  475. {
  476. template <typename T>
  477. static long call(T n, mpl::true_)
  478. {
  479. // this cast is safe since we know the result is not larger
  480. // than Radix
  481. return static_cast<long>(n % Radix);
  482. }
  483. template <typename T>
  484. static long call(T n, mpl::false_)
  485. {
  486. // Allow ADL to find the correct overload for fmod
  487. using namespace std;
  488. return cast_to_long::call(fmod(n, T(Radix)));
  489. }
  490. template <typename T>
  491. static long call(T n)
  492. {
  493. return call(n, mpl::bool_<is_integral<T>::value>());
  494. }
  495. };
  496. }}}
  497. namespace boost { namespace spirit { namespace karma
  498. {
  499. ///////////////////////////////////////////////////////////////////////////
  500. //
  501. // The int_inserter template takes care of the integer to string
  502. // conversion. If specified, the loop is unrolled for better performance.
  503. //
  504. // Set the value BOOST_KARMA_NUMERICS_LOOP_UNROLL to some integer in
  505. // between 0 (no unrolling) and the largest expected generated integer
  506. // string length (complete unrolling).
  507. // If not specified, this value defaults to 6.
  508. //
  509. ///////////////////////////////////////////////////////////////////////////
  510. #define BOOST_KARMA_NUMERICS_INNER_LOOP_PREFIX(z, x, data) \
  511. if (!traits::test_zero(n)) { \
  512. int ch_##x = radix_type::call(remainder_type::call(n)); \
  513. n = divide_type::call(n, num, ++exp); \
  514. /**/
  515. #define BOOST_KARMA_NUMERICS_INNER_LOOP_SUFFIX(z, x, n_rolls_sub1) \
  516. *sink = char(BOOST_PP_CAT(ch_, BOOST_PP_SUB(n_rolls_sub1, x))); \
  517. ++sink; \
  518. } \
  519. /**/
  520. template <
  521. unsigned Radix, typename CharEncoding = unused_type
  522. , typename Tag = unused_type>
  523. struct int_inserter
  524. {
  525. typedef traits::convert_digit<Radix, CharEncoding, Tag> radix_type;
  526. typedef traits::divide<Radix> divide_type;
  527. typedef traits::remainder<Radix> remainder_type;
  528. template <typename OutputIterator, typename T>
  529. static bool
  530. call(OutputIterator& sink, T n, T& num, int exp)
  531. {
  532. // remainder_type::call returns n % Radix
  533. int ch = radix_type::call(remainder_type::call(n));
  534. n = divide_type::call(n, num, ++exp);
  535. BOOST_PP_REPEAT(
  536. BOOST_KARMA_NUMERICS_LOOP_UNROLL,
  537. BOOST_KARMA_NUMERICS_INNER_LOOP_PREFIX, _);
  538. if (!traits::test_zero(n))
  539. call(sink, n, num, exp);
  540. BOOST_PP_REPEAT(
  541. BOOST_KARMA_NUMERICS_LOOP_UNROLL,
  542. BOOST_KARMA_NUMERICS_INNER_LOOP_SUFFIX,
  543. BOOST_PP_DEC(BOOST_KARMA_NUMERICS_LOOP_UNROLL));
  544. *sink = char(ch);
  545. ++sink;
  546. return true;
  547. }
  548. // Common code for integer string representations
  549. template <typename OutputIterator, typename T>
  550. static bool
  551. call(OutputIterator& sink, T n)
  552. {
  553. return call(sink, n, n, 0);
  554. }
  555. private:
  556. // helper function returning the biggest number representable either in
  557. // a boost::long_long_type (if this does exist) or in a plain long
  558. // otherwise
  559. #if defined(BOOST_HAS_LONG_LONG)
  560. typedef boost::long_long_type biggest_long_type;
  561. #else
  562. typedef long biggest_long_type;
  563. #endif
  564. static biggest_long_type max_long()
  565. {
  566. return (std::numeric_limits<biggest_long_type>::max)();
  567. }
  568. public:
  569. // Specialization for doubles and floats, falling back to long integers
  570. // for representable values. These specializations speed up formatting
  571. // of floating point numbers considerably as all the required
  572. // arithmetics will be executed using integral data types.
  573. template <typename OutputIterator>
  574. static bool
  575. call(OutputIterator& sink, long double n)
  576. {
  577. if (std::fabs(n) < max_long())
  578. {
  579. biggest_long_type l((biggest_long_type)n);
  580. return call(sink, l, l, 0);
  581. }
  582. return call(sink, n, n, 0);
  583. }
  584. template <typename OutputIterator>
  585. static bool
  586. call(OutputIterator& sink, double n)
  587. {
  588. if (std::fabs(n) < max_long())
  589. {
  590. biggest_long_type l((biggest_long_type)n);
  591. return call(sink, l, l, 0);
  592. }
  593. return call(sink, n, n, 0);
  594. }
  595. template <typename OutputIterator>
  596. static bool
  597. call(OutputIterator& sink, float n)
  598. {
  599. if (std::fabs(n) < max_long())
  600. {
  601. biggest_long_type l((biggest_long_type)n);
  602. return call(sink, l, l, 0);
  603. }
  604. return call(sink, n, n, 0);
  605. }
  606. };
  607. #undef BOOST_KARMA_NUMERICS_INNER_LOOP_PREFIX
  608. #undef BOOST_KARMA_NUMERICS_INNER_LOOP_SUFFIX
  609. ///////////////////////////////////////////////////////////////////////////
  610. //
  611. // The uint_inserter template takes care of the conversion of any integer
  612. // to a string, while interpreting the number as an unsigned type.
  613. //
  614. ///////////////////////////////////////////////////////////////////////////
  615. template <
  616. unsigned Radix, typename CharEncoding = unused_type
  617. , typename Tag = unused_type>
  618. struct uint_inserter : int_inserter<Radix, CharEncoding, Tag>
  619. {
  620. typedef int_inserter<Radix, CharEncoding, Tag> base_type;
  621. // Common code for integer string representations
  622. template <typename OutputIterator, typename T>
  623. static bool
  624. call(OutputIterator& sink, T const& n)
  625. {
  626. typedef typename traits::absolute_value<T>::type type;
  627. type un = type(n);
  628. return base_type::call(sink, un, un, 0);
  629. }
  630. };
  631. ///////////////////////////////////////////////////////////////////////////
  632. //
  633. // The sign_inserter template generates a sign for a given numeric value.
  634. //
  635. // The parameter forcesign allows to generate a sign even for positive
  636. // numbers.
  637. //
  638. ///////////////////////////////////////////////////////////////////////////
  639. struct sign_inserter
  640. {
  641. template <typename OutputIterator>
  642. static bool
  643. call_noforce(OutputIterator& sink, bool is_zero, bool is_negative,
  644. bool sign_if_zero)
  645. {
  646. // generate a sign for negative numbers only
  647. if (is_negative || (is_zero && sign_if_zero)) {
  648. *sink = '-';
  649. ++sink;
  650. }
  651. return true;
  652. }
  653. template <typename OutputIterator>
  654. static bool
  655. call_force(OutputIterator& sink, bool is_zero, bool is_negative,
  656. bool sign_if_zero)
  657. {
  658. // generate a sign for all numbers except zero
  659. if (!is_zero || sign_if_zero)
  660. *sink = is_negative ? '-' : '+';
  661. else
  662. *sink = ' ';
  663. ++sink;
  664. return true;
  665. }
  666. template <typename OutputIterator>
  667. static bool
  668. call(OutputIterator& sink, bool is_zero, bool is_negative
  669. , bool forcesign, bool sign_if_zero = false)
  670. {
  671. return forcesign ?
  672. call_force(sink, is_zero, is_negative, sign_if_zero) :
  673. call_noforce(sink, is_zero, is_negative, sign_if_zero);
  674. }
  675. };
  676. ///////////////////////////////////////////////////////////////////////////
  677. // These are helper functions for the real policies allowing to generate
  678. // a single character and a string
  679. ///////////////////////////////////////////////////////////////////////////
  680. template <typename CharEncoding = unused_type, typename Tag = unused_type>
  681. struct char_inserter
  682. {
  683. template <typename OutputIterator, typename Char>
  684. static bool call(OutputIterator& sink, Char c)
  685. {
  686. return detail::generate_to(sink, c, CharEncoding(), Tag());
  687. }
  688. };
  689. template <typename CharEncoding = unused_type, typename Tag = unused_type>
  690. struct string_inserter
  691. {
  692. template <typename OutputIterator, typename String>
  693. static bool call(OutputIterator& sink, String str)
  694. {
  695. return detail::string_generate(sink, str, CharEncoding(), Tag());
  696. }
  697. };
  698. }}}
  699. #endif