yat  0.10.4pre
concept_check.h
1 #ifndef _theplu_yat_utility_concept_check_
2 #define _theplu_yat_utility_concept_check_
3 
4 // $Id: concept_check.h 2673 2011-12-03 00:30:12Z peter $
5 
6 /*
7  Copyright (C) 2010, 2011 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 
61  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  BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_iterator>));
91  BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_row_iterator>));
92  BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<const_column_iterator>));
93  }
94 
95  private:
96  T t_;
97  value_type value_;
98  };
99 
118  template <class T>
120  {
121  public:
123  typedef typename T::reference reference;
125  typedef typename T::iterator iterator;
127  typedef typename T::row_iterator row_iterator;
129  typedef typename T::column_iterator column_iterator;
130 
135  {
136  iterator iter_ = t_.begin();
137  iter_ = t_.end();
138  row_iterator row_iter_ = t_.begin_row(0);
139  row_iter_ = t_.end_row(0);
140  column_iterator col_iter_ = t_.begin_column(0);
141  col_iter_ = t_.end_column(0);
142  reference r = t_(0,0);
143  t_(0,0) = r;
144  using boost::Mutable_RandomAccessIterator; // just to avoid long lines
145  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<iterator>));
146  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<row_iterator>));
147  BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<column_iterator>));
148  }
149  private:
150  T t_;
151  };
152 
153 
172  template <class T>
174  : public boost::Assignable<T>
175  , public boost::EqualityComparable<T>
176  , public boost::DefaultConstructible<T>
177 
178  {
179  public:
181  typedef typename std::iterator_traits<T>::iterator_category iterator_category;
183  typedef typename std::iterator_traits<T>::value_type value_type;
185  typedef typename std::iterator_traits<T>::difference_type difference_type;
187  typedef typename std::iterator_traits<T>::pointer pointer;
189  typedef typename std::iterator_traits<T>::reference reference;
190 
195  {
196  T t;
197  value_ = *t;
198  }
199  private:
200  value_type value_;
201  };
202 
221  template <class T>
223  {
224  public:
228  typedef typename std::iterator_traits<T>::value_type value_type;
229 
234  {
235  BOOST_CONCEPT_ASSERT((TrivialIterator<T>));
236  tag t;
237  constraints(t);
238  }
239  private:
240  void constraints(yat::utility::unweighted_iterator_tag t) const
241  {
242  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, double>));
243  }
244 
245  void constraints(yat::utility::weighted_iterator_tag t) const
246  {
247  BOOST_CONCEPT_ASSERT((boost::Convertible<value_type, DataWeight>));
248  }
249  };
250 
251 
270  template <class T>
271  class DistanceConcept : public boost::CopyConstructible<T>
272  {
273  public:
278  {
279  boost::random_access_iterator_archetype<double> unweighted;
280  boost::random_access_iterator_archetype<DataWeight> weighted;
281  double d;
282  d = distance_(unweighted, unweighted, unweighted);
283  d = distance_(unweighted, unweighted, weighted);
284  d = distance_(weighted, weighted, unweighted);
285  d = distance_(weighted, weighted, weighted);
286  }
287  private:
288  T distance_;
289  };
290 
291 }}} // of namespace utility, yat, and theplu
292 #endif

Generated on Mon Nov 11 2013 09:41:44 for yat by  doxygen 1.8.1