Commit 8dca6023 authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

util/BindMethod: simplify BindMethod()

parent 0ed24f3a
/* /*
* Copyright 2016-2018 Max Kellermann <max.kellermann@gmail.com> * Copyright 2016-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef BIND_METHOD_HXX #pragma once
#define BIND_METHOD_HXX
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
...@@ -247,18 +246,20 @@ MakeBindFunctionWrapper() noexcept ...@@ -247,18 +246,20 @@ MakeBindFunctionWrapper() noexcept
/** /**
* Construct a #BoundMethod instance. * Construct a #BoundMethod instance.
* *
* @param T the containing class
* @param S the plain function signature type
* @param method the method pointer * @param method the method pointer
* @param instance the instance of #T to be bound * @param instance the instance of #T to be bound
*/ */
template<typename T, typename S, template<auto method>
typename BindMethodDetail::MethodWithSignature<T, S>::method_pointer method> constexpr auto
constexpr BoundMethod<S> BindMethod(typename BindMethodDetail::MethodSignatureHelper<decltype(method)>::class_type &instance) noexcept
BindMethod(T &_instance) noexcept
{ {
return BoundMethod<S>(&_instance, using H = BindMethodDetail::MethodSignatureHelper<decltype(method)>;
BindMethodDetail::MakeBindMethodWrapper<T, S, method>()); using class_type = typename H::class_type;
using plain_signature = typename H::plain_signature;
return BoundMethod<plain_signature>{
&instance,
BindMethodDetail::MakeBindMethodWrapper<class_type, plain_signature, method>(),
};
} }
/** /**
...@@ -266,9 +267,7 @@ BindMethod(T &_instance) noexcept ...@@ -266,9 +267,7 @@ BindMethod(T &_instance) noexcept
* constructs a #BoundMethod instance. * constructs a #BoundMethod instance.
*/ */
#define BIND_METHOD(instance, method) \ #define BIND_METHOD(instance, method) \
BindMethod<typename BindMethodDetail::MethodSignatureHelper<decltype(method)>::class_type, \ BindMethod<method>(instance)
typename BindMethodDetail::MethodSignatureHelper<decltype(method)>::plain_signature, \
method>(instance)
/** /**
* Shortcut wrapper for BIND_METHOD() which assumes "*this" is the * Shortcut wrapper for BIND_METHOD() which assumes "*this" is the
...@@ -296,5 +295,3 @@ BindFunction() noexcept ...@@ -296,5 +295,3 @@ BindFunction() noexcept
*/ */
#define BIND_FUNCTION(function) \ #define BIND_FUNCTION(function) \
BindFunction<typename BindMethodDetail::FunctionTraits<decltype(function)>, &function>() BindFunction<typename BindMethodDetail::FunctionTraits<decltype(function)>, &function>()
#endif
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