77 static constexpr decltype(
auto)
call(U&&...args);
91 constexpr decltype(
auto)
operator() (U&&...)
const;
182template<
class StaticCaller,
class Functor>
183class fallback_caller {
190 template<
class Dummy,
class...T>
191 constexpr auto forward(Dummy*, T&&...args)
const
192 ->
decltype(m_functor(std::forward<T>(args)...))
194 return m_functor(std::forward<T>(args)...);
197 template<
class Dummy,
class...T>
198 constexpr decltype(
auto) forward(Dummy, T&&...args)
const {
204 constexpr fallback_caller(
const Functor& f) : m_functor(f) {}
205 constexpr fallback_caller(Functor&& f) : m_functor(std::move(f)) {}
207 fallback_caller(fallback_caller&&) =
default;
208 fallback_caller(
const fallback_caller&) =
delete;
211 constexpr decltype(
auto)
call(T&&...args)
const {
212 if constexpr ( StaticCaller::template
is_matched_v<T...> ) {
213 return StaticCaller::call(std::forward<T>(args)...);
215 auto dummy = (
int*)
nullptr;
216 return forward(dummy, std::forward<T>(args)...);
221 constexpr decltype(
auto)
operator()(T&&...args)
const {
222 return call(std::forward<T>(args)...);
280#define UGMISC_NAMED_MEMBER_TYPE_TEST(TEMPLATENAME, ALIASNAME, HASMEMBERNAME, NAME) template<class TYPE, class DEFAULTTYPE = void> \
281 class TEMPLATENAME { \
282 template<class...> struct get_defined_type; \
284 template<class V, class T, class...Ts> struct get_defined_type<V, T, Ts...> { \
285 static constexpr bool has_member = get_defined_type<void, Ts...>::has_member; \
286 using type = typename get_defined_type<void, Ts...>::type; \
289 template<class T, class...Ts> struct get_defined_type<std::void_t<typename T::NAME>, T, Ts...> { \
290 static constexpr bool has_member = true; \
291 using type = typename T::NAME; \
294 template<class V> struct get_defined_type<V> { \
295 static constexpr bool has_member = false; \
296 using type = DEFAULTTYPE; \
299 using tlist = ::ugmisc::flatten_t<void, TYPE>; \
300 using dt = typename tlist::template apply<get_defined_type>; \
303 using type = typename dt::type; \
304 static constexpr bool has_member = dt::has_member; \
307 template<class T, class D=void> \
308 using ALIASNAME = typename TEMPLATENAME<T, D>::type; \
310 template<class...T> \
311 static constexpr bool HASMEMBERNAME = TEMPLATENAME<::ugmisc::type_list<T...>>::has_member
343#define UGMISC_MEMBER_TYPE_TEST(NAME) \
344 UGMISC_NAMED_MEMBER_TYPE_TEST(member_type_test_##NAME, member_type_##NAME, has_member_type_##NAME, NAME)
350#define UGMISC__MEMBER_CALLER_TYPE_NAME(TNAME) _ugmisc_caller_##TNAME
360#define UGMISC__DECL_MEMBER_CALLER_TYPE(TNAME, NAME) \
361struct UGMISC__MEMBER_CALLER_TYPE_NAME(TNAME) { \
363 template<class T, class, class...A> \
365 static constexpr bool is_callable = false; \
368 template<class T, class...A> \
369 struct caller<T, std::void_t<decltype(T::NAME(std::declval<A>()...))>, A...> { \
370 static constexpr bool is_callable = true; \
372 static constexpr decltype(auto) call(A...args) { \
373 return T::NAME(std::forward<A>(args)...); \
382template<
class Caller,
class T,
class...A>
383inline constexpr bool is_callable_v =
384 Caller::template caller<T, void, A...>::is_callable;
387template<
class Caller,
class T,
class...A>
388constexpr bool is_callable(A&&...) {
389 return is_callable_v<Caller, T, A...>;
399template<
class Caller,
class...T>
401 template<
class V,
class List,
class...Args>
403 :
public caller<V, type_list_remove_prefix<1, List>, Args...> {
406 template<
class...Args>
struct caller<void, type_list<>, Args...> {
407 static constexpr bool is_callable =
false;
410 template<
class List,
class...Args>
412 std::enable_if_t< is_callable_v<Caller, type_list_member<0, List>, Args...>>,
417 static constexpr bool is_callable =
true;
418 using type = type_list_member<0, List>;
421 using types_list = flatten_t<T...>;
424 template<
class...Args>
425 static constexpr bool is_matched_v =
426 caller<void, types_list, Args...>::is_callable;
428 template<
class...Args>
429 static constexpr bool is_matched(Args&&...) {
430 return is_matched_v<Args...>;
433 template<
class...Args>
434 using matched_type =
typename caller<void, types_list, Args...>::type;
436 template<
class...Args>
437 static constexpr decltype(
auto) call(Args&&...args) {
439 is_matched_v<Args...>,
440 "None of the types is callable with these argument types."
442 return Caller::template caller<matched_type<Args...>, void, Args...>
443 ::call(std::forward<Args>(args)...);
446 template<
class...Args>
447 constexpr decltype(
auto)
operator()(Args&&...args)
const {
448 return call(std::forward<Args>(args)...);
453 fallback_caller<chain_caller, std::remove_reference_t<F>>
454 fallback(F&& functor) {
455 return std::forward<F>(functor);
458 template<
class...Args>
459 static matched_type<Args...> declval_matched(Args&&...)
noexcept;
509#define UGMISC_NAMED_MEMBER_STATIC_METHOD_CALL(TEMPLATENAME, NAME) \
510 UGMISC__DECL_MEMBER_CALLER_TYPE(TEMPLATENAME, NAME); \
511 template<class...T> class TEMPLATENAME \
512 : public ::ugmisc::member_::chain_caller< \
513 UGMISC__MEMBER_CALLER_TYPE_NAME(TEMPLATENAME), \
517 static constexpr const char *template_name = #TEMPLATENAME; \
518 static constexpr const char *function_name = #NAME; \
529#define UGMISC_MEMBER_STATIC_METHOD_CALL(NAME) \
530 UGMISC_NAMED_MEMBER_STATIC_METHOD_CALL(member_call_##NAME, NAME)
static constexpr decltype(auto) call(U &&...args)
static constexpr auto fallback(F &&functor)
??? matched_type
Definition member.hpp:132
static matched_type< U... > declval_matched(U &&...) noexcept
static constexpr bool is_matched(U &&...)
static constexpr bool is_matched_v
Definition member.hpp:139
Lists of types which may be used in some of the ugmisc templates where a single type would usually be...