mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-02 16:16:19 +08:00
Removed rfl::Enum, it is replaced by the externally tagged variant
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#define RFL_RFL_HPP_
|
||||
|
||||
#include "rfl/Box.hpp"
|
||||
#include "rfl/Enum.hpp"
|
||||
#include "rfl/Field.hpp"
|
||||
#include "rfl/Flatten.hpp"
|
||||
#include "rfl/Literal.hpp"
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
#ifndef RFL_ENUM_HPP_
|
||||
#define RFL_ENUM_HPP_
|
||||
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
|
||||
#include "rfl/NamedTuple.hpp"
|
||||
#include "rfl/internal/StringLiteral.hpp"
|
||||
#include "rfl/internal/no_duplicate_field_names.hpp"
|
||||
|
||||
namespace rfl {
|
||||
|
||||
template <class... FieldTypes>
|
||||
struct Enum {
|
||||
using Fields = std::tuple<FieldTypes...>;
|
||||
|
||||
/// The type of the underlying variant.
|
||||
using VariantType = std::variant<FieldTypes...>;
|
||||
|
||||
Enum(const VariantType& _variant) : variant_(_variant) {
|
||||
static_assert(internal::no_duplicate_field_names<Fields>(),
|
||||
"Duplicate field names are not allowed");
|
||||
}
|
||||
|
||||
Enum(VariantType&& _variant) : variant_(std::move(_variant)) {
|
||||
static_assert(internal::no_duplicate_field_names<Fields>(),
|
||||
"Duplicate field names are not allowed");
|
||||
}
|
||||
|
||||
~Enum() = default;
|
||||
|
||||
/// Assigns the underlying variant.
|
||||
inline void operator=(const VariantType& _variant) {
|
||||
static_assert(internal::no_duplicate_field_names<Fields>(),
|
||||
"Duplicate field names are not allowed");
|
||||
variant_ = _variant;
|
||||
}
|
||||
|
||||
/// Assigns the underlying variant.
|
||||
inline void operator=(VariantType&& _variant) {
|
||||
static_assert(internal::no_duplicate_field_names<Fields>(),
|
||||
"Duplicate field names are not allowed");
|
||||
variant_ = std::move(_variant);
|
||||
}
|
||||
|
||||
/// Returns the underlying variant.
|
||||
inline VariantType& variant() { return variant_; }
|
||||
|
||||
/// Returns the underlying variant.
|
||||
inline const VariantType& variant() const { return variant_; }
|
||||
|
||||
/// The underlying variant - an Enum is a thin wrapper
|
||||
/// around a variant that is mainly used for parsing.
|
||||
VariantType variant_;
|
||||
};
|
||||
|
||||
} // namespace rfl
|
||||
|
||||
#endif // RFL_TAGGEDUNION_HPP_
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "rfl/Box.hpp"
|
||||
#include "rfl/Enum.hpp"
|
||||
#include "rfl/Literal.hpp"
|
||||
#include "rfl/NamedTuple.hpp"
|
||||
#include "rfl/Ref.hpp"
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include "rfl/Enum.hpp"
|
||||
#include "rfl/Literal.hpp"
|
||||
#include "rfl/TaggedUnion.hpp"
|
||||
#include "rfl/internal/StringLiteral.hpp"
|
||||
@@ -12,12 +11,6 @@
|
||||
|
||||
namespace rfl {
|
||||
|
||||
/// Implements the visitor pattern for Enums.
|
||||
template <class Visitor, class... Args>
|
||||
inline auto visit(const Visitor& _visitor, const Enum<Args...>& _enum) {
|
||||
return std::visit(_visitor, _enum.variant_);
|
||||
}
|
||||
|
||||
/// Implements the visitor pattern for Literals.
|
||||
template <class Visitor, internal::StringLiteral... _fields, class... Args>
|
||||
inline auto visit(const Visitor& _visitor, const Literal<_fields...> _literal,
|
||||
@@ -33,7 +26,7 @@ inline auto visit(const Visitor& _visitor, const Literal<_fields...> _literal,
|
||||
template <class Visitor, internal::StringLiteral _discriminator, class... Args>
|
||||
inline auto visit(const Visitor& _visitor,
|
||||
const TaggedUnion<_discriminator, Args...>& _tagged_union) {
|
||||
return std::visit(_visitor, _tagged_union.variant_);
|
||||
return std::visit(_visitor, _tagged_union.variant());
|
||||
}
|
||||
|
||||
} // namespace rfl
|
||||
|
||||
Reference in New Issue
Block a user