| 1 | #include <iostream>
|
|---|
| 2 |
|
|---|
| 3 | #include <boost/spirit/include/karma.hpp>
|
|---|
| 4 | #include <boost/spirit/include/karma_format.hpp>
|
|---|
| 5 | #include <boost/spirit/include/karma_real.hpp>
|
|---|
| 6 |
|
|---|
| 7 | namespace karma = boost::spirit::karma;
|
|---|
| 8 |
|
|---|
| 9 | template <typename T>
|
|---|
| 10 | struct my_policy : karma::real_policies<T>
|
|---|
| 11 | {
|
|---|
| 12 | static unsigned int precision(T){return 3;}
|
|---|
| 13 | static int floatfield(T){return std::ios_base::scientific;}
|
|---|
| 14 | };
|
|---|
| 15 |
|
|---|
| 16 | int main()
|
|---|
| 17 | {
|
|---|
| 18 | karma::real_generator<float, my_policy<float> > my_real;
|
|---|
| 19 |
|
|---|
| 20 | // Expected output is "1.0e01 1.0e-02 1.0e04" or "1.0e+01 1.0e-02 1.0e+04",
|
|---|
| 21 | // but result is "10.0e00 10.0e-03 10.0e03"
|
|---|
| 22 | std::cout << karma::format(my_real << " " << my_real << " " << my_real, 9.9999, 9.9996e-3, 9.99951e+3) << std::endl;
|
|---|
| 23 | }
|
|---|