Commit e09a83d8 authored by Marian Triebe's avatar Marian Triebe

Add `CAF_HAS_MEMBER_TRAIT` macro

parent e47c5a49
...@@ -31,6 +31,19 @@ ...@@ -31,6 +31,19 @@
#include "caf/detail/type_list.hpp" #include "caf/detail/type_list.hpp"
#define CAF_HAS_MEMBER_TRAIT(name) \
template <class T> \
struct has_##name##_member { \
template <class U> \
static auto test(U* x) -> decltype(x->name(), std::true_type()); \
\
template <class U> \
static auto test(...) -> std::false_type; \
\
using type = decltype(test<T>(nullptr)); \
static constexpr bool value = type::value; \
}
namespace caf { namespace caf {
namespace detail { namespace detail {
...@@ -663,29 +676,8 @@ public: ...@@ -663,29 +676,8 @@ public:
static constexpr bool value = false; static constexpr bool value = false;
}; };
template <class T> CAF_HAS_MEMBER_TRAIT(size);
struct has_data_member { CAF_HAS_MEMBER_TRAIT(data);
template <class U>
static auto test(U* x) -> decltype(x->data(), std::true_type());
template <class U>
static auto test(...) -> std::false_type;
using type = decltype(test<T>(nullptr));
static constexpr bool value = type::value;
};
template <class T>
struct has_size_member {
template <class U>
static auto test(U* x) -> decltype(x->size(), std::true_type());
template <class U>
static auto test(...) -> std::false_type;
using type = decltype(test<T>(nullptr));
static constexpr bool value = type::value;
};
/// Checks whether T is convertible to either `std::function<void (T&)>` /// Checks whether T is convertible to either `std::function<void (T&)>`
/// or `std::function<void (const T&)>`. /// or `std::function<void (const T&)>`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment