yat  0.13.2pre
concept_check.h
1 #ifndef _theplu_yat_utility_concept_check_
2 #define _theplu_yat_utility_concept_check_
3 
4 // $Id: concept_check.h 3417 2015-05-25 01:35:59Z peter $
5 
6 /*
7  Copyright (C) 2010, 2011, 2013, 2015 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 #include <boost/iterator/iterator_concepts.hpp>
33 
34 namespace theplu {
35 namespace yat {
36 namespace utility {
37 
56  template <class T>
58  {
59  public:
60 #ifdef YAT_HAVE_BOOST_CONCEPT_WITH_CONSTRUCTOR
61  Container2D(void) {}
63 #endif
64 
66  typedef typename T::value_type value_type;
68  typedef typename T::const_reference const_reference;
70  typedef typename T::const_iterator const_iterator;
72  typedef typename T::const_row_iterator const_row_iterator;
74  typedef typename T::const_column_iterator const_column_iterator;
75 
80  {
81  const_iterator iter_ = t_.begin();
82  iter_ = t_.end();
83  const_row_iterator row_iter_ = t_.begin_row(0);
84  row_iter_ = t_.end_row(0);
85  const_column_iterator col_iter_ = t_.begin_column(0);
86  col_iter_ = t_.end_column(0);
87  const_reference r = t_(0,0);
88  value_ = r;
89  size_t n = t_.rows();
90  n = t_.columns();
91  some_func(n);
92  using boost_concepts::ReadableIterator;
93  BOOST_CONCEPT_ASSERT((ReadableIterator<const_iterator>));
94  BOOST_CONCEPT_ASSERT((ReadableIterator<const_row_iterator>));
95  BOOST_CONCEPT_ASSERT((ReadableIterator<const_column_iterator>));
96  }
97 
98  private:
99  void some_func(size_t x) const {}
100  T t_;
101  value_type value_;
102  };
103 
122  template <class T>
124  {
125  public:
127  typedef typename T::reference reference;
129  typedef typename T::iterator iterator;
131  typedef typename T::row_iterator row_iterator;
133  typedef typename T::column_iterator column_iterator;
134 
139  {
140  iterator iter_ = t_.begin();
141  iter_ = t_.end();
142  row_iterator row_iter_ = t_.begin_row(0);
143  row_iter_ = t_.end_row(0);
144  column_iterator col_iter_ = t_.begin_column(0);
145  col_iter_ = t_.end_column(0);
146  reference r = t_(0,0);
147  t_(0,0) = r;
148  using boost::Mutable_RandomAccessIterator; // just to avoid long lines
149  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
150  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
151  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
152  }
153  private:
154  T t_;
155  };
156 
157 
176  template <class T>
178  : public boost::Assignable<T>
179  , public boost::EqualityComparable<T>
180  , public boost::DefaultConstructible<T>
181 
182  {
183  public:
185  typedef typename std::iterator_traits<T>::iterator_category iterator_category;
187  typedef typename std::iterator_traits<T>::value_type value_type;
189  typedef typename std::iterator_traits<T>::difference_type difference_type;
191  typedef typename std::iterator_traits<T>::pointer pointer;
193  typedef typename std::iterator_traits<T>::reference reference;
194 
199  {
200  T t;
201  value_ = *t;
202  }
203  private:
204  value_type value_;
205  };
206 
225  template <class T>
227  {
228  public:
232  typedef typename std::iterator_traits<T>::value_type value_type;
233 
238  {
239  BOOST_CONCEPT_ASSERT((TrivialIterator<T>));
240  tag t;
241  constraints(t);
242  }
243  private:
244  void constraints(yat::utility::unweighted_iterator_tag t) const
245  {
246  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
247  }
248 
249  void constraints(yat::utility::weighted_iterator_tag t) const
250  {
251  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
252  }
253  };
254 
255 
274  template <class T>
275  class DistanceConcept : public boost::CopyConstructible<T>
276  {
277  public:
282  {
283  boost::random_access_iterator_archetype<double> unweighted;
284  boost::random_access_iterator_archetype<DataWeight> weighted;
285  double d=0;
286  d += distance_(unweighted, unweighted, unweighted);
287  d += distance_(unweighted, unweighted, weighted);
288  d += distance_(weighted, weighted, unweighted);
289  d += distance_(weighted, weighted, weighted);
290  // avoid compiler warning
291  func(d);
292  }
293  private:
294  void func(double x) {}
295  T distance_;
296  };
297 
298 }}} // of namespace utility, yat, and theplu
299 #endif
weighted_iterator_traits< T >::type tag
tag
Definition: concept_check.h:230
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:114
Concept check for Trivial Iterator
Definition: concept_check.h:177
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:232
Concept check for Data Iterator.
Definition: concept_check.h:226
Concept check for Container2D.
Definition: concept_check.h:57
Definition: iterator_traits.h:47
T::const_reference const_reference
const_reference
Definition: concept_check.h:68
std::iterator_traits< T >::iterator_category iterator_category
iterator_category
Definition: concept_check.h:185
Concept check for Mutable Container2D.
Definition: concept_check.h:123
Definition: iterator_traits.h:55
std::iterator_traits< T >::difference_type difference_type
difference_type
Definition: concept_check.h:189
T::const_iterator const_iterator
const_iterator
Definition: concept_check.h:70
BOOST_CONCEPT_USAGE(TrivialIterator)
function doing the concept test
Definition: concept_check.h:198
BOOST_CONCEPT_USAGE(Container2D)
function doing the concept test
Definition: concept_check.h:79
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:187
std::iterator_traits< T >::pointer pointer
pointer
Definition: concept_check.h:191
T::const_row_iterator const_row_iterator
const_row_iterator
Definition: concept_check.h:72
BOOST_CONCEPT_USAGE(Mutable_Container2D)
function doing the concept test
Definition: concept_check.h:138
T::iterator iterator
iterator
Definition: concept_check.h:129
T::row_iterator row_iterator
row_iterator
Definition: concept_check.h:131
std::iterator_traits< T >::reference reference
reference
Definition: concept_check.h:193
BOOST_CONCEPT_USAGE(DataIteratorConcept)
function doing the concept test
Definition: concept_check.h:237
Concept check for a Distance.
Definition: concept_check.h:275
T::reference reference
reference
Definition: concept_check.h:127
T::const_column_iterator const_column_iterator
const_column_iterator
Definition: concept_check.h:74
T::value_type value_type
value_type
Definition: concept_check.h:66
T::column_iterator column_iterator
column_iterator
Definition: concept_check.h:133
BOOST_CONCEPT_USAGE(DistanceConcept)
function doing the concept test
Definition: concept_check.h:281
Container2D(void)
Default constructor.
Definition: concept_check.h:62

Generated on Wed Jan 4 2017 02:23:07 for yat by  doxygen 1.8.5