]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/iterator/test/is_lvalue_iterator.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / iterator / test / is_lvalue_iterator.cpp
CommitLineData
7c673cae
FG
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>
11fdf7f2 8#include <cstddef> // std::ptrdiff_t
7c673cae
FG
9#include <boost/static_assert.hpp>
10#include <boost/noncopyable.hpp>
11#include <boost/iterator/is_lvalue_iterator.hpp>
7c673cae
FG
12
13// Last, for BOOST_NO_LVALUE_RETURN_DETECTION
14#include <boost/iterator/detail/config_def.hpp>
15
16struct v
17{
18 v();
19 ~v();
20};
21
22
11fdf7f2 23struct value_iterator
7c673cae 24{
11fdf7f2
TL
25 typedef std::input_iterator_tag iterator_category;
26 typedef v value_type;
27 typedef std::ptrdiff_t difference_type;
28 typedef v* pointer;
29 typedef v& reference;
30
7c673cae
FG
31 v operator*() const;
32};
33
11fdf7f2 34struct noncopyable_iterator
7c673cae 35{
11fdf7f2
TL
36 typedef std::forward_iterator_tag iterator_category;
37 typedef boost::noncopyable value_type;
38 typedef std::ptrdiff_t difference_type;
39 typedef boost::noncopyable* pointer;
40 typedef boost::noncopyable& reference;
f67539c2 41
7c673cae
FG
42 boost::noncopyable const& operator*() const;
43};
44
45template <class T>
46struct proxy_iterator
7c673cae
FG
47{
48 typedef T value_type;
11fdf7f2
TL
49 typedef std::output_iterator_tag iterator_category;
50 typedef std::ptrdiff_t difference_type;
51 typedef T* pointer;
52 typedef T& reference;
f67539c2 53
7c673cae
FG
54 struct proxy
55 {
56 operator value_type&() const;
57 proxy& operator=(value_type) const;
58 };
f67539c2 59
7c673cae
FG
60 proxy operator*() const;
61};
62
63template <class T>
64struct lvalue_iterator
65{
66 typedef T value_type;
67 typedef T& reference;
68 typedef T difference_type;
69 typedef std::input_iterator_tag iterator_category;
70 typedef T* pointer;
71
72 T& operator*() const;
73 lvalue_iterator& operator++();
74 lvalue_iterator operator++(int);
75};
76
77template <class T>
78struct constant_lvalue_iterator
79{
80 typedef T value_type;
81 typedef T const& reference;
82 typedef T difference_type;
83 typedef std::input_iterator_tag iterator_category;
84 typedef T const* pointer;
85
86 T const& operator*() const;
87 constant_lvalue_iterator& operator++();
88 constant_lvalue_iterator operator++(int);
89};
90
91
92int main()
93{
94 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<v*>::value);
95 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<v const*>::value);
96 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<std::deque<v>::iterator>::value);
97 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<std::deque<v>::const_iterator>::value);
98 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<std::back_insert_iterator<std::deque<v> > >::value);
99 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<std::ostream_iterator<v> >::value);
100 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<proxy_iterator<v> >::value);
101 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<proxy_iterator<int> >::value);
102#ifndef BOOST_NO_LVALUE_RETURN_DETECTION
103 BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<value_iterator>::value);
104#endif
105 // Make sure inaccessible copy constructor doesn't prevent
106 // reference binding
107 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<noncopyable_iterator>::value);
108
109 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<v> >::value);
110 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<int> >::value);
111 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<char*> >::value);
112 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<float> >::value);
113
f67539c2 114
7c673cae
FG
115 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<v> >::value);
116 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<int> >::value);
117 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<char*> >::value);
118 BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<float> >::value);
119
f67539c2
TL
120
121
7c673cae
FG
122 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<v*>::value);
123 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<v const*>::value);
124 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<std::deque<v>::iterator>::value);
125 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::deque<v>::const_iterator>::value);
126 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::back_insert_iterator<std::deque<v> > >::value);
127 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::ostream_iterator<v> >::value);
128 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<proxy_iterator<v> >::value);
129 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<proxy_iterator<int> >::value);
130#ifndef BOOST_NO_LVALUE_RETURN_DETECTION
131 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<value_iterator>::value);
132#endif
133 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<noncopyable_iterator>::value);
f67539c2 134
7c673cae
FG
135 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<v> >::value);
136#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
137 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<int> >::value);
f67539c2 138#endif
7c673cae
FG
139 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<char*> >::value);
140 BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<float> >::value);
f67539c2 141
7c673cae
FG
142 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<v> >::value);
143 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<int> >::value);
144 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<char*> >::value);
145 BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<float> >::value);
f67539c2 146
7c673cae
FG
147 return 0;
148}