]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iterator/test/is_lvalue_iterator.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / iterator / test / is_lvalue_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_lvalue_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 template <class T>
34 struct proxy_iterator
35 : boost::iterator<std::output_iterator_tag,T>
36 {
37 typedef T value_type;
38
39 #if BOOST_WORKAROUND(__GNUC__, == 2)
40 typedef boost::iterator<std::input_iterator_tag,value_type> base;
41 typedef base::iterator_category iterator_category;
42 typedef base::difference_type difference_type;
43 typedef base::pointer pointer;
44 typedef base::reference reference;
45 #endif
46
47 struct proxy
48 {
49 operator value_type&() const;
50 proxy& operator=(value_type) const;
51 };
52
53 proxy operator*() const;
54 };
55
56 template <class T>
57 struct lvalue_iterator
58 {
59 typedef T value_type;
60 typedef T& reference;
61 typedef T difference_type;
62 typedef std::input_iterator_tag iterator_category;
63 typedef T* pointer;
64
65 T& operator*() const;
66 lvalue_iterator& operator++();
67 lvalue_iterator operator++(int);
68 };
69
70 template <class T>
71 struct constant_lvalue_iterator
72 {
73 typedef T value_type;
74 typedef T const& reference;
75 typedef T difference_type;
76 typedef std::input_iterator_tag iterator_category;
77 typedef T const* pointer;
78
79 T const& operator*() const;
80 constant_lvalue_iterator& operator++();
81 constant_lvalue_iterator operator++(int);
82 };
83
84
85 int main()
86 {
87 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<v*>::value);
88 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<v const*>::value);
89 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<std::deque<v>::iterator>::value);
90 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<std::deque<v>::const_iterator>::value);
91 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<std::back_insert_iterator<std::deque<v> > >::value);
92 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<std::ostream_iterator<v> >::value);
93 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<proxy_iterator<v> >::value);
94 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<proxy_iterator<int> >::value);
95 #ifndef BOOST_NO_LVALUE_RETURN_DETECTION
96 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<value_iterator>::value);
97 #endif
98 // Make sure inaccessible copy constructor doesn't prevent
99 // reference binding
100 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<noncopyable_iterator>::value);
101
102 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<v> >::value);
103 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<int> >::value);
104 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<char*> >::value);
105 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<float> >::value);
106
107
108 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<v> >::value);
109 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<int> >::value);
110 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<char*> >::value);
111 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<float> >::value);
112
113
114
115 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<v*>::value);
116 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<v const*>::value);
117 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<std::deque<v>::iterator>::value);
118 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::deque<v>::const_iterator>::value);
119 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::back_insert_iterator<std::deque<v> > >::value);
120 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::ostream_iterator<v> >::value);
121 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<proxy_iterator<v> >::value);
122 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<proxy_iterator<int> >::value);
123 #ifndef BOOST_NO_LVALUE_RETURN_DETECTION
124 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<value_iterator>::value);
125 #endif
126 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<noncopyable_iterator>::value);
127
128 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<v> >::value);
129 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
130 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<int> >::value);
131 #endif
132 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<char*> >::value);
133 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<float> >::value);
134
135 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<v> >::value);
136 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<int> >::value);
137 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<char*> >::value);
138 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<float> >::value);
139
140 return 0;
141 }