yat  0.12.3pre
concept_check.h
1 #ifndef _theplu_yat_utility_concept_check_
2 #define _theplu_yat_utility_concept_check_
3 
4 // $Id: concept_check.h 3114 2013-11-10 23:51:47Z peter $
5 
6 /*
7  Copyright (C) 2010, 2011, 2013 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 
30 #include <boost/concept_archetype.hpp>
31 #include <boost/concept_check.hpp>
32 
33 namespace theplu {
34 namespace yat {
35 namespace utility {
36 
55  template <class T>
57  {
58  public:
59 #ifdef YAT_HAVE_BOOST_CONCEPT_WITH_CONSTRUCTOR
60  Container2D(void) {}
62 #endif
63 
65  typedef typename T::value_type value_type;
67  typedef typename T::const_reference const_reference;
69  typedef typename T::const_iterator const_iterator;
71  typedef typename T::const_row_iterator const_row_iterator;
73  typedef typename T::const_column_iterator const_column_iterator;
74 
79  {
80  const_iterator iter_ = t_.begin();
81  iter_ = t_.end();
82  const_row_iterator row_iter_ = t_.begin_row(0);
83  row_iter_ = t_.end_row(0);
84  const_column_iterator col_iter_ = t_.begin_column(0);
85  col_iter_ = t_.end_column(0);
86  const_reference r = t_(0,0);
87  value_ = r;
88  size_t n = t_.rows();
89  n = t_.columns();
90  some_func(n);
91  BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_iterator>));
92  BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_row_iterator>));
93  BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_column_iterator>));
94  }
95 
96  private:
97  void some_func(size_t x) const {}
98  T t_;
99  value_type value_;
100  };
101 
120  template <class T>
122  {
123  public:
125  typedef typename T::reference reference;
127  typedef typename T::iterator iterator;
129  typedef typename T::row_iterator row_iterator;
131  typedef typename T::column_iterator column_iterator;
132 
137  {
138  iterator iter_ = t_.begin();
139  iter_ = t_.end();
140  row_iterator row_iter_ = t_.begin_row(0);
141  row_iter_ = t_.end_row(0);
142  column_iterator col_iter_ = t_.begin_column(0);
143  col_iter_ = t_.end_column(0);
144  reference r = t_(0,0);
145  t_(0,0) = r;
146  using boost::Mutable_RandomAccessIterator; // just to avoid long lines
147  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
148  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
149  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
150  }
151  private:
152  T t_;
153  };
154 
155 
174  template <class T>
176  : public boost::Assignable<T>
177  , public boost::EqualityComparable<T>
178  , public boost::DefaultConstructible<T>
179 
180  {
181  public:
183  typedef typename std::iterator_traits<T>::iterator_category iterator_category;
185  typedef typename std::iterator_traits<T>::value_type value_type;
187  typedef typename std::iterator_traits<T>::difference_type difference_type;
189  typedef typename std::iterator_traits<T>::pointer pointer;
191  typedef typename std::iterator_traits<T>::reference reference;
192 
197  {
198  T t;
199  value_ = *t;
200  }
201  private:
202  value_type value_;
203  };
204 
223  template <class T>
225  {
226  public:
230  typedef typename std::iterator_traits<T>::value_type value_type;
231 
236  {
237  BOOST_CONCEPT_ASSERT((TrivialIterator<T>));
238  tag t;
239  constraints(t);
240  }
241  private:
242  void constraints(yat::utility::unweighted_iterator_tag t) const
243  {
244  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
245  }
246 
247  void constraints(yat::utility::weighted_iterator_tag t) const
248  {
249  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
250  }
251  };
252 
253 
272  template <class T>
273  class DistanceConcept : public boost::CopyConstructible<T>
274  {
275  public:
280  {
281  boost::random_access_iterator_archetype<double> unweighted;
282  boost::random_access_iterator_archetype<DataWeight> weighted;
283  double d=0;
284  d += distance_(unweighted, unweighted, unweighted);
285  d += distance_(unweighted, unweighted, weighted);
286  d += distance_(weighted, weighted, unweighted);
287  d += distance_(weighted, weighted, weighted);
288  // avoid compiler warning
289  func(d);
290  }
291  private:
292  void func(double x) {}
293  T distance_;
294  };
295 
296 }}} // of namespace utility, yat, and theplu
297 #endif
weighted_iterator_traits< T >::type tag
tag
Definition: concept_check.h:228
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:108
Concept check for Trivial Iterator
Definition: concept_check.h:175
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:230
Concept check for Data Iterator.
Definition: concept_check.h:224
Concept check for Container2D.
Definition: concept_check.h:56
Definition: iterator_traits.h:46
T::const_reference const_reference
const_reference
Definition: concept_check.h:67
std::iterator_traits< T >::iterator_category iterator_category
iterator_category
Definition: concept_check.h:183
Concept check for Mutable Container2D.
Definition: concept_check.h:121
Definition: iterator_traits.h:54
std::iterator_traits< T >::difference_type difference_type
difference_type
Definition: concept_check.h:187
T::const_iterator const_iterator
const_iterator
Definition: concept_check.h:69
BOOST_CONCEPT_USAGE(TrivialIterator)
function doing the concept test
Definition: concept_check.h:196
BOOST_CONCEPT_USAGE(Container2D)
function doing the concept test
Definition: concept_check.h:78
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:185
std::iterator_traits< T >::pointer pointer
pointer
Definition: concept_check.h:189
T::const_row_iterator const_row_iterator
const_row_iterator
Definition: concept_check.h:71
BOOST_CONCEPT_USAGE(Mutable_Container2D)
function doing the concept test
Definition: concept_check.h:136
T::iterator iterator
iterator
Definition: concept_check.h:127
T::row_iterator row_iterator
row_iterator
Definition: concept_check.h:129
std::iterator_traits< T >::reference reference
reference
Definition: concept_check.h:191
BOOST_CONCEPT_USAGE(DataIteratorConcept)
function doing the concept test
Definition: concept_check.h:235
Concept check for a Distance.
Definition: concept_check.h:273
T::reference reference
reference
Definition: concept_check.h:125
T::const_column_iterator const_column_iterator
const_column_iterator
Definition: concept_check.h:73
T::value_type value_type
value_type
Definition: concept_check.h:65
T::column_iterator column_iterator
column_iterator
Definition: concept_check.h:131
BOOST_CONCEPT_USAGE(DistanceConcept)
function doing the concept test
Definition: concept_check.h:279
Container2D(void)
Default constructor.
Definition: concept_check.h:61

Generated on Mon Jun 1 2015 12:29:52 for yat by  doxygen 1.8.5