Skip to content

Commit

Permalink
FunctionRef: Try to make it compile on Clang
Browse files Browse the repository at this point in the history
Try to bypass "error: cannot compile this forwarded non-trivially copyable parameter yet"
  • Loading branch information
SirLynix committed Feb 5, 2024
1 parent 037fbb6 commit a447904
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/NazaraUtils/FunctionRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace Nz
FunctionRef& operator=(FunctionRef&&) noexcept = default;

private:
template<typename Functor> static Ret Call(void* functor, Args... args);

using Callback = Ret(*)(void* functor, Args...);

Callback m_callback;
Expand Down
12 changes: 8 additions & 4 deletions include/NazaraUtils/FunctionRef.inl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ namespace Nz
FunctionRef<Ret(Args...)>::FunctionRef(F&& f) noexcept
{
m_functor = reinterpret_cast<void*>(std::addressof(f));
m_callback = [](void* functor, Args... args) -> Ret
{
return std::invoke(*reinterpret_cast<decltype(std::addressof(f))>(functor), std::forward<Args>(args)...);
};
m_callback = &Call<decltype(std::addressof(f))>;
}

template<typename Ret, typename... Args>
Expand All @@ -37,4 +34,11 @@ namespace Nz
{
return m_functor != nullptr;
}

template<typename Ret, typename... Args>
template<typename Functor>
Ret FunctionRef<Ret(Args...)>::Call(void* functor, Args... args)
{
return std::invoke(*reinterpret_cast<Functor>(functor), std::forward<Args>(args)...);
}
}

0 comments on commit a447904

Please sign in to comment.