mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-22 21:40:42 +00:00
Use SFINAE to avoid conflicts between visit functions
This commit is contained in:
parent
a60f657f5a
commit
83d212fe0f
@ -18,6 +18,15 @@ namespace ESM
|
||||
struct CellId;
|
||||
class RefId;
|
||||
|
||||
class CellVariant;
|
||||
|
||||
template <class, class T>
|
||||
using Substitute = T;
|
||||
|
||||
template <class F, class... T>
|
||||
using VisitReturnType = std::enable_if_t<(std::is_base_of_v<CellVariant, std::decay_t<T>> && ...),
|
||||
typename std::invoke_result<F, Substitute<T, const Cell&>...>::type>;
|
||||
|
||||
class CellVariant
|
||||
{
|
||||
protected:
|
||||
@ -39,7 +48,7 @@ namespace ESM
|
||||
const ESM::Cell& getEsm3() const;
|
||||
|
||||
template <class F, class... T>
|
||||
friend auto visit(F&& f, T&&... v);
|
||||
friend VisitReturnType<F, T...> visit(F&& f, T&&... v);
|
||||
};
|
||||
|
||||
struct ReferenceVariant
|
||||
@ -66,7 +75,7 @@ namespace ESM
|
||||
};
|
||||
|
||||
template <class F, class... T>
|
||||
auto visit(F&& f, T&&... v)
|
||||
VisitReturnType<F, T...> visit(F&& f, T&&... v)
|
||||
{
|
||||
return std::visit([&](auto*... ptr) { return std::forward<F>(f)(*ptr...); }, std::forward<T>(v).mVariant...);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user