libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hasless.hxx
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QITYPE_DETAIL_HASLESS_HXX_
8 #define _QITYPE_DETAIL_HASLESS_HXX_
9 
10 #include <boost/type_traits/has_less.hpp>
11 
12 namespace qi {
13  namespace detail {
14 
15  template<typename T>
16  struct HasLessGuard;
17 
18  // boost::has_less gives true for a vector<F> even if has_less<F> gives false
19  template<typename T>
20  struct HasLess
21  {
22  static const bool value = boost::has_less<T, T>::value;
23  };
24 
25  template<typename T>
26  struct HasLess<std::vector<T> >
27  {
28  static const bool value = HasLessGuard<T>::value;
29  };
30 
31  template<typename T>
32  struct HasLess<std::list<T> >
33  {
34  static const bool value = HasLessGuard<T>::value;
35  };
36 
37  template<typename K, typename V>
38  struct HasLess<std::map<K, V> >
39  {
40  static const bool value = HasLessGuard<K>::value
42  };
43 
44  template<typename A, typename B>
45  struct HasLess<std::pair<A, B> >
46  {
47  static const bool value = HasLessGuard<A>::value
49  };
50 
51  // boost::optional<T> has a less operator if and only if T has a less operator.
52  template<typename T>
53  struct HasLess<boost::optional<T>>
54  {
55  static const bool value = HasLessGuard<T>::value;
56  };
57 
58  //boost::has_less fails for member function pointer, gard
59  template<typename T, bool v>
61  {};
62 
63  template<typename T>
64  struct HasLessSwitch<T, false>
65  {
66  static const bool value = false;
67  };
68 
69  template<typename T> struct HasLessSwitch<T, true>
70  {
71  static const bool value = HasLess<T>::value;
72  };
73 
74  template<typename T>
75  struct HasLessGuard
76  {
77  static const bool switchVal =
78  boost::is_member_function_pointer<T>::value
79  || boost::is_function<T>::value
80  || boost::is_function<typename boost::remove_pointer<T>::type>::value
81  || boost::is_member_pointer<T>::value;
83 
84  };
85 
86 
87  template<typename T, bool hasLessGuard>
88  struct LessHelper
89  {
90  bool operator()(T* a, T* b) { return *a<*b;}
91  };
92 
93  template<typename T>
94  struct LessHelper<T, false>
95  {
96  bool operator()(T*a, T*b) { return a<b;}
97  };
98 
99  template<typename T>
100  struct Less: public LessHelper<T, HasLessGuard<T>::value>
101  {};
102  }
103 }
104 
105 #endif // _QITYPE_DETAIL_HASLESS_HXX_
static const bool switchVal
Definition: hasless.hxx:77
bool operator()(T *a, T *b)
Definition: hasless.hxx:90
static const bool value
Definition: hasless.hxx:82
static const bool value
Definition: hasless.hxx:22