]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/regression_iterator.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / regression_iterator.cpp
1 // Copyright (c) 2013 Louis Dionne
2 // Copyright (c) 2001-2013 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
10 #include <boost/range/adaptor/transformed.hpp>
11 #include <boost/spirit/include/karma.hpp>
12
13 #include <iostream>
14
15 // Note how the return is made by value instead of by reference.
16 template <typename T> T identity(T const& t) { return t; }
17
18 template <typename Char, typename Expr, typename CopyExpr, typename CopyAttr
19 , typename Delimiter, typename Attribute>
20 bool test(Char const *expected,
21 boost::spirit::karma::detail::format_manip<
22 Expr, CopyExpr, CopyAttr, Delimiter, Attribute> const& fm)
23 {
24 std::ostringstream ostrm;
25 ostrm << fm;
26 return ostrm.good() && ostrm.str() == expected;
27 }
28
29 int main()
30 {
31 namespace karma = boost::spirit::karma;
32 namespace adaptors = boost::adaptors;
33 int ints[] = {0, 1, 2, 3, 4};
34
35 BOOST_TEST((test("0 1 2 3 4",
36 karma::format(karma::int_ % ' ',
37 ints | adaptors::transformed(&identity<int>)))
38 ));
39
40 return boost::report_errors();
41 }
42