Skip to content

Commit 5880c8e

Browse files
committed
FunctionRef: Rework it to make it compile on Clang on Windows
Try to bypass "error: cannot compile this forwarded non-trivially copyable parameter yet"
1 parent 45e4b8e commit 5880c8e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

include/NazaraUtils/FunctionRef.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace Nz
3535
FunctionRef& operator=(FunctionRef&&) noexcept = default;
3636

3737
private:
38+
template<typename Functor> static Ret Call(void* functor, Args... args);
39+
3840
using Callback = Ret(*)(void* functor, Args...);
3941

4042
Callback m_callback;

include/NazaraUtils/FunctionRef.inl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ namespace Nz
1919
FunctionRef<Ret(Args...)>::FunctionRef(F&& f) noexcept
2020
{
2121
m_functor = reinterpret_cast<void*>(std::addressof(f));
22-
m_callback = [](void* functor, Args... args) -> Ret
23-
{
24-
return std::invoke(*reinterpret_cast<decltype(std::addressof(f))>(functor), std::forward<Args>(args)...);
25-
};
22+
m_callback = &Call<decltype(std::addressof(f))>;
2623
}
2724

2825
template<typename Ret, typename... Args>
@@ -37,4 +34,11 @@ namespace Nz
3734
{
3835
return m_functor != nullptr;
3936
}
37+
38+
template<typename Ret, typename... Args>
39+
template<typename Functor>
40+
Ret FunctionRef<Ret(Args...)>::Call(void* functor, Args... args)
41+
{
42+
return std::invoke(*reinterpret_cast<Functor>(functor), std::forward<Args>(args)...);
43+
}
4044
}

0 commit comments

Comments
 (0)