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:
commit
c802da8e4b
1 changed files with 11 additions and 2 deletions
|
@ -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…
Reference in a new issue