source: branches/0.14-stable/test/weighted_iterator_archetype.cc @ 3569

Last change on this file since 3569 was 3569, checked in by Peter, 6 years ago

std::iterator_traits<T>::value_type does not work on OSX when T is an
incrementable iterator (not single pass). As this must work for an
iterator that models concept Data Iterator, add single pass iterator
as an requirement, test for it in the concept check class (plus a few
more fixes) and turn off the test in
'test/weighted_iterator_archetype.cc'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1// $Id: weighted_iterator_archetype.cc 3569 2017-01-09 03:43:08Z peter $
2
3/*
4  Copyright (C) 2014, 2015, 2016 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 utility::WeightedIteratorArchetype 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
33#include "yat/utility/concept_check.h"
34#include "yat/utility/iterator_traits.h"
35#include "yat/utility/WeightedIteratorArchetype.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
43using namespace theplu::yat;
44using namespace boost::iterator_archetypes;
45
46template<typename Iterator>
47void test_const_access(Iterator iterator)
48{
49  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>));
50}
51
52
53template<typename Iterator>
54void test_access(Iterator iterator)
55{
56  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>));
57  BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<Iterator>));
58}
59
60
61template<typename Iterator>
62void test_traversal(Iterator iterator, boost::incrementable_traversal_tag)
63{
64  BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<Iterator>));
65}
66
67
68template<typename Iterator>
69void test_traversal(Iterator iterator, boost::single_pass_traversal_tag)
70{
71  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>));
72}
73
74
75template<typename Iterator>
76void test_traversal(Iterator iterator, boost::forward_traversal_tag)
77{
78  BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<Iterator>));
79}
80
81
82template<typename Iterator>
83void test_traversal(Iterator iterator, boost::bidirectional_traversal_tag)
84{
85  BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<Iterator>));
86}
87
88
89template<typename Iterator>
90void test_traversal(Iterator iterator, boost::random_access_traversal_tag)
91{
92  BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<Iterator>));
93}
94
95
96template<typename Iterator, typename ConstIterator>
97void 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
104template<typename Iterator, typename ConstIterator>
105void test_interoperability(Iterator i, ConstIterator ci,
106                           boost::incrementable_traversal_tag)
107{
108}
109
110
111template<typename TraversalCategory>
112void test1(void)
113{
114  utility::WeightedIteratorArchetype_ctor_arg arg;
115  using boost::iterator_archetypes::readable_iterator_t;
116  typedef utility::WeightedIteratorArchetype<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 utility::WeightedIteratorArchetype<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
143// test test::DataIterator
144template<typename TraversalCategory>
145void test2(void)
146{
147  TraversalCategory traversal;
148  typedef test::DataIterator<TraversalCategory> trait;
149  typename trait::unweighted_const_iterator const_iterator;
150  test_const_access(const_iterator);
151  test_traversal(const_iterator, traversal);
152  typename trait::unweighted_iterator iterator;
153  test_access(iterator);
154  test_traversal(iterator, traversal);
155
156  typename trait::weighted_const_iterator weighted_const_iterator;
157  test_const_access(weighted_const_iterator);
158  test_traversal(weighted_const_iterator, traversal);
159  typename trait::weighted_iterator weighted_iterator;
160  test_access(weighted_iterator);
161  test_traversal(weighted_iterator, traversal);
162}
163
164
165int main(void)
166{
167  // this is a compilation test - do not run
168  if (false) {
169    // On some systems std::iterator_traits<>::value_type does not
170    // work, so we require concept Data Iterator to be single pass.
171    //test1<boost::incrementable_traversal_tag>();
172    test1<boost::single_pass_traversal_tag>();
173    test1<boost::forward_traversal_tag>();
174    test1<boost::bidirectional_traversal_tag>();
175    test1<boost::random_access_traversal_tag>();
176
177    test2<boost::forward_traversal_tag>();
178    test2<boost::bidirectional_traversal_tag>();
179    test2<boost::random_access_traversal_tag>();
180  }
181
182  return 0;
183}
Note: See TracBrowser for help on using the repository browser.