1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-19 15:09:43 +00:00

Merge branch 'scoped_visit' into 'master'

Use SFINAE to avoid conflicts between visit functions

See merge request OpenMW/openmw!2838
This commit is contained in:
psi29a 2023-03-18 09:14:21 +00:00
commit c802da8e4b

View file

@ -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...);
}