From 1c1a76d6d738c79de62aea1471760f05f8b9ef5e Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 13 Oct 2024 21:57:54 +0300 Subject: [PATCH] BAN: Member function pointers now use references instead of pointers This seems cleaner as class pointer cannot be null anymore --- BAN/include/BAN/Function.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/BAN/include/BAN/Function.h b/BAN/include/BAN/Function.h index a01bd370..94068720 100644 --- a/BAN/include/BAN/Function.h +++ b/BAN/include/BAN/Function.h @@ -20,13 +20,13 @@ namespace BAN new (m_storage) CallablePointer(function); } template - Function(Ret(Own::*function)(Args...), Own* owner) + Function(Ret(Own::*function)(Args...), Own& owner) { static_assert(sizeof(CallableMember) <= m_size); new (m_storage) CallableMember(function, owner); } template - Function(Ret(Own::*function)(Args...) const, const Own* owner) + Function(Ret(Own::*function)(Args...) const, const Own& owner) { static_assert(sizeof(CallableMemberConst) <= m_size); new (m_storage) CallableMemberConst(function, owner); @@ -91,36 +91,36 @@ namespace BAN template struct CallableMember : public CallableBase { - CallableMember(Ret(Own::*function)(Args...), Own* owner) + CallableMember(Ret(Own::*function)(Args...), Own& owner) : m_owner(owner) , m_function(function) { } virtual Ret call(Args... args) const override { - return (m_owner->*m_function)(forward(args)...); + return (m_owner.*m_function)(forward(args)...); } private: - Own* m_owner = nullptr; + Own& m_owner; Ret(Own::*m_function)(Args...) = nullptr; }; template struct CallableMemberConst : public CallableBase { - CallableMemberConst(Ret(Own::*function)(Args...) const, const Own* owner) + CallableMemberConst(Ret(Own::*function)(Args...) const, const Own& owner) : m_owner(owner) , m_function(function) { } virtual Ret call(Args... args) const override { - return (m_owner->*m_function)(forward(args)...); + return (m_owner.*m_function)(forward(args)...); } private: - const Own* m_owner = nullptr; + const Own& m_owner; Ret(Own::*m_function)(Args...) const = nullptr; };