• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //   Copyright (c) 2009 Matthias Vallentin
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 
6 #include <boost/config/warning_disable.hpp>
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/iterator/indirect_iterator.hpp>
9 #include <boost/make_shared.hpp>
10 #include <boost/noncopyable.hpp>
11 #include <boost/spirit/include/karma.hpp>
12 #include <boost/spirit/include/karma_format.hpp>
13 
14 #include <sstream>
15 #include <string>
16 #include <vector>
17 
18 struct foo : boost::noncopyable
19 {
foofoo20     foo()
21       : str("foo")
22     {
23     }
24 
25     std::string str;
26 };
27 
28 template <typename Stream>
operator <<(Stream & out,const foo & f)29 Stream& operator<<(Stream& out, const foo& f)
30 {
31     out << f.str;
32     return out;
33 }
34 
main()35 int main()
36 {
37     using namespace boost::spirit;
38 
39     typedef boost::shared_ptr<foo> foo_ptr;
40     std::vector<foo_ptr> v;
41 
42     std::size_t i = 10;
43     while (i--)
44         v.push_back(boost::make_shared<foo>());
45 
46     typedef boost::indirect_iterator<std::vector<foo_ptr>::const_iterator>
47         iterator_type;
48 
49     std::stringstream strm;
50     strm
51         << karma::format(stream % ',',
52             boost::iterator_range<iterator_type>(
53                 iterator_type(v.begin()), iterator_type(v.end())
54                 )
55             );
56     BOOST_TEST(strm.str() == "foo,foo,foo,foo,foo,foo,foo,foo,foo,foo");
57 
58     return boost::report_errors();
59 }
60