draconisplusplus/include/rfl/internal/VisitorWrapper.hpp

28 lines
732 B
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_INTERNAL_VISITORWRAPPER_HPP_
#define RFL_INTERNAL_VISITORWRAPPER_HPP_
#include "../Literal.hpp"
#include "../TaggedUnion.hpp"
#include "StringLiteral.hpp"
namespace rfl {
2024-06-08 14:10:59 -04:00
namespace internal {
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// Necessary for the VisitTree structure.
template <class Visitor, internal::StringLiteral... _fields>
struct VisitorWrapper {
/// Calls the underlying visitor when required to do so.
template <int _i, class... Args>
inline auto visit(const Args&... _args) const {
2024-05-31 22:59:00 -04:00
return (*visitor_)(name_of<Literal<_fields...>, _i>(), _args...);
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// The underlying visitor.
const Visitor* visitor_;
};
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
} // namespace internal
} // namespace rfl
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
#endif // RFL_VISIT_HPP_