yat  0.21pre
concept_check.h
1 #ifndef _theplu_yat_utility_concept_check_
2 #define _theplu_yat_utility_concept_check_
3 
4 // $Id: concept_check.h 4207 2022-08-26 04:36:28Z peter $
5 
6 /*
7  Copyright (C) 2010, 2011, 2013, 2015, 2016, 2017, 2018, 2019, 2022 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 
40  namespace detail {
41  template<typename T>
42  void avoid_compiler_warning(const T& t) {}
43  }
44 
45 
64  template <class T>
66  {
67  public:
68 #ifdef YAT_HAVE_BOOST_CONCEPT_WITH_CONSTRUCTOR
69  Container2D(void) {}
71 #endif
72 
74  typedef typename T::value_type value_type;
76  typedef typename T::const_reference const_reference;
78  typedef typename T::const_iterator const_iterator;
80  typedef typename T::const_row_iterator const_row_iterator;
82  typedef typename T::const_column_iterator const_column_iterator;
83 
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 
132  template <class T>
134  {
135  public:
137  typedef typename T::reference reference;
139  typedef typename T::iterator iterator;
141  typedef typename T::row_iterator row_iterator;
143  typedef typename T::column_iterator column_iterator;
144 
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 
190  template <class T>
192  : public boost::Assignable<T>
193  , public boost::EqualityComparable<T>
194  , public boost::DefaultConstructible<T>
195 
196  {
197  public:
199  typedef typename std::iterator_traits<T>::iterator_category iterator_category;
201  typedef typename std::iterator_traits<T>::value_type value_type;
203  typedef typename std::iterator_traits<T>::difference_type difference_type;
205  typedef typename std::iterator_traits<T>::pointer pointer;
207  typedef typename std::iterator_traits<T>::reference reference;
208 
213  {
214  T t;
215  value_ = *t;
216  }
217  private:
218  value_type value_;
219  };
220 
239  template <class T>
241  {
242  public:
246  typedef typename std::iterator_traits<T>::value_type value_type;
247 
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 
289  template <class T>
290  class DistanceConcept : public boost::CopyConstructible<T>
291  {
292  public:
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;
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
weighted_iterator_traits< T >::type tag
tag
Definition: concept_check.h:244
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:114
Concept check for Trivial Iterator.
Definition: concept_check.h:191
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:246
Concept check for Data Iterator.
Definition: concept_check.h:240
The Department of Theoretical Physics namespace as we define it.
Concept check for Container2D.
Definition: concept_check.h:65
Definition: iterator_traits.h:47
T::const_reference const_reference
const_reference
Definition: concept_check.h:76
std::iterator_traits< T >::iterator_category iterator_category
iterator_category
Definition: concept_check.h:199
Concept check for Mutable Container2D.
Definition: concept_check.h:133
Definition: WeightedIteratorArchetype.h:133
Definition: iterator_traits.h:55
std::iterator_traits< T >::difference_type difference_type
difference_type
Definition: concept_check.h:203
T::const_iterator const_iterator
const_iterator
Definition: concept_check.h:78
BOOST_CONCEPT_USAGE(TrivialIterator)
function doing the concept test
Definition: concept_check.h:212
BOOST_CONCEPT_USAGE(Container2D)
function doing the concept test
Definition: concept_check.h:87
std::iterator_traits< T >::value_type value_type
value_type
Definition: concept_check.h:201
std::iterator_traits< T >::pointer pointer
pointer
Definition: concept_check.h:205
T::const_row_iterator const_row_iterator
const_row_iterator
Definition: concept_check.h:80
BOOST_CONCEPT_USAGE(Mutable_Container2D)
function doing the concept test
Definition: concept_check.h:148
T::iterator iterator
iterator
Definition: concept_check.h:139
T::row_iterator row_iterator
row_iterator
Definition: concept_check.h:141
std::iterator_traits< T >::reference reference
reference
Definition: concept_check.h:207
BOOST_CONCEPT_USAGE(DataIteratorConcept)
function doing the concept test
Definition: concept_check.h:251
Concept check for a Distance.
Definition: concept_check.h:290
T::reference reference
reference
Definition: concept_check.h:137
T::const_column_iterator const_column_iterator
const_column_iterator
Definition: concept_check.h:82
T::value_type value_type
value_type
Definition: concept_check.h:74
T::column_iterator column_iterator
column_iterator
Definition: concept_check.h:143
BOOST_CONCEPT_USAGE(DistanceConcept)
function doing the concept test
Definition: concept_check.h:296
Container2D(void)
Default constructor.
Definition: concept_check.h:70

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14