Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
spatial_builtin.hpp
1 // -*- C++ -*-
2 //
3 // Copyright Sylvain Bougerel 2009 - 2013.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file COPYING or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
14 #ifndef SPATIAL_COMPARE_BUILTIN_HPP
15 #define SPATIAL_COMPARE_BUILTIN_HPP
16 
17 #include "spatial_import_type_traits.hpp"
18 #include "spatial_check_concept.hpp"
19 
20 namespace spatial
21 {
22  // Forward declarations for builtin compartors and difference
23  template<typename Accessor, typename Tp, typename Unit> struct accessor_minus;
24  template<typename Tp, typename Unit> struct bracket_minus;
25  template<typename Tp, typename Unit> struct paren_minus;
26  template<typename Tp, typename Unit> struct iterator_minus;
27  template<typename Accessor, typename Tp> struct accessor_less;
28  template<typename Tp> struct bracket_less;
29  template<typename Tp> struct paren_less;
30  template<typename Tp> struct iterator_less;
31 
32  namespace details
33  {
38  template <typename>
40  struct is_compare_builtin_helper : import::false_type { };
41  template <typename Tp>
43  : import::true_type { };
44  template <typename Tp>
46  : import::true_type { };
47  template <typename Tp>
49  : import::true_type { };
50  template <typename Accessor, typename Tp>
52  : import::true_type { };
54 
60  template <typename Ct>
62  : is_compare_builtin_helper<typename container_traits<Ct>::key_compare>
63  { };
64 
69  template<typename Container, typename Enable = void>
70  struct with_builtin_difference { }; // sink for not using built-in compare
71 
87  template<typename Container>
89  <Container,
90  typename enable_if<is_compare_builtin<Container> >::type>
91  {
102  template<typename>
104  struct builtin_difference { }; // sink type, never used normally
105 
106  template<typename Key>
107  struct builtin_difference<bracket_less<Key> >
108  {
110  type operator() (const bracket_less<Key>&) const
111  { return type(); }
112  };
113 
114  template<typename Key>
115  struct builtin_difference<paren_less<Key> >
116  {
118  type operator() (const paren_less<Key>&) const
119  { return type(); }
120  };
121 
122  template<typename Key>
123  struct builtin_difference<iterator_less<Key> >
124  {
126  type operator() (const iterator_less<Key>&) const
127  { return type(); }
128  };
129 
130  template<typename Key, typename Accessor>
131  struct builtin_difference<accessor_less<Accessor, Key> >
132  {
134  type operator() (const accessor_less<Accessor, Key>& cmp) const
135  { return type(cmp.accessor()); }
136  };
138 
139  typedef typename builtin_difference
141 
144  type operator()(const Container& container) const
145  {
146  return builtin_difference
148  (container.key_comp());
149  }
150  };
151 
161  template <typename>
162  struct is_difference_builtin : import::false_type { };
163  template <typename Tp, typename Unit>
165  : import::true_type { };
166  template <typename Tp, typename Unit>
168  : import::true_type { };
169  template <typename Tp, typename Unit>
171  : import::true_type { };
172  template <typename Accessor, typename Tp, typename Unit>
173  struct is_difference_builtin<accessor_minus<Accessor, Tp, Unit> >
174  : import::true_type { };
212  template <typename Diff, typename DistanceType>
214  { typedef Diff type; }; // sink type
215 
221  template <typename Tp, typename Unit, typename DistanceType>
222  struct rebind_builtin_difference<bracket_minus<Tp, Unit>, DistanceType>
224 
230  template <typename Tp, typename Unit, typename DistanceType>
231  struct rebind_builtin_difference<paren_minus<Tp, Unit>, DistanceType>
233 
239  template <typename Tp, typename Unit, typename DistanceType>
240  struct rebind_builtin_difference<iterator_minus<Tp, Unit>, DistanceType>
242 
248  template <typename Accessor, typename Tp, typename Unit,
249  typename DistanceType>
250  struct rebind_builtin_difference<accessor_minus<Accessor, Tp, Unit>,
251  DistanceType>
253  }
254 }
255 
256 #endif // SPATIAL_COMPARE_BUILTIN_HPP
Help to resolve whether the type used is a builtin comparator or not.
A comparator that simplifies using the spatial containers with a Key type that has coordiates accessi...
Statically resolve if key_compare used in the container corresponds to one of the builtin library com...
A comparator that simplifies using the spatial containers with a Key type that has coordinate that ar...
This functor uses the minus operator to calculate the difference between 2 elements of Tp along the d...
This functor uses the minus operator to calculate the difference between 2 elements of Tp along the d...
Tp::key_compare key_compare
Comparison functor used to compare two instances of key_type.
Definition: traits.hpp:98
A comparator that simplifies using the spatial containers with a Key type that has coordiates accessi...
A comparator that simplifies using the spatial containers with a Key type that has coordiates accessi...
This functor uses the minus operator to calculate the difference between 2 elements of Tp along the d...
Help to resolve whether the type used is a builtin difference or not.
If Diff is a builtin difference type, change the current unit of Diff to the DistanceType specified i...
const Accessor & accessor() const
Definition: function.hpp:152
The main namespace used in the library.
Definition: algorithm.hpp:23
This functor uses the minus operator to calculate the difference between 2 elements of Tp along the d...
type operator()(const Container &container) const
Constructs the difference type from the built-in container's key compare operator.
The generic helper class to determine if a container uses a built-in compare type.