Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / iterator / test / is_readable_iterator.cpp
1 // Copyright David Abrahams 2003. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
5 #include <deque>
6 #include <iterator>
7 #include <iostream>
8 #include <boost/static_assert.hpp>
9 #include <boost/noncopyable.hpp>
10 #include <boost/iterator/is_readable_iterator.hpp>
11 #include <boost/iterator.hpp>
12
13 // Last, for BOOST_NO_LVALUE_RETURN_DETECTION
14 #include <boost/iterator/detail/config_def.hpp>
15
16 struct v
17 {
18     v();
19     ~v();
20 };
21
22
23 struct value_iterator : boost::iterator<std::input_iterator_tag,v>
24 {
25     v operator*() const;
26 };
27
28 struct noncopyable_iterator : boost::iterator<std::forward_iterator_tag,boost::noncopyable>
29 {
30     boost::noncopyable const& operator*() const;
31 };
32
33 struct proxy_iterator : boost::iterator<std::output_iterator_tag,v>
34 {
35 #if BOOST_WORKAROUND(__GNUC__, == 2)
36     typedef boost::iterator<std::input_iterator_tag,v> base;
37     typedef base::iterator_category iterator_category;
38     typedef base::value_type value_type;
39     typedef base::difference_type difference_type;
40     typedef base::pointer pointer;
41     typedef base::reference reference;
42 #endif 
43     
44     struct proxy
45     {
46         operator v&();
47         proxy& operator=(v) const;
48     };
49         
50     proxy operator*() const;
51 };
52
53 struct proxy_iterator2 : boost::iterator<std::output_iterator_tag,v>
54 {
55 #if BOOST_WORKAROUND(__GNUC__, == 2)
56     typedef boost::iterator<std::input_iterator_tag,v> base;
57     typedef base::iterator_category iterator_category;
58     typedef base::value_type value_type;
59     typedef base::difference_type difference_type;
60     typedef base::pointer pointer;
61     typedef base::reference reference;
62 #endif 
63     
64     struct proxy
65     {
66         proxy& operator=(v) const;
67     };
68         
69     proxy operator*() const;
70 };
71
72
73 int main()
74 {
75     BOOST_STATIC_ASSERT(boost::is_readable_iterator<v*>::value);
76     BOOST_STATIC_ASSERT(boost::is_readable_iterator<v const*>::value);
77     BOOST_STATIC_ASSERT(boost::is_readable_iterator<std::deque<v>::iterator>::value);
78     BOOST_STATIC_ASSERT(boost::is_readable_iterator<std::deque<v>::const_iterator>::value);
79     BOOST_STATIC_ASSERT(!boost::is_readable_iterator<std::back_insert_iterator<std::deque<v> > >::value);
80     BOOST_STATIC_ASSERT(!boost::is_readable_iterator<std::ostream_iterator<v> >::value);
81     BOOST_STATIC_ASSERT(boost::is_readable_iterator<proxy_iterator>::value);
82     BOOST_STATIC_ASSERT(!boost::is_readable_iterator<proxy_iterator2>::value);
83     BOOST_STATIC_ASSERT(boost::is_readable_iterator<value_iterator>::value);
84     
85     // Make sure inaccessible copy constructor doesn't prevent
86     // readability
87     BOOST_STATIC_ASSERT(boost::is_readable_iterator<noncopyable_iterator>::value);
88     
89     return 0;
90 }