1 | // $Id: weighted_iterator_archetype.cc 3379 2015-02-13 11:22:36Z 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 | #include <boost/static_assert.hpp> |
---|
41 | #include <boost/type_traits.hpp> |
---|
42 | |
---|
43 | using namespace theplu::yat; |
---|
44 | using namespace boost::iterator_archetypes; |
---|
45 | |
---|
46 | template<typename Iterator> |
---|
47 | void test_const_access(Iterator iterator) |
---|
48 | { |
---|
49 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>)); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | template<typename Iterator> |
---|
54 | void test_access(Iterator iterator) |
---|
55 | { |
---|
56 | BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>)); |
---|
57 | BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<Iterator>)); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | template<typename Iterator> |
---|
62 | void test_traversal(Iterator iterator, boost::incrementable_traversal_tag) |
---|
63 | { |
---|
64 | BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<Iterator>)); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | template<typename Iterator> |
---|
69 | void test_traversal(Iterator iterator, boost::single_pass_traversal_tag) |
---|
70 | { |
---|
71 | BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>)); |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | template<typename Iterator> |
---|
76 | void test_traversal(Iterator iterator, boost::forward_traversal_tag) |
---|
77 | { |
---|
78 | BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<Iterator>)); |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | template<typename Iterator> |
---|
83 | void test_traversal(Iterator iterator, boost::bidirectional_traversal_tag) |
---|
84 | { |
---|
85 | BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<Iterator>)); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | template<typename Iterator> |
---|
90 | void test_traversal(Iterator iterator, boost::random_access_traversal_tag) |
---|
91 | { |
---|
92 | BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<Iterator>)); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | template<typename Iterator, typename ConstIterator> |
---|
97 | void test_interoperability(Iterator i, ConstIterator ci, |
---|
98 | boost::single_pass_traversal_tag) |
---|
99 | { |
---|
100 | BOOST_CONCEPT_ASSERT((boost_concepts::InteroperableIterator<Iterator, ConstIterator>)); |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | template<typename Iterator, typename ConstIterator> |
---|
105 | void test_interoperability(Iterator i, ConstIterator ci, |
---|
106 | boost::incrementable_traversal_tag) |
---|
107 | { |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | template<typename TraversalCategory> |
---|
112 | void test1(void) |
---|
113 | { |
---|
114 | test::ctor_arg arg; |
---|
115 | using boost::iterator_archetypes::readable_iterator_t; |
---|
116 | typedef test::weighted_iterator_archetype<readable_iterator_t, |
---|
117 | TraversalCategory> |
---|
118 | ConstIterator; |
---|
119 | typedef typename utility::weighted_iterator_traits<ConstIterator>::type tag1; |
---|
120 | using utility::weighted_iterator_tag; |
---|
121 | using boost::is_same; |
---|
122 | BOOST_STATIC_ASSERT((is_same<tag1, weighted_iterator_tag>::type::value)); |
---|
123 | ConstIterator ci(arg); |
---|
124 | test_const_access(ci); |
---|
125 | TraversalCategory traversal; |
---|
126 | test_traversal(ci, traversal); |
---|
127 | |
---|
128 | using boost::iterator_archetypes::readable_writable_iterator_t; |
---|
129 | typedef test::weighted_iterator_archetype<readable_writable_iterator_t, |
---|
130 | TraversalCategory> Iterator; |
---|
131 | |
---|
132 | typedef typename utility::weighted_iterator_traits<Iterator>::type tag2; |
---|
133 | BOOST_STATIC_ASSERT((is_same<tag2, weighted_iterator_tag>::type::value)); |
---|
134 | Iterator i(arg); |
---|
135 | test_access(i); |
---|
136 | test_traversal(i, traversal); |
---|
137 | |
---|
138 | test_interoperability(i, ci, traversal); |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | int main(void) |
---|
143 | { |
---|
144 | // this is a compilation test - do not run |
---|
145 | if (false) { |
---|
146 | //test1<boost::incrementable_traversal_tag>(); |
---|
147 | test1<boost::single_pass_traversal_tag>(); |
---|
148 | test1<boost::forward_traversal_tag>(); |
---|
149 | test1<boost::bidirectional_traversal_tag>(); |
---|
150 | test1<boost::random_access_traversal_tag>(); |
---|
151 | } |
---|
152 | |
---|
153 | return 0; |
---|
154 | } |
---|