libqi-api  release-2.5.3-2016-11-18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
traits.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2016 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QI_TYPE_TRAITS_HPP_
8 #define _QI_TYPE_TRAITS_HPP_
9 
10 #include <type_traits>
11 
12 namespace qi
13 {
15  namespace type
16  {
17  using True = std::true_type;
18  using False = std::false_type;
19 
20  template<typename A, typename B>
21  using Equal = typename std::is_same<A, B>::type;
22 
23  namespace detail
24  {
25  template<typename A>
26  struct RemoveCvImpl : std::remove_cv<A>
27  {
28  };
29 
30  template<typename Ret, typename C, typename... Arg>
31  struct RemoveCvImpl<Ret (C::*)(Arg...) const>
32  {
33  using type = Ret (C::*)(Arg...);
34  };
35 
36  template<typename Ret, typename C, typename... Arg>
37  struct RemoveCvImpl<Ret (C::*)(Arg...) volatile>
38  {
39  using type = Ret (C::*)(Arg...);
40  };
41 
42  template<typename Ret, typename C, typename... Arg>
43  struct RemoveCvImpl<Ret (C::*)(Arg...) const volatile>
44  {
45  using type = Ret (C::*)(Arg...);
46  };
47  } // namespace detail
48 
51  template<typename A>
53 
55  template<typename A>
56  using RemoveRef = typename std::remove_reference<A>::type;
57 
60  template<typename A>
62 
63  namespace detail
64  {
65  template<typename A>
67  {
68  template<typename B>
69  static True test(decltype(&B::operator(), 0));
70 
71  template<typename>
72  static False test(...);
73 
74  using type = decltype(test<A>(0));
75  };
76  } // namespace detail
77 
78  template<typename A>
80 
81  namespace detail
82  {
83  template<typename A>
85  {
86  };
87  }
88 
91  template<typename A>
93 
94  namespace detail
95  {
96  template<typename A>
98 
99  template<typename Ret, typename C, typename... Arg>
100  struct FunctionImplFunctionObject<Ret (C::*)(Arg...)>
101  {
102  // A typedef is used here instead of a using because of a VS 2013 bug.
103  // TODO: Replace it by a using when moving to VS 2015.
104  typedef Ret (type)(Arg...);
105  };
106 
107  template<typename A>
108  struct FunctionImpl : FunctionImplFunctionObject<RemoveCv<decltype(&A::operator())>>
109  {
110  };
111 
112  template<typename Ret, typename... Arg>
113  struct FunctionImpl<Ret (Arg...)>
114  {
115  // A typedef is used here instead of a using because of a VS 2013 bug.
116  // TODO: Replace it by a using when moving to VS 2015.
117  typedef Ret (type)(Arg...);
118  };
119 
120  template<typename Ret, typename... Arg>
121  struct FunctionImpl<Ret (*)(Arg...)>
122  {
123  // A typedef is used here instead of a using because of a VS 2013 bug.
124  // TODO: Replace it by a using when moving to VS 2015.
125  typedef Ret (type)(Arg...);
126  };
127  } // namespace detail
128 
132  template<typename A>
134 
135  } // namespace type
136 } // namespace qi
137 
138 #endif // _QITYPE_TYPETRAITS_HPP_
typename std::is_same< A, B >::type Equal
Definition: traits.hpp:21
static True test(decltype(&B::operator(), 0))
std::false_type False
Definition: traits.hpp:18
std::true_type True
Definition: traits.hpp:17
typename detail::IsFunctionObjectImpl< A >::type IsFunctionObject
Definition: traits.hpp:92
typename detail::FunctionImpl< A >::type Function
Definition: traits.hpp:133
typename std::remove_reference< A >::type RemoveRef
Remove reference (normal reference and r-value reference).
Definition: traits.hpp:56
RemoveCv< RemoveRef< A >> RemoveCvRef
Definition: traits.hpp:61
typename detail::HasMemberOperatorCallImpl< A >::type HasMemberOperatorCall
Definition: traits.hpp:79
typename detail::RemoveCvImpl< A >::type RemoveCv
Definition: traits.hpp:52