1 | // $Id: weighted_iterator_archetype.cc 3376 2015-02-11 10:28:17Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2014, 2015 Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 3 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | // Test that class test::weighted_iterator_archetype works as |
---|
23 | // intended. If the class does not work on a system (and this test |
---|
24 | // fails), it probably cause many other failures and it probably a |
---|
25 | // good idea to fix this test first before the other failures (which |
---|
26 | // might be bogus). |
---|
27 | |
---|
28 | |
---|
29 | #include <config.h> |
---|
30 | |
---|
31 | #include "Suite.h" |
---|
32 | #include "weighted_iterator_archetype.h" |
---|
33 | |
---|
34 | #include "yat/utility/concept_check.h" |
---|
35 | #include "yat/utility/iterator_traits.h" |
---|
36 | |
---|
37 | #include <boost/iterator/iterator_archetypes.hpp> |
---|
38 | #include <boost/iterator/iterator_categories.hpp> |
---|
39 | #include <boost/iterator/iterator_concepts.hpp> |
---|
40 | |
---|
41 | using namespace theplu::yat; |
---|
42 | using namespace boost::iterator_archetypes; |
---|
43 | |
---|
44 | template<typename Iterator> |
---|
45 | void test_const_access(Iterator iterator) |
---|
46 | { |
---|
47 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>)); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | template<typename Iterator> |
---|
52 | void test_access(Iterator iterator) |
---|
53 | { |
---|
54 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>)); |
---|
55 | BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<Iterator>)); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | template<typename Iterator> |
---|
60 | void test_traversal(Iterator iterator, boost::incrementable_traversal_tag) |
---|
61 | { |
---|
62 | BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<Iterator>)); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | template<typename Iterator> |
---|
67 | void test_traversal(Iterator iterator, boost::single_pass_traversal_tag) |
---|
68 | { |
---|
69 | BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>)); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | template<typename Iterator> |
---|
74 | void test_traversal(Iterator iterator, boost::forward_traversal_tag) |
---|
75 | { |
---|
76 | BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<Iterator>)); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | template<typename Iterator> |
---|
81 | void test_traversal(Iterator iterator, boost::bidirectional_traversal_tag) |
---|
82 | { |
---|
83 | BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<Iterator>)); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | template<typename Iterator> |
---|
88 | void test_traversal(Iterator iterator, boost::random_access_traversal_tag) |
---|
89 | { |
---|
90 | BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<Iterator>)); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | template<typename Iterator, typename ConstIterator> |
---|
95 | void test_interoperability(Iterator i, ConstIterator ci, |
---|
96 | boost::single_pass_traversal_tag) |
---|
97 | { |
---|
98 | BOOST_CONCEPT_ASSERT((boost_concepts::InteroperableIterator<Iterator, ConstIterator>)); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | template<typename Iterator, typename ConstIterator> |
---|
103 | void test_interoperability(Iterator i, ConstIterator ci, |
---|
104 | boost::incrementable_traversal_tag) |
---|
105 | { |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | template<typename TraversalCategory> |
---|
110 | void test1(void) |
---|
111 | { |
---|
112 | test::ctor_arg arg; |
---|
113 | using boost::iterator_archetypes::readable_iterator_t; |
---|
114 | typedef test::weighted_iterator_archetype<readable_iterator_t, |
---|
115 | TraversalCategory> |
---|
116 | ConstIterator; |
---|
117 | typedef typename utility::weighted_iterator_traits<ConstIterator>::type tag1; |
---|
118 | ConstIterator ci(arg); |
---|
119 | test_const_access(ci); |
---|
120 | TraversalCategory traversal; |
---|
121 | test_traversal(ci, traversal); |
---|
122 | |
---|
123 | using boost::iterator_archetypes::readable_writable_iterator_t; |
---|
124 | typedef test::weighted_iterator_archetype<readable_writable_iterator_t, |
---|
125 | TraversalCategory> Iterator; |
---|
126 | |
---|
127 | typedef typename utility::weighted_iterator_traits<Iterator>::type tag2; |
---|
128 | Iterator i(arg); |
---|
129 | test_access(i); |
---|
130 | test_traversal(i, traversal); |
---|
131 | |
---|
132 | test_interoperability(i, ci, traversal); |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | int main(void) |
---|
137 | { |
---|
138 | // this is a compilation test - do not run |
---|
139 | if (false) { |
---|
140 | test1<boost::incrementable_traversal_tag>(); |
---|
141 | test1<boost::single_pass_traversal_tag>(); |
---|
142 | test1<boost::forward_traversal_tag>(); |
---|
143 | test1<boost::bidirectional_traversal_tag>(); |
---|
144 | test1<boost::random_access_traversal_tag>(); |
---|
145 | } |
---|
146 | |
---|
147 | return 0; |
---|
148 | } |
---|