yat  0.14.5pre
concept_check.h
1 #ifndef _theplu_yat_utility_concept_check_
2 #define _theplu_yat_utility_concept_check_
3 
4 // $Id: concept_check.h 3569 2017-01-09 03:43:08Z 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 
36 namespace theplu {
37 namespace yat {
38 namespace utility {
39 
58  template <class T>
60  {
61  public:
62 #ifdef YAT_HAVE_BOOST_CONCEPT_WITH_CONSTRUCTOR
63  Container2D(void) {}
65 #endif
66 
68  typedef typename T::value_type value_type;
70  typedef typename T::const_reference const_reference;
72  typedef typename T::const_iterator const_iterator;
74  typedef typename T::const_row_iterator const_row_iterator;
76  typedef typename T::const_column_iterator const_column_iterator;
77 
82  {
83  const_iterator iter_ = t_.begin();
84  iter_ = t_.end();
85  const_row_iterator row_iter_ = t_.begin_row(0);
86  row_iter_ = t_.end_row(0);
87  const_column_iterator col_iter_ = t_.begin_column(0);
88  col_iter_ = t_.end_column(0);
89  const_reference r = t_(0,0);
90  value_ = r;
91  size_t n = t_.rows();
92  n = t_.columns();
93  some_func(n);
94  using boost_concepts::ReadableIterator;
95  BOOST_CONCEPT_ASSERT((ReadableIterator<const_iterator>));
96  BOOST_CONCEPT_ASSERT((ReadableIterator<const_row_iterator>));
97  BOOST_CONCEPT_ASSERT((ReadableIterator<const_column_iterator>));
98  }
99 
100  private:
101  void some_func(size_t x) const {}
102  T t_;
103  value_type value_;
104  };
105 
124  template <class T>
126  {
127  public:
129  typedef typename T::reference reference;
131  typedef typename T::iterator iterator;
133  typedef typename T::row_iterator row_iterator;
135  typedef typename T::column_iterator column_iterator;
136 
141  {
142  iterator iter_ = t_.begin();
143  iter_ = t_.end();
144  row_iterator row_iter_ = t_.begin_row(0);
145  row_iter_ = t_.end_row(0);
146  column_iterator col_iter_ = t_.begin_column(0);
147  col_iter_ = t_.end_column(0);
148  reference r = t_(0,0);
149  t_(0,0) = r;
150  using boost::Mutable_RandomAccessIterator; // just to avoid long lines
151  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
152  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
153  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
154  }
155  private:
156  T t_;
157  };
158 
159 
178  template <class T>
180  : public boost::Assignable<T>
181  , public boost::EqualityComparable<T>
182  , public boost::DefaultConstructible<T>
183 
184  {
185  public:
187  typedef typename std::iterator_traits<T>::iterator_category iterator_category;
189  typedef typename std::iterator_traits<T>::value_type value_type;
191  typedef typename std::iterator_traits<T>::difference_type difference_type;
193  typedef typename std::iterator_traits<T>::pointer pointer;
195  typedef typename std::iterator_traits<T>::reference reference;
196 
201  {
202  T t;
203  value_ = *t;
204  }
205  private:
206  value_type value_;
207  };
208 
227  template <class T>
229  {
230  public:
234  typedef typename std::iterator_traits<T>::value_type value_type;
235 
240  {
241  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<T>));
242  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<T>));
243  tag t;
244  constraints(t);
245  }
246  private:
247  void constraints(yat::utility::unweighted_iterator_tag t) const
248  {
249  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
250  }
251 
252  void constraints(yat::utility::weighted_iterator_tag t) const
253  {
254  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
255  }
256  };
257 
258 
277  template <class T>
278  class DistanceConcept : public boost::CopyConstructible<T>
279  {
280  public:
285  {
286  using boost::iterator_archetypes::readable_iterator_t;
287  using boost::forward_traversal_tag;
288  boost::iterator_archetype<double, readable_iterator_t,
289  forward_traversal_tag> unweighted;
291  weighted;
292  double d=0;
293  d += distance_(unweighted, unweighted, unweighted);
294  d += distance_(unweighted, unweighted, weighted);
295  d += distance_(weighted, weighted, unweighted);
296  d += distance_(weighted, weighted, weighted);
297  // avoid compiler warning
298  func(d);
299  }
300  private:
301  void func(double x) {}
302  T distance_;
303  };
304 
305 }}} // of namespace utility, yat, and theplu
306 #endif
weighted_iterator_traits< T >::type tag
tag
Definition: concept_check.h:232
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:114
Concept check for Trivial Iterator
Definition: concept_check.h:179
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:234
Concept check for Data Iterator.
Definition: concept_check.h:228
Concept check for Container2D.
Definition: concept_check.h:59
Definition: iterator_traits.h:47
T::const_reference const_reference
const_reference
Definition: concept_check.h:70
std::iterator_traits< T >::iterator_category iterator_category
iterator_category
Definition: concept_check.h:187
Concept check for Mutable Container2D.
Definition: concept_check.h:125
Definition: WeightedIteratorArchetype.h:133
Definition: iterator_traits.h:55
std::iterator_traits< T >::difference_type difference_type
difference_type
Definition: concept_check.h:191
T::const_iterator const_iterator
const_iterator
Definition: concept_check.h:72
BOOST_CONCEPT_USAGE(TrivialIterator)
function doing the concept test
Definition: concept_check.h:200
BOOST_CONCEPT_USAGE(Container2D)
function doing the concept test
Definition: concept_check.h:81
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:189
std::iterator_traits< T >::pointer pointer
pointer
Definition: concept_check.h:193
T::const_row_iterator const_row_iterator
const_row_iterator
Definition: concept_check.h:74
BOOST_CONCEPT_USAGE(Mutable_Container2D)
function doing the concept test
Definition: concept_check.h:140
T::iterator iterator
iterator
Definition: concept_check.h:131
T::row_iterator row_iterator
row_iterator
Definition: concept_check.h:133
std::iterator_traits< T >::reference reference
reference
Definition: concept_check.h:195
BOOST_CONCEPT_USAGE(DataIteratorConcept)
function doing the concept test
Definition: concept_check.h:239
Concept check for a Distance.
Definition: concept_check.h:278
T::reference reference
reference
Definition: concept_check.h:129
T::const_column_iterator const_column_iterator
const_column_iterator
Definition: concept_check.h:76
T::value_type value_type
value_type
Definition: concept_check.h:68
T::column_iterator column_iterator
column_iterator
Definition: concept_check.h:135
BOOST_CONCEPT_USAGE(DistanceConcept)
function doing the concept test
Definition: concept_check.h:284
Container2D(void)
Default constructor.
Definition: concept_check.h:64

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5