74 static constexpr decltype(
auto)
call(U&&...args);
88 constexpr decltype(
auto)
operator() (U&&...)
const;
179template<
class StaticCaller,
class Functor>
180class fallback_caller {
187 template<
class Dummy,
class...T>
188 constexpr auto forward(Dummy*, T&&...args)
const
189 ->
decltype(m_functor(std::forward<T>(args)...))
191 return m_functor(std::forward<T>(args)...);
194 template<
class Dummy,
class...T>
195 constexpr decltype(
auto) forward(Dummy, T&&...args)
const {
201 constexpr fallback_caller(
const Functor& f) : m_functor(f) {}
202 constexpr fallback_caller(Functor&& f) : m_functor(std::move(f)) {}
204 fallback_caller(fallback_caller&&) =
default;
205 fallback_caller(
const fallback_caller&) =
delete;
208 constexpr decltype(
auto)
call(T&&...args)
const {
209 if constexpr ( StaticCaller::template
is_matched_v<T...> ) {
210 return StaticCaller::call(std::forward<T>(args)...);
212 auto dummy = (
int*)
nullptr;
213 return forward(dummy, std::forward<T>(args)...);
218 constexpr decltype(
auto)
operator()(T&&...args)
const {
219 return call(std::forward<T>(args)...);
277#define UGMISC_NAMED_MEMBER_TYPE_TEST(TEMPLATENAME, ALIASNAME, HASMEMBERNAME, NAME) template<class TYPE, class DEFAULTTYPE = void> \
278 class TEMPLATENAME { \
279 template<class...> struct get_defined_type; \
281 template<class V, class T, class...Ts> struct get_defined_type<V, T, Ts...> { \
282 static constexpr bool has_member = get_defined_type<void, Ts...>::has_member; \
283 using type = typename get_defined_type<void, Ts...>::type; \
286 template<class T, class...Ts> struct get_defined_type<std::void_t<typename T::NAME>, T, Ts...> { \
287 static constexpr bool has_member = true; \
288 using type = typename T::NAME; \
291 template<class V> struct get_defined_type<V> { \
292 static constexpr bool has_member = false; \
293 using type = DEFAULTTYPE; \
296 using tlist = ::ugmisc::flatten_t<void, TYPE>; \
297 using dt = typename tlist::template apply<get_defined_type>; \
300 using type = typename dt::type; \
301 static constexpr bool has_member = dt::has_member; \
304 template<class T, class D=void> \
305 using ALIASNAME = typename TEMPLATENAME<T, D>::type; \
307 template<class...T> \
308 static constexpr bool HASMEMBERNAME = TEMPLATENAME<::ugmisc::type_list<T...>>::has_member
340#define UGMISC_MEMBER_TYPE_TEST(NAME) \
341 UGMISC_NAMED_MEMBER_TYPE_TEST(member_type_test_##NAME, member_type_##NAME, has_member_type_##NAME, NAME)
347#define UGMISC__MEMBER_CALLER_TYPE_NAME(TNAME) _ugmisc_caller_##TNAME
357#define UGMISC__DECL_MEMBER_CALLER_TYPE(TNAME, NAME) \
358struct UGMISC__MEMBER_CALLER_TYPE_NAME(TNAME) { \
360 template<class T, class, class...A> \
362 static constexpr bool is_callable = false; \
365 template<class T, class...A> \
366 struct caller<T, std::void_t<decltype(T::NAME(std::declval<A>()...))>, A...> { \
367 static constexpr bool is_callable = true; \
369 static constexpr decltype(auto) call(A...args) { \
370 return T::NAME(std::forward<A>(args)...); \
379template<
class Caller,
class T,
class...A>
380inline constexpr bool is_callable_v =
381 Caller::template caller<T, void, A...>::is_callable;
384template<
class Caller,
class T,
class...A>
385constexpr bool is_callable(A&&...) {
386 return is_callable_v<Caller, T, A...>;
396template<
class Caller,
class...T>
398 template<
class V,
class List,
class...Args>
400 :
public caller<V, type_list_remove_prefix<1, List>, Args...> {
403 template<
class...Args>
struct caller<void, type_list<>, Args...> {
404 static constexpr bool is_callable =
false;
407 template<
class List,
class...Args>
409 std::enable_if_t< is_callable_v<Caller, type_list_member<0, List>, Args...>>,
414 static constexpr bool is_callable =
true;
415 using type = type_list_member<0, List>;
418 using types_list = flatten_t<T...>;
421 template<
class...Args>
422 static constexpr bool is_matched_v =
423 caller<void, types_list, Args...>::is_callable;
425 template<
class...Args>
426 static constexpr bool is_matched(Args&&...) {
427 return is_matched_v<Args...>;
430 template<
class...Args>
431 using matched_type =
typename caller<void, types_list, Args...>::type;
433 template<
class...Args>
434 static constexpr decltype(
auto) call(Args&&...args) {
436 is_matched_v<Args...>,
437 "None of the types is callable with these argument types."
439 return Caller::template caller<matched_type<Args...>, void, Args...>
440 ::call(std::forward<Args>(args)...);
443 template<
class...Args>
444 constexpr decltype(
auto)
operator()(Args&&...args)
const {
445 return call(std::forward<Args>(args)...);
450 fallback_caller<chain_caller, std::remove_reference_t<F>>
451 fallback(F&& functor) {
452 return std::forward<F>(functor);
455 template<
class...Args>
456 static matched_type<Args...> declval_matched(Args&&...)
noexcept;
506#define UGMISC_NAMED_MEMBER_STATIC_METHOD_CALL(TEMPLATENAME, NAME) \
507 UGMISC__DECL_MEMBER_CALLER_TYPE(TEMPLATENAME, NAME); \
508 template<class...T> class TEMPLATENAME \
509 : public ::ugmisc::member_::chain_caller< \
510 UGMISC__MEMBER_CALLER_TYPE_NAME(TEMPLATENAME), \
514 static constexpr const char *template_name = #TEMPLATENAME; \
515 static constexpr const char *function_name = #NAME; \
526#define UGMISC_MEMBER_STATIC_METHOD_CALL(NAME) \
527 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:129
static matched_type< U... > declval_matched(U &&...) noexcept
static constexpr bool is_matched(U &&...)
static constexpr bool is_matched_v
Definition member.hpp:136
Lists of types which may be used in some of the ugmisc templates where a single type would usually be...