source: trunk/yat/utility/concept_check.h @ 3788

Last change on this file since 3788 was 3788, checked in by Peter, 3 years ago

avoid compiler warnings with GCC v6.4.0

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1#ifndef _theplu_yat_utility_concept_check_
2#define _theplu_yat_utility_concept_check_
3
4// $Id: concept_check.h 3788 2019-01-29 06:08:25Z peter $
5
6/*
7  Copyright (C) 2010, 2011, 2013, 2015, 2016, 2017 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25// always include config first
26#include "config_public.h"
27
28#include "iterator_traits.h"
29#include "WeightedIteratorArchetype.h"
30
31#include <boost/concept_archetype.hpp>
32#include <boost/concept_check.hpp>
33#include <boost/iterator/iterator_archetypes.hpp>
34#include <boost/iterator/iterator_concepts.hpp>
35
36namespace theplu {
37namespace yat {
38namespace utility {
39
40  namespace detail {
41    template<typename T>
42    void avoid_compiler_warning(const T& t) {}
43  }
44
45
46  /**
47     \brief Concept check for \ref concept_container_2d
48
49     This class is intended to be used in a <a
50     href="\boost_url/concept_check/using_concept_check.htm">
51     BOOST_CONCEPT_ASSERT </a>
52
53     \code
54     template<class T>
55     void some_function(const T& t)
56     {
57     BOOST_CONCEPT_ASSERT((Container2D<T>));
58     ...
59     }
60     \endcode
61
62     \since New in yat 0.7
63  */
64  template <class T>
65  class Container2D
66  {
67  public:
68#ifdef YAT_HAVE_BOOST_CONCEPT_WITH_CONSTRUCTOR
69    /// Default constructor
70    Container2D(void) {}
71#endif
72
73    /// value_type
74    typedef typename T::value_type value_type;
75    /// const_reference
76    typedef typename T::const_reference const_reference;
77    /// const_iterator
78    typedef typename T::const_iterator const_iterator;
79    /// const_row_iterator
80    typedef typename T::const_row_iterator const_row_iterator;
81    /// const_column_iterator
82    typedef typename T::const_column_iterator const_column_iterator;
83
84    /**
85       \brief function doing the concept test
86     */
87    BOOST_CONCEPT_USAGE(Container2D)
88    {
89      const_iterator iter_ = t_.begin();
90      iter_ = t_.end();
91      detail::avoid_compiler_warning(iter_);
92      const_row_iterator row_iter_ = t_.begin_row(0);
93      row_iter_ = t_.end_row(0);
94      detail::avoid_compiler_warning(row_iter_);
95      const_column_iterator col_iter_ = t_.begin_column(0);
96      col_iter_ = t_.end_column(0);
97      detail::avoid_compiler_warning(col_iter_);
98      const_reference r = t_(0,0);
99      value_ = r;
100      size_t n = t_.rows();
101      n = t_.columns();
102      detail::avoid_compiler_warning(n);
103      using boost_concepts::ReadableIterator;
104      BOOST_CONCEPT_ASSERT((ReadableIterator<const_iterator>));
105      BOOST_CONCEPT_ASSERT((ReadableIterator<const_row_iterator>));
106      BOOST_CONCEPT_ASSERT((ReadableIterator<const_column_iterator>));
107    }
108
109  private:
110    T t_;
111    value_type value_;
112  };
113
114  /**
115     \brief Concept check for \ref concept_mutable_container_2d
116
117     This class is intended to be used in a <a
118     href="\boost_url/concept_check/using_concept_check.htm">
119     BOOST_CONCEPT_ASSERT </a>
120
121     \code
122     template<class T>
123     void some_function(const T& t)
124     {
125     BOOST_CONCEPT_ASSERT((Mutable_Container2D<T>));
126     ...
127     }
128     \endcode
129
130     \since New in yat 0.7
131  */
132  template <class T>
133  class Mutable_Container2D : public Container2D<T>
134  {
135  public:
136    /// reference
137    typedef typename T::reference reference;
138    /// iterator
139    typedef typename T::iterator iterator;
140    /// row_iterator
141    typedef typename T::row_iterator row_iterator;
142    /// column_iterator
143    typedef typename T::column_iterator column_iterator;
144
145    /**
146       \brief function doing the concept test
147     */
148    BOOST_CONCEPT_USAGE(Mutable_Container2D)
149    {
150      iterator iter_ = t_.begin();
151      iter_ = t_.end();
152      detail::avoid_compiler_warning(iter_);
153      row_iterator row_iter_ = t_.begin_row(0);
154      row_iter_ = t_.end_row(0);
155      detail::avoid_compiler_warning(row_iter_);
156      column_iterator col_iter_ = t_.begin_column(0);
157      col_iter_ = t_.end_column(0);
158      detail::avoid_compiler_warning(col_iter_);
159      reference r = t_(0,0);
160      t_(0,0) = r;
161      detail::avoid_compiler_warning(r);
162      using boost::Mutable_RandomAccessIterator; // just to avoid long lines
163      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
164      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
165      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
166    }
167  private:
168    T t_;
169  };
170
171
172  /**
173     \brief Concept check for Trivial Iterator
174
175     This class is intended to be used in a <a
176     href="\boost_url/concept_check/using_concept_check.htm">
177     BOOST_CONCEPT_ASSERT </a>
178
179     \code
180     template<class Iterator>
181     void some_function(const Iterator& it)
182     {
183     BOOST_CONCEPT_ASSERT((TrivialIterator<Iterator>));
184     ...
185     }
186     \endcode
187
188     \since New in yat 0.7
189  */
190  template <class T>
191  class TrivialIterator
192    : public boost::Assignable<T>
193    , public boost::EqualityComparable<T>
194    , public boost::DefaultConstructible<T>
195
196  {
197  public:
198    /// iterator_category
199    typedef typename std::iterator_traits<T>::iterator_category iterator_category;
200    /// value_type
201    typedef typename std::iterator_traits<T>::value_type value_type;
202    /// difference_type
203    typedef typename std::iterator_traits<T>::difference_type difference_type;
204    /// pointer
205    typedef typename std::iterator_traits<T>::pointer pointer;
206    /// reference
207    typedef typename std::iterator_traits<T>::reference reference;
208
209    /**
210       \brief function doing the concept test
211     */
212    BOOST_CONCEPT_USAGE(TrivialIterator)
213    {
214      T t;
215      value_ = *t;
216    }
217  private:
218    value_type value_;
219  };
220
221  /**
222     \brief Concept check for \ref concept_data_iterator
223
224     This class is intended to be used in a <a
225     href="\boost_url/concept_check/using_concept_check.htm">
226     BOOST_CONCEPT_ASSERT </a>
227
228     \code
229     template<class Iterator>
230     void some_function(const Iterator& it)
231     {
232     BOOST_CONCEPT_ASSERT((DataIteratorConcept<Iterator>));
233     ...
234     }
235     \endcode
236
237     \since New in yat 0.7
238  */
239  template <class T>
240  class DataIteratorConcept
241  {
242  public:
243    /// tag
244    typedef typename weighted_iterator_traits<T>::type tag;
245    /// value_type
246    typedef typename std::iterator_traits<T>::value_type value_type;
247
248    /**
249       \brief function doing the concept test
250     */
251    BOOST_CONCEPT_USAGE(DataIteratorConcept)
252    {
253      BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<T>));
254      BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<T>));
255      tag t;
256      constraints(t);
257    }
258  private:
259    void constraints(yat::utility::unweighted_iterator_tag t) const
260    {
261      BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
262    }
263
264    void constraints(yat::utility::weighted_iterator_tag t) const
265    {
266      BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
267    }
268  };
269
270
271  /**
272     \brief Concept check for a \ref concept_distance
273
274     This class is intended to be used in a <a
275     href="\boost_url/concept_check/using_concept_check.htm">
276     BOOST_CONCEPT_ASSERT </a>
277
278     \code
279     template<class Distance>
280     void some_function(double x)
281     {
282     BOOST_CONCEPT_ASSERT((DistanceConcept<Distance>));
283     ...
284     }
285     \endcode
286
287     \since New in yat 0.7
288  */
289  template <class T>
290  class DistanceConcept : public boost::CopyConstructible<T>
291  {
292  public:
293    /**
294       \brief function doing the concept test
295     */
296    BOOST_CONCEPT_USAGE(DistanceConcept)
297    {
298      using boost::iterator_archetypes::readable_iterator_t;
299      using boost::forward_traversal_tag;
300      boost::iterator_archetype<double, readable_iterator_t,
301                                forward_traversal_tag> unweighted;
302      WeightedIteratorArchetype<readable_iterator_t, forward_traversal_tag>
303        weighted;
304      double d=0;
305      d += distance_(unweighted, unweighted, unweighted);
306      d += distance_(unweighted, unweighted, weighted);
307      d += distance_(weighted, weighted, unweighted);
308      d += distance_(weighted, weighted, weighted);
309      detail::avoid_compiler_warning(d);
310    }
311  private:
312    T distance_;
313  };
314
315}}} // of namespace utility, yat, and theplu
316#endif
Note: See TracBrowser for help on using the repository browser.