1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-23 06:41:08 +00:00

Use SFINAE to avoid conflicts between visit functions

This commit is contained in:
elsid 2023-03-06 00:12:11 +01:00
parent a60f657f5a
commit 83d212fe0f
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

View File

@ -18,6 +18,15 @@ namespace ESM
struct CellId; struct CellId;
class RefId; 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 class CellVariant
{ {
protected: protected:
@ -39,7 +48,7 @@ namespace ESM
const ESM::Cell& getEsm3() const; const ESM::Cell& getEsm3() const;
template <class F, class... T> template <class F, class... T>
friend auto visit(F&& f, T&&... v); friend VisitReturnType<F, T...> visit(F&& f, T&&... v);
}; };
struct ReferenceVariant struct ReferenceVariant
@ -66,7 +75,7 @@ namespace ESM
}; };
template <class F, class... T> 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...); return std::visit([&](auto*... ptr) { return std::forward<F>(f)(*ptr...); }, std::forward<T>(v).mVariant...);
} }