aimstil  5.0.5
std_wrap.h
Go to the documentation of this file.
1 #ifndef TIL_STD_WRAP_H_
2 #define TIL_STD_WRAP_H_
3 
4 // includes from STL
5 #include <algorithm>
6 
7 // includes from BOOST
8 #include "boost/call_traits.hpp"
9 
10 // includes from TIL
11 #include "til/basic_range.h"
12 #include "til/ext_declarations.h"
13 #include "til/traits.h"
14 
16 // I think it is important to pass objects rather than iterators to these functions.
17 // I mean, from what I understand, the reasons why STL is passing iterators around is for technical
18 // reasons (and I mean technical ease, here) -- one of them being compatibility with C-style
19 // arrays, others being I think const and reference type attribute headache.
20 
21 // Okay, actually it's more suble: the iterator can contain part of the algorithm itself,
22 // e.g. reverse or insert or whatever. Such iterators actually extends the power of the
23 // algorithm to degrees the algorithm is not even aware of. That could be taken care of
24 // here by using extra template arguments reflecting the iterator types to use in the algo.
25 
26 // The pb is that iterators generally know almost nothing about the objects they are pointing to.
27 // STL iterators are quite plain and thus manipulating iterators is okay. But when we try to do
28 // more complicated stuff, like compressed arrays, this hurts.
29 // I'm perfectly aware that precisely, compressed arrays and stuff should rather not be STL compliant,
30 // because if they were, it would be too easy to misuse them.
31 // Still: if we want to have a function that is generic and would accept both, we need these functions.
32 
33 namespace til
34 {
36  template < typename TContainer >
37  inline
38  //typename boost::enable_if<til::is_container<TContainer>, std::size_t>::type
39  std::size_t
40  size(const TContainer &c)
41  {
42  return c.size();
43  }
44 
46  template < typename TContainer >
47  inline void fill(TContainer & c, typename boost::call_traits<typename TContainer::value_type>::param_type value)
48  {
49  std::fill(c.begin(), c.end(), value);
50  }
51 
52  // Commented out because I think that's already the case
53  /*
55  template<class T, std::size_t N>
56  bool operator<(const boost::array<T,N> & x, const boost::array<T,N> & y)
57  {
58  return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
59  }
60  */
61 
62 
63  //------------------------------------------------------------------------------
64 
65 
66  // range for std::vector
67  template < typename T, typename TAlloc >
68  struct range_of<std::vector<T,TAlloc> >
70  template < typename T, typename TAlloc >
71  struct const_range_of<std::vector<T,TAlloc> >
73 
74  template < typename T, typename TAlloc >
76  whole_range(std::vector<T,TAlloc> & v)
77  { return typename range_of<std::vector<T,TAlloc> >::type (v.begin(), v.end()); }
78  template < typename T, typename TAlloc >
80  whole_range(const std::vector<T,TAlloc> & v)
81  { return typename const_range_of<std::vector<T,TAlloc> >::type (v.begin(), v.end()); }
82 
83  // range for std::list
84  template < typename T, typename TAlloc >
85  struct range_of<std::list<T,TAlloc> >
87  template < typename T, typename TAlloc >
88  struct const_range_of<std::list<T,TAlloc> >
90 
91  template < typename T, typename TAlloc >
93  whole_range(std::list<T,TAlloc> & v)
94  { return typename range_of<std::list<T,TAlloc> >::type (v.begin(), v.end()); }
95  template < typename T, typename TAlloc >
97  whole_range(const std::list<T,TAlloc> & v)
98  { return typename const_range_of<std::list<T,TAlloc> >::type (v.begin(), v.end()); }
99 
100 
101 } // namespace til
102 
103 /*
105 template < typename T, std::size_t D >
106 inline
107 std::size_t
108 size(const boost::array<T,D> &) { return D; }
109 */
110 
111 #endif /*STD_WRAP_H_*/
basic_range< typename std::vector< T, TAlloc >::iterator > type
Definition: std_wrap.h:69
STL namespace.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
numeric_array< T, D > size(const Box< T, D > &box)
Return the size of a box.
Definition: boxTools.h:56
basic_range< typename std::list< T, TAlloc >::iterator > type
Definition: std_wrap.h:86
basic_range< typename std::list< T, TAlloc >::const_iterator > type
Definition: std_wrap.h:89
T::range type
Definition: traits.h:296
basic_range< typename std::vector< T, TAlloc >::const_iterator > type
Definition: std_wrap.h:72
void fill(sparse_vector< T, BaselinePolicy > &v, typename boost::call_traits< T >::param_type value)
Specialized fill for sparse_vector.
A simple range made out of a couple of iterators.
Definition: basic_range.h:18
void fill(TContainer &c, typename boost::call_traits< typename TContainer::value_type >::param_type value)
Wrapper of std::fill.
Definition: std_wrap.h:47
range_of< std::vector< T, TAlloc > >::type whole_range(std::vector< T, TAlloc > &v)
Definition: std_wrap.h:76