]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/classic/test/sf_bug_720917.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / classic / test / sf_bug_720917.cpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2003 Giovanni Bajo
3 Copyrigh (c) 2003 Martin Wille
4 http://spirit.sourceforge.net/
5
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9=============================================================================*/
10#include <boost/spirit/include/classic_multi_pass.hpp>
11#include <iterator>
12#include "impl/sstream.hpp"
13#include <boost/detail/lightweight_test.hpp>
14
15using namespace std;
16using namespace BOOST_SPIRIT_CLASSIC_NS;
17
18// Test for bug #720917
19// http://sf.net/tracker/index.php?func=detail&aid=720917&group_id=28447&atid=393386
20//
21// Check that it's possible to use multi_pass
22// together with standard library as a normal iterator
23//
24
25// a functor to test out the functor_multi_pass
26class my_functor
27{
28 public:
29 typedef char result_type;
30 my_functor()
31 : c('A')
32 {}
33
34 char operator()()
35 {
36 if (c == 'M')
37 return eof;
38 else
39 return c++;
40 }
41
42 static result_type eof;
43 private:
44 char c;
45};
46
47my_functor::result_type my_functor::eof = '\0';
48
49////////////////////////////////////////////////
50// four types of multi_pass iterators
51typedef multi_pass<
52 my_functor,
53 multi_pass_policies::functor_input,
54 multi_pass_policies::first_owner,
55 multi_pass_policies::no_check,
56 multi_pass_policies::std_deque
57> functor_multi_pass_t;
58
59typedef multi_pass<istream_iterator<char> > default_multi_pass_t;
60typedef look_ahead<istream_iterator<char>, 6> fixed_multi_pass_t;
61
62typedef multi_pass<
63 istream_iterator<char>,
64 multi_pass_policies::input_iterator,
65 multi_pass_policies::first_owner,
66 multi_pass_policies::buf_id_check,
67 multi_pass_policies::std_deque
68> first_owner_multi_pass_t;
69
70
71////////////////////////////////////////////////
72// the test cases
73template <typename IterT>
74void construct_string_from(void)
75{
76 sstream_t ss;
77 ss << "test string";
78
79 IterT mpend;
80 istream_iterator<char> a(ss);
81 IterT mp1(a);
82
83 std::string dummy;
84#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
85 dummy.assign(mp1, mpend);
86#else
87 copy(mp1, mpend, inserter(dummy, dummy.end()));
88#endif
89}
90
91template <>
92void construct_string_from<functor_multi_pass_t>(void)
93{
94 functor_multi_pass_t mpend;
95 functor_multi_pass_t mp1 = functor_multi_pass_t(my_functor());
96
97 std::string dummy;
98#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
99 dummy.assign(mp1, mpend);
100#else
101 copy(mp1, mpend, inserter(dummy, dummy.end()));
102#endif
103}
104
105////////////////////////////////////////////////
106// Definition of the test suite
107int
108main()
109{
110 construct_string_from<default_multi_pass_t>();
111 construct_string_from<fixed_multi_pass_t>();
112 construct_string_from<first_owner_multi_pass_t>();
113 construct_string_from<functor_multi_pass_t>();
114 return boost::report_errors();
115}