util/BindMethod: simplify BindMethod()
This commit is contained in:

committed by
Max Kellermann

parent
0ed24f3a05
commit
8dca602346
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* 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 @@
|
|||||||
* 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
|
|||||||
/**
|
/**
|
||||||
* 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
|
|||||||
* 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
|
|||||||
*/
|
*/
|
||||||
#define BIND_FUNCTION(function) \
|
#define BIND_FUNCTION(function) \
|
||||||
BindFunction<typename BindMethodDetail::FunctionTraits<decltype(function)>, &function>()
|
BindFunction<typename BindMethodDetail::FunctionTraits<decltype(function)>, &function>()
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Reference in New Issue
Block a user