Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
Classes | Namespaces | Macros
sfinae_utils.h File Reference
#include <tesseract_common/macros.h>
#include <type_traits>
#include <array>
Include dependency graph for sfinae_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tesseract_common::ambiguate< Args >
 
struct  tesseract_common::got_type< A, typename >
 
struct  tesseract_common::got_type< A >
 
struct  tesseract_common::sig_check< T, T >
 
struct  tesseract_common::has_member< Alias, AmbiguitySeed >
 

Namespaces

namespace  tesseract_common
 

Macros

#define CREATE_MEMBER_CHECK(member)
 Check for member x in a given class. Could be var, func, class, union, or enum: More...
 
#define CREATE_MEMBER_FUNC_INVOCABLE_CHECK(func_name, ...)
 Check if a member function is invocable with the provided input types. More...
 
#define CREATE_MEMBER_FUNC_RETURN_TYPE_CHECK(func_name, return_type, ...)
 Check if a member function has a given return type with input parameters. More...
 
#define CREATE_MEMBER_FUNC_RETURN_TYPE_NOARGS_CHECK(func_name, return_type)
 Check if a member function has a given return type that takes no arguments. More...
 
#define CREATE_MEMBER_FUNC_SIGNATURE_CHECK(func_name, return_type, ...)
 Check if a member function has a given return type. More...
 
#define CREATE_MEMBER_FUNC_SIGNATURE_NOARGS_CHECK(func_name, return_type)
 Check if a member function has a given return type that takes no arguments. More...
 

Macro Definition Documentation

◆ CREATE_MEMBER_CHECK

#define CREATE_MEMBER_CHECK (   member)
Value:
\
template <typename T, typename = std::true_type> \
struct Alias_##member; \
\
template <typename T> \
struct Alias_##member<T, std::integral_constant<bool, tesseract_common::got_type<decltype(&T::member)>::value>> \
{ \
static const decltype(&T::member) value; \
}; \
\
struct AmbiguitySeed_##member \
{ \
char member; /* NOLINT */ \
}; \
\
template <typename T> \
struct has_member_##member \
{ \
static const bool value = \
Alias_##member<AmbiguitySeed_##member>>::value; \
}
Definition: polygon_mesh.h:46
Definition: sfinae_utils.h:45
object value
Definition: tesseract_common_serialization_unit.cpp:495

Check for member x in a given class. Could be var, func, class, union, or enum:

CREATE_MEMBER_CHECK(x); bool has_x = has_member_x<class_to_check_for_x>::value;

Note
Also useful to add static assert in constructor to provide useful message static_assert(has_member_x<class_to_check_for_x>::value, "Class does not have member function 'x'");

◆ CREATE_MEMBER_FUNC_INVOCABLE_CHECK

#define CREATE_MEMBER_FUNC_INVOCABLE_CHECK (   func_name,
  ... 
)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_func_invocable_##func_name : std::false_type \
{ \
}; \
\
template <typename T> \
struct has_member_func_invocable_##func_name< \
T, \
std::integral_constant<bool, std::is_invocable<decltype(&T::func_name), T, __VA_ARGS__>::value>> \
: std::true_type \
{ \
};

Check if a member function is invocable with the provided input types.

Check if the class has a function named add which takes two double as arguments CREATE_MEMBER_FUNC_INVOCABLE_CHECK(add, double, double) bool has_add_invocable = has_member_func_invocable_add<class_to_check_for_add_invocable>::value;

◆ CREATE_MEMBER_FUNC_RETURN_TYPE_CHECK

#define CREATE_MEMBER_FUNC_RETURN_TYPE_CHECK (   func_name,
  return_type,
  ... 
)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_func_return_type_##func_name : std::false_type \
{ \
}; \
\
template <typename T> \
struct has_member_func_return_type_##func_name< \
T, \
std::integral_constant<bool, \
std::is_same<typename std::invoke_result<decltype(&T::func_name), T, __VA_ARGS__>::type, \
return_type>::value>> : std::true_type \
{ \
};

Check if a member function has a given return type with input parameters.

Check if the class has a function named add with return type followed function parameters CREATE_MEMBER_FUNC_RETURN_TYPE_CHECK(add, double, double, double) bool has_add_return_type = has_member_func_return_type_add<class_to_check_for_add_return_type>::value;

◆ CREATE_MEMBER_FUNC_RETURN_TYPE_NOARGS_CHECK

#define CREATE_MEMBER_FUNC_RETURN_TYPE_NOARGS_CHECK (   func_name,
  return_type 
)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_func_return_type_##func_name : std::false_type \
{ \
}; \
\
template <typename T> \
struct has_member_func_return_type_##func_name< \
T, \
std::integral_constant< \
bool, \
std::is_same<typename std::invoke_result<decltype(&T::func_name), T>::type, return_type>::value>> \
: std::true_type \
{ \
};

Check if a member function has a given return type that takes no arguments.

Check if the class has a function named add with return type CREATE_MEMBER_FUNC_RETURN_TYPE_NOARGS_CHECK(update, bool) bool has_update_return_type = has_member_func_return_type_update<class_to_check_for_update_return_type>::value;

◆ CREATE_MEMBER_FUNC_SIGNATURE_CHECK

#define CREATE_MEMBER_FUNC_SIGNATURE_CHECK (   func_name,
  return_type,
  ... 
)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_func_signature_##func_name : std::false_type \
{ \
}; \
\
template <typename T> \
struct has_member_func_signature_##func_name< \
T, \
std::integral_constant< \
bool, \
std::is_invocable<decltype(&T::func_name), T, __VA_ARGS__>::value && \
std::is_same<typename std::invoke_result<decltype(&T::func_name), T, __VA_ARGS__>::type, \
return_type>::value>> : std::true_type \
{ \
};

Check if a member function has a given return type.

Check if the class has a function named add with return type followed function parameters CREATE_MEMBER_FUNC_SIGNATURE_CHECK(add, double, double, double) bool has_add_signature = has_member_func_signature_add<class_to_check_for_add_signature>::value;

◆ CREATE_MEMBER_FUNC_SIGNATURE_NOARGS_CHECK

#define CREATE_MEMBER_FUNC_SIGNATURE_NOARGS_CHECK (   func_name,
  return_type 
)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_func_signature_##func_name : std::false_type \
{ \
}; \
\
template <typename T> \
struct has_member_func_signature_##func_name< \
T, \
std::integral_constant< \
bool, \
std::is_invocable<decltype(&T::func_name), T>::value && \
std::is_same<typename std::invoke_result<decltype(&T::func_name), T>::type, return_type>::value>> \
: std::true_type \
{ \
};

Check if a member function has a given return type that takes no arguments.

Check if the class has a function named add with return type CREATE_MEMBER_FUNC_SIGNATURE_NOARGS_CHECK(add, double) bool has_add_signature = has_member_func_signature_add<class_to_check_for_add_signature>::value;