BAN: Function now properly forward arguments
This commit is contained in:
parent
124afbecaa
commit
53a5ad3cf9
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <BAN/Errors.h>
|
#include <BAN/Errors.h>
|
||||||
|
#include <BAN/Move.h>
|
||||||
|
|
||||||
namespace BAN
|
namespace BAN
|
||||||
{
|
{
|
||||||
|
@ -30,13 +31,13 @@ namespace BAN
|
||||||
new (m_storage) CallableMemberConst<Own>(function, owner);
|
new (m_storage) CallableMemberConst<Own>(function, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ret operator()(const Args&... args)
|
Ret operator()(Args... args)
|
||||||
{
|
{
|
||||||
ASSERT(HasFunction());
|
ASSERT(*this);
|
||||||
return ((CallableBase*)m_storage)->call(args...);
|
return reinterpret_cast<CallableBase*>(m_storage)->call(Forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasFunction() const
|
operator bool() const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_size; i++)
|
for (size_t i = 0; i < m_size; i++)
|
||||||
if (m_storage[i])
|
if (m_storage[i])
|
||||||
|
@ -48,7 +49,7 @@ namespace BAN
|
||||||
struct CallableBase
|
struct CallableBase
|
||||||
{
|
{
|
||||||
virtual ~CallableBase() {}
|
virtual ~CallableBase() {}
|
||||||
virtual Ret call(const Args&...) = 0;
|
virtual Ret call(Args...) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CallablePointer : public CallableBase
|
struct CallablePointer : public CallableBase
|
||||||
|
@ -57,9 +58,9 @@ namespace BAN
|
||||||
: m_function(function)
|
: m_function(function)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual Ret call(const Args&... args) override
|
virtual Ret call(Args... args) override
|
||||||
{
|
{
|
||||||
return m_function(args...);
|
return m_function(Forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -74,9 +75,9 @@ namespace BAN
|
||||||
, m_function(function)
|
, m_function(function)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual Ret call(const Args&... args) override
|
virtual Ret call(Args... args) override
|
||||||
{
|
{
|
||||||
return (m_owner->*m_function)(args...);
|
return (m_owner->*m_function)(Forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -92,9 +93,9 @@ namespace BAN
|
||||||
, m_function(function)
|
, m_function(function)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual Ret call(const Args&... args) override
|
virtual Ret call(Args... args) override
|
||||||
{
|
{
|
||||||
return (m_owner->*m_function)(args...);
|
return (m_owner->*m_function)(Forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -385,21 +385,21 @@ namespace Input
|
||||||
|
|
||||||
while (!s_key_event_queue.Empty())
|
while (!s_key_event_queue.Empty())
|
||||||
{
|
{
|
||||||
if (s_key_event_callback.HasFunction())
|
if (s_key_event_callback)
|
||||||
s_key_event_callback(s_key_event_queue.Front());
|
s_key_event_callback(s_key_event_queue.Front());
|
||||||
s_key_event_queue.Pop();
|
s_key_event_queue.Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!s_mouse_button_event_queue.Empty())
|
while (!s_mouse_button_event_queue.Empty())
|
||||||
{
|
{
|
||||||
if (s_mouse_button_event_callback.HasFunction())
|
if (s_mouse_button_event_callback)
|
||||||
s_mouse_button_event_callback(s_mouse_button_event_queue.Front());
|
s_mouse_button_event_callback(s_mouse_button_event_queue.Front());
|
||||||
s_mouse_button_event_queue.Pop();
|
s_mouse_button_event_queue.Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!s_mouse_move_event_queue.Empty())
|
while (!s_mouse_move_event_queue.Empty())
|
||||||
{
|
{
|
||||||
if (s_mouse_move_event_callback.HasFunction())
|
if (s_mouse_move_event_callback)
|
||||||
s_mouse_move_event_callback(s_mouse_move_event_queue.Front());
|
s_mouse_move_event_callback(s_mouse_move_event_queue.Front());
|
||||||
s_mouse_move_event_queue.Pop();
|
s_mouse_move_event_queue.Pop();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue