Last change
on this file since 12 was
12,
checked in by landauf, 17 years ago
|
added boost
|
-
Property svn:executable set to
*
|
File size:
1.4 KB
|
Line | |
---|
1 | // Copyright David Abrahams 2004. 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 <boost/iterator/iterator_adaptor.hpp> |
---|
6 | #include <boost/pending/iterator_tests.hpp> |
---|
7 | #include <cassert> |
---|
8 | |
---|
9 | struct mutable_it : boost::iterator_adaptor<mutable_it,int*> |
---|
10 | { |
---|
11 | typedef boost::iterator_adaptor<mutable_it,int*> super_t; |
---|
12 | |
---|
13 | mutable_it(); |
---|
14 | explicit mutable_it(int* p) : super_t(p) {} |
---|
15 | |
---|
16 | bool equal(mutable_it const& rhs) const |
---|
17 | { |
---|
18 | return this->base() == rhs.base(); |
---|
19 | } |
---|
20 | }; |
---|
21 | |
---|
22 | struct constant_it : boost::iterator_adaptor<constant_it,int const*> |
---|
23 | { |
---|
24 | typedef boost::iterator_adaptor<constant_it,int const*> super_t; |
---|
25 | |
---|
26 | constant_it(); |
---|
27 | explicit constant_it(int* p) : super_t(p) {} |
---|
28 | constant_it(mutable_it const& x) : super_t(x.base()) {} |
---|
29 | |
---|
30 | bool equal(constant_it const& rhs) const |
---|
31 | { |
---|
32 | return this->base() == rhs.base(); |
---|
33 | } |
---|
34 | }; |
---|
35 | |
---|
36 | int main() |
---|
37 | { |
---|
38 | int data[] = { 49, 77 }; |
---|
39 | |
---|
40 | mutable_it i(data); |
---|
41 | constant_it j(data + 1); |
---|
42 | assert(i < j); |
---|
43 | assert(j > i); |
---|
44 | assert(i <= j); |
---|
45 | assert(j >= i); |
---|
46 | assert(j - i == 1); |
---|
47 | assert(i - j == -1); |
---|
48 | |
---|
49 | constant_it k = i; |
---|
50 | |
---|
51 | assert(!(i < k)); |
---|
52 | assert(!(k > i)); |
---|
53 | assert(i <= k); |
---|
54 | assert(k >= i); |
---|
55 | assert(k - i == 0); |
---|
56 | assert(i - k == 0); |
---|
57 | |
---|
58 | return 0; |
---|
59 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.