libqi-api  release-2.5.3-2016-11-18
 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::has_less fails for member function pointer, gard
52  template<typename T, bool v>
54  {};
55 
56  template<typename T>
57  struct HasLessSwitch<T, false>
58  {
59  static const bool value = false;
60  };
61 
62  template<typename T> struct HasLessSwitch<T, true>
63  {
64  static const bool value = HasLess<T>::value;
65  };
66 
67  template<typename T>
68  struct HasLessGuard
69  {
70  static const bool switchVal =
71  boost::is_member_function_pointer<T>::value
72  || boost::is_function<T>::value
73  || boost::is_function<typename boost::remove_pointer<T>::type>::value
74  || boost::is_member_pointer<T>::value;
76 
77  };
78 
79 
80  template<typename T, bool b>
81  struct LessHelper
82  {};
83 
84  template<typename T>
85  struct LessHelper<T, true>
86  {
87  bool operator()(T* a, T* b) { return *a<*b;}
88  };
89 
90  template<typename T>
91  struct LessHelper<T, false>
92  {
93  bool operator()(T*a, T*b) { return a<b;}
94  };
95 
96  template<typename T>
97  struct Less: public LessHelper<T, HasLessGuard<T>::value>
98  {};
99  }
100 }
101 
102 #endif // _QITYPE_DETAIL_HASLESS_HXX_
static const bool switchVal
Definition: hasless.hxx:70
static const bool value
Definition: hasless.hxx:75
static const bool value
Definition: hasless.hxx:22