]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (c) 2010 Lars Kielhorn |
2 | // Copyright (c) 2001-2010 Hartmut Kaiser | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #include <boost/config/warning_disable.hpp> | |
8 | #include <boost/detail/lightweight_test.hpp> | |
9 | #include <boost/spirit/include/karma.hpp> | |
10 | ||
11 | #include <iostream> | |
12 | #include <string> | |
13 | #include <iterator> | |
14 | ||
15 | namespace karma = boost::spirit::karma; | |
16 | ||
17 | // define a new real number formatting policy | |
18 | template <typename Num> | |
19 | struct scientific_policy : karma::real_policies<Num> | |
20 | { | |
21 | // we want the numbers always to be in scientific format | |
22 | static int floatfield(Num) { return std::ios_base::scientific; } | |
23 | }; | |
24 | ||
25 | int main() | |
26 | { | |
27 | // define a new generator type based on the new policy | |
28 | typedef karma::real_generator<double, scientific_policy<double> > | |
29 | science_type; | |
30 | science_type const scientific = science_type(); | |
31 | ||
32 | std::string output; | |
33 | typedef std::back_insert_iterator<std::string> output_iterator; | |
34 | output_iterator sink(output); | |
35 | ||
36 | // should output: 1.0e-01, but will output: 10.0e-02 | |
37 | BOOST_TEST(karma::generate(sink, scientific, 0.1) && output == "1.0e-01"); | |
38 | ||
39 | return boost::report_errors(); | |
11fdf7f2 | 40 | } |