tasks_traits.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2022 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <Eigen/Core>
8 
9 #include <type_traits>
10 
13 namespace mc_tasks
14 {
15 
16 namespace details
17 {
18 
19 #define MAKE_GETTER_DETECTOR(GETTER) \
20  namespace impl \
21  { \
22  template<typename T> \
23  struct GETTER##_getter_traits \
24  { \
25  template<typename U> \
26  static constexpr std::true_type test_has(std::void_t<decltype(std::declval<U>().GETTER())> * = nullptr); \
27  template<typename U> \
28  static constexpr std::false_type test_has(...); \
29  static constexpr bool has = decltype(test_has<T>(0))::value; \
30  template<typename U> \
31  static auto test(std::void_t<decltype(std::declval<const U>().GETTER())> * = nullptr) \
32  -> decltype(std::declval<const U>().GETTER()); \
33  template<typename U> \
34  static void test(...); \
35  using type = decltype(test<T>(0)); \
36  }; \
37  } \
38  template<typename T> \
39  inline constexpr bool has_##GETTER##_getter_v = impl::GETTER##_getter_traits<T>::has; \
40  template<typename T> \
41  using GETTER##_return_t = typename impl::GETTER##_getter_traits<T>::type
42 
43 #define MAKE_SETTER_DETECTOR(SETTER) \
44  namespace impl \
45  { \
46  template<typename T> \
47  struct has_##SETTER##_setter \
48  { \
49  template<typename U> \
50  static constexpr std::true_type test( \
51  std::void_t<decltype(std::declval<U>().SETTER(std::declval<Eigen::VectorXd>()))> * = nullptr); \
52  template<typename U> \
53  static constexpr std::false_type test(...); \
54  static constexpr bool value = decltype(test<T>(0))::value; \
55  }; \
56  } \
57  template<typename T> \
58  inline constexpr bool has_##SETTER##_setter_v = impl::has_##SETTER##_setter<T>::value
59 
60 MAKE_GETTER_DETECTOR(refVel);
61 MAKE_SETTER_DETECTOR(refVel);
62 MAKE_GETTER_DETECTOR(refAccel);
63 MAKE_SETTER_DETECTOR(refAccel);
64 
65 template<typename T>
66 inline constexpr bool has_refVel_v = has_refVel_getter_v<T> && has_refVel_setter_v<T>;
67 
68 template<typename T>
69 inline constexpr bool has_refAccel_v = has_refAccel_getter_v<T> && has_refAccel_setter_v<T>;
70 
71 template<typename T>
72 inline constexpr bool always_false_v = false;
73 
74 #undef MAKE_GETTER_DETECTOR
75 #undef MAKE_SETTER_DETECTOR
76 
77 } // namespace details
78 
79 } // namespace mc_tasks
mc_tasks::details::MAKE_GETTER_DETECTOR
MAKE_GETTER_DETECTOR(refVel)
mc_tasks::details::MAKE_SETTER_DETECTOR
MAKE_SETTER_DETECTOR(refVel)
mc_tasks::details::has_refAccel_v
constexpr bool has_refAccel_v
Definition: tasks_traits.h:69
mc_tasks::details::always_false_v
constexpr bool always_false_v
Definition: tasks_traits.h:72
mc_tasks::details::has_refVel_v
constexpr bool has_refVel_v
Definition: tasks_traits.h:66
mc_tasks
Definition: StabilizerStandingState.h:11