mirror of https://github.com/oxen-io/lokinet
Delete llarp::util::memFn
It's unnecessary abstraction that barely simplifies anything, and is now only used in one single place anyway, which is easily replaced with a (unabstracted) lambda.pull/2216/head
parent
32395caec1
commit
1ca852d2f5
@ -1,72 +0,0 @@
|
||||
#ifndef LLARP_UTIL_MEMFN
|
||||
#define LLARP_UTIL_MEMFN
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp::util
|
||||
{
|
||||
// Wraps a member function and instance into a callable object that invokes
|
||||
// the method (non-const overload).
|
||||
template <
|
||||
typename Return,
|
||||
typename Class,
|
||||
typename Derived,
|
||||
typename... Arg,
|
||||
typename = std::enable_if_t<std::is_base_of<Class, Derived>::value>>
|
||||
auto
|
||||
memFn(Return (Class::*f)(Arg...), Derived* self)
|
||||
{
|
||||
return [f, self](Arg... args) -> Return { return (self->*f)(std::forward<Arg>(args)...); };
|
||||
}
|
||||
|
||||
// Wraps a member function and instance into a lambda that invokes the
|
||||
// method (const overload).
|
||||
template <
|
||||
typename Return,
|
||||
typename Class,
|
||||
typename Derived,
|
||||
typename... Arg,
|
||||
typename = std::enable_if_t<std::is_base_of<Class, Derived>::value>>
|
||||
auto
|
||||
memFn(Return (Class::*f)(Arg...) const, const Derived* self)
|
||||
{
|
||||
return [f, self](Arg... args) -> Return { return (self->*f)(std::forward<Arg>(args)...); };
|
||||
}
|
||||
|
||||
// Wraps a member function and shared pointer to an instance into a lambda
|
||||
// that invokes the method.
|
||||
template <
|
||||
typename Return,
|
||||
typename Class,
|
||||
typename Derived,
|
||||
typename... Arg,
|
||||
typename = std::enable_if_t<std::is_base_of<Class, Derived>::value>>
|
||||
auto
|
||||
memFn(Return (Class::*f)(Arg...), std::shared_ptr<Derived> self)
|
||||
{
|
||||
return [f, self = std::move(self)](Arg... args) -> Return {
|
||||
return (self.get()->*f)(std::forward<Arg>(args)...);
|
||||
};
|
||||
}
|
||||
|
||||
// Wraps a member function and shared pointer to an instance into a lambda
|
||||
// that invokes the method (const method overload).
|
||||
template <
|
||||
typename Return,
|
||||
typename Class,
|
||||
typename Derived,
|
||||
typename... Arg,
|
||||
typename = std::enable_if_t<std::is_base_of<Class, Derived>::value>>
|
||||
auto
|
||||
memFn(Return (Class::*f)(Arg...) const, std::shared_ptr<Derived> self)
|
||||
{
|
||||
return [f, self = std::move(self)](Arg... args) -> Return {
|
||||
return (self.get()->*f)(std::forward<Arg>(args)...);
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace llarp::util
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue