source: branches/0.7-stable/yat/utility/concept_check.h @ 2403

Last change on this file since 2403 was 2403, checked in by Peter, 11 years ago

avoid compiler warnings. fixes #648

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1#ifndef _theplu_yat_utility_concept_check_
2#define _theplu_yat_utility_concept_check_
3
4// $Id: concept_check.h 2403 2011-01-10 17:50:03Z peter $
5
6/*
7  Copyright (C) 2010 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#include "iterator_traits.h"
26
27#include <boost/concept_archetype.hpp>
28#include <boost/concept_check.hpp>
29
30namespace theplu {
31namespace yat {
32namespace utility {
33
34  /**
35     \brief Concept check for \ref concept_container_2d
36
37     This class is intended to be used in a <a
38     href="\boost_url/concept_check/using_concept_check.htm">
39     BOOST_CONCEPT_ASSERT </a>
40
41     \code
42     template<class T>
43     void some_function(const T& t)
44     {
45     BOOST_CONCEPT_ASSERT((Container2D<T>));
46     ...
47     }
48     \endcode
49
50     \since New in yat 0.7
51  */
52  template <class T>
53  class Container2D
54  {
55  public:
56    /// Default constructor
57    Container2D(void) {}
58
59    /// value_type
60    typedef typename T::value_type value_type;
61    /// const_reference
62    typedef typename T::const_reference const_reference;
63    /// const_iterator
64    typedef typename T::const_iterator const_iterator;
65    /// const_row_iterator
66    typedef typename T::const_row_iterator const_row_iterator;
67    /// const_column_iterator
68    typedef typename T::const_column_iterator const_column_iterator;
69
70    /**
71       \brief function doing the concept test
72     */
73    BOOST_CONCEPT_USAGE(Container2D)
74    {
75      const_iterator iter_ = t_.begin();
76      iter_ = t_.end();
77      const_row_iterator row_iter_ = t_.begin_row(0);
78      row_iter_ = t_.end_row(0);
79      const_column_iterator col_iter_ = t_.begin_column(0);
80      col_iter_ = t_.end_column(0);
81      const_reference r = t_(0,0);
82      value_ = r;
83      size_t n = t_.rows();
84      n = t_.columns();
85      BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_iterator>));
86      BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_row_iterator>));
87      BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_column_iterator>));
88    }
89
90  private:
91    T t_;
92    value_type value_;
93  };
94
95  /**
96     \brief Concept check for \ref concept_mutable_container_2d
97
98     This class is intended to be used in a <a
99     href="\boost_url/concept_check/using_concept_check.htm">
100     BOOST_CONCEPT_ASSERT </a>
101
102     \code
103     template<class T>
104     void some_function(const T& t)
105     {
106     BOOST_CONCEPT_ASSERT((Mutable_Container2D<T>));
107     ...
108     }
109     \endcode
110
111     \since New in yat 0.7
112  */
113  template <class T>
114  class Mutable_Container2D : public Container2D<T>
115  {
116  public:
117    /// reference
118    typedef typename T::reference reference;
119    /// iterator
120    typedef typename T::iterator iterator;
121    /// row_iterator
122    typedef typename T::row_iterator row_iterator;
123    /// column_iterator
124    typedef typename T::column_iterator column_iterator;
125
126    /**
127       \brief function doing the concept test
128     */
129    BOOST_CONCEPT_USAGE(Mutable_Container2D)
130    {
131      iterator iter_ = t_.begin();
132      iter_ = t_.end();
133      row_iterator row_iter_ = t_.begin_row(0);
134      row_iter_ = t_.end_row(0);
135      column_iterator col_iter_ = t_.begin_column(0);
136      col_iter_ = t_.end_column(0);
137      reference r = t_(0,0);
138      t_(0,0) = r;
139      using boost::Mutable_RandomAccessIterator; // just to avoid long lines
140      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
141      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
142      BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
143    }
144  private:
145    T t_;
146  };
147
148
149  /**
150     \brief Concept check for \trivial_iterator
151
152     This class is intended to be used in a <a
153     href="\boost_url/concept_check/using_concept_check.htm">
154     BOOST_CONCEPT_ASSERT </a>
155
156     \code
157     template<class Iterator>
158     void some_function(const Iterator& it)
159     {
160     BOOST_CONCEPT_ASSERT((TrivialIterator<Iterator>));
161     ...
162     }
163     \endcode
164
165     \since New in yat 0.7
166  */
167  template <class T>
168  class TrivialIterator
169    : public boost::Assignable<T>
170    , public boost::EqualityComparable<T>
171    , public boost::DefaultConstructible<T>
172
173  {
174  public:
175    /// iterator_category
176    typedef typename std::iterator_traits<T>::iterator_category iterator_category;
177    /// value_type
178    typedef typename std::iterator_traits<T>::value_type value_type;
179    /// difference_type
180    typedef typename std::iterator_traits<T>::difference_type difference_type;
181    /// pointer
182    typedef typename std::iterator_traits<T>::pointer pointer;
183    /// reference
184    typedef typename std::iterator_traits<T>::reference reference;
185
186    /**
187       \brief function doing the concept test
188     */
189    BOOST_CONCEPT_USAGE(TrivialIterator)
190    {
191      T t;
192      value_ = *t;
193    }
194  private:
195    value_type value_;
196  };
197
198  /**
199     \brief Concept check for \ref concept_data_iterator
200
201     This class is intended to be used in a <a
202     href="\boost_url/concept_check/using_concept_check.htm">
203     BOOST_CONCEPT_ASSERT </a>
204
205     \code
206     template<class Iterator>
207     void some_function(const Iterator& it)
208     {
209     BOOST_CONCEPT_ASSERT((DataIteratorConcept<Iterator>));
210     ...
211     }
212     \endcode
213
214     \since New in yat 0.7
215  */
216  template <class T>
217  class DataIteratorConcept
218  {
219  public:
220    /// tag
221    typedef typename weighted_iterator_traits<T>::type tag;
222    /// value_type
223    typedef typename std::iterator_traits<T>::value_type value_type;
224
225    /**
226       \brief function doing the concept test
227     */
228    BOOST_CONCEPT_USAGE(DataIteratorConcept)
229    {
230      BOOST_CONCEPT_ASSERT((TrivialIterator<T>));
231      tag t;
232      constraints(t);
233    }
234  private:
235    void constraints(yat::utility::unweighted_iterator_tag t) const
236    { 
237      BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
238    }
239
240    void constraints(yat::utility::weighted_iterator_tag t) const
241    {
242      BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
243    }
244  };
245
246
247  /**
248     \brief Concept check for a \ref concept_distance
249
250     This class is intended to be used in a <a
251     href="\boost_url/concept_check/using_concept_check.htm">
252     BOOST_CONCEPT_ASSERT </a>
253
254     \code
255     template<class Distance>
256     void some_function(double x)
257     {
258     BOOST_CONCEPT_ASSERT((DistanceConcept<Distance>));
259     ...
260     }
261     \endcode
262
263     \since New in yat 0.7
264  */
265  template <class T>
266  class DistanceConcept : public boost::CopyConstructible<T>
267  {
268  public:
269    /**
270       \brief function doing the concept test
271     */
272    BOOST_CONCEPT_USAGE(DistanceConcept)
273    {
274      boost::random_access_iterator_archetype<double> unweighted;
275      boost::random_access_iterator_archetype<DataWeight> weighted;
276      double d;
277      d = distance_(unweighted, unweighted, unweighted);
278      d = distance_(unweighted, unweighted, weighted);
279      d = distance_(weighted, weighted, unweighted);
280      d = distance_(weighted, weighted, weighted);
281    }
282  private:
283    T distance_;
284  };
285
286}}} // of namespace utility, yat, and theplu
287#endif
Note: See TracBrowser for help on using the repository browser.