diff --git a/include/rfl/Field.hpp b/include/rfl/Field.hpp index 6d7da8d3..824325d6 100644 --- a/include/rfl/Field.hpp +++ b/include/rfl/Field.hpp @@ -14,10 +14,10 @@ namespace rfl { /// Used to define a field in the NamedTuple. -template +template struct Field { /// The underlying type. - using Type = _Type; + using Type = T; /// The name of the field. using Name = rfl::Literal<_name>; @@ -26,31 +26,31 @@ struct Field { Field(Type&& _value) noexcept : value_(std::move(_value)) {} - Field(Field<_name, _Type>&& _field) noexcept = default; + Field(Field<_name, T>&& _field) noexcept = default; Field(const Field<_name, Type>& _field) = default; - template - Field(const Field<_name, T>& _field) : value_(_field.get()) {} + template + Field(const Field<_name, U>& _field) : value_(_field.get()) {} - template - Field(Field<_name, T>&& _field) : value_(_field.get()) {} + template + Field(Field<_name, U>&& _field) : value_(_field.get()) {} - template , + template , bool>::type = true> - Field(const T& _value) : value_(_value) {} + Field(const U& _value) : value_(_value) {} - template , + template , bool>::type = true> - Field(T&& _value) noexcept : value_(std::forward(_value)) {} + Field(U&& _value) noexcept : value_(std::forward(_value)) {} - template , + template , bool>::type = true> - Field(const Field<_name, T>& _field) : value_(_field.value()) {} + Field(const Field<_name, U>& _field) : value_(_field.value()) {} /// Assigns the underlying object to its default value. - template , + template , bool>::type = true> Field(const Default& _default) : value_(Type()) {} @@ -81,16 +81,16 @@ struct Field { } /// Assigns the underlying object. - template , + template , bool>::type = true> - auto& operator=(const T& _value) { + auto& operator=(const U& _value) { value_ = _value; return *this; } /// Assigns the underlying object to its default value. - template , + template , bool>::type = true> auto& operator=(const Default& _default) { value_ = Type(); @@ -98,21 +98,21 @@ struct Field { } /// Assigns the underlying object. - Field<_name, _Type>& operator=(const Field<_name, _Type>& _field) = default; + Field<_name, T>& operator=(const Field<_name, T>& _field) = default; /// Assigns the underlying object. - Field<_name, _Type>& operator=(Field<_name, _Type>&& _field) = default; + Field<_name, T>& operator=(Field<_name, T>&& _field) = default; /// Assigns the underlying object. - template - auto& operator=(const Field<_name, T>& _field) { + template + auto& operator=(const Field<_name, U>& _field) { value_ = _field.get(); return *this; } /// Assigns the underlying object. - template - auto& operator=(Field<_name, T>&& _field) { + template + auto& operator=(Field<_name, U>&& _field) { value_ = std::forward(_field.value_); return *this; } @@ -133,14 +133,14 @@ struct Field { Type value_; }; -template -inline auto make_field(_Type&& _value) { - return Field<_name, _Type>(std::forward<_Type>(_value)); +template +inline auto make_field(T&& _value) { + return Field<_name, T>(std::forward(_value)); } -template -inline auto make_field(const _Type& _value) { - return Field<_name, _Type>(_value); +template +inline auto make_field(const T& _value) { + return Field<_name, T>(_value); } } // namespace rfl diff --git a/include/rfl/Flatten.hpp b/include/rfl/Flatten.hpp index 5d7028e8..b5234436 100644 --- a/include/rfl/Flatten.hpp +++ b/include/rfl/Flatten.hpp @@ -10,91 +10,92 @@ namespace rfl { /// Used to embed another struct into the generated output. -template +template struct Flatten { - /// The underlying type. - using Type = std::decay_t<_Type>; + /// The underlying type. + using Type = std::decay_t; - Flatten(const Type& _value) : value_(_value) {} + Flatten(const Type& _value) : value_(_value) {} - Flatten(Type&& _value) noexcept : value_(std::forward(_value)) {} + Flatten(Type&& _value) noexcept : value_(std::forward(_value)) {} - Flatten(const Flatten<_Type>& _f) = default; + Flatten(const Flatten& _f) = default; - Flatten(Flatten<_Type>&& _f) noexcept = default; + Flatten(Flatten&& _f) noexcept = default; - template - Flatten(const Flatten& _f) : value_(_f.get()) {} + template + Flatten(const Flatten& _f) : value_(_f.get()) {} - template - Flatten(Flatten&& _f) : value_(_f.get()) {} + template + Flatten(Flatten&& _f) : value_(_f.get()) {} - template , - bool>::type = true> - Flatten(const T& _value) : value_(_value) {} + template , + bool>::type = true> + Flatten(const U& _value) : value_(_value) {} - template , - bool>::type = true> - Flatten(T&& _value) : value_(_value) {} + template , + bool>::type = true> + Flatten(U&& _value) : value_(_value) {} - ~Flatten() = default; + ~Flatten() = default; - /// Returns the underlying object. - const Type& get() const { return value_; } + /// Returns the underlying object. + const Type& get() const { return value_; } - /// Returns the underlying object. - Type& operator()() { return value_; } + /// Returns the underlying object. + Type& operator()() { return value_; } - /// Returns the underlying object. - const Type& operator()() const { return value_; } + /// Returns the underlying object. + const Type& operator()() const { return value_; } - /// Assigns the underlying object. - Flatten<_Type>& operator=(const _Type& _value) { - value_ = _value; - return *this; - } + /// Assigns the underlying object. + Flatten& operator=(const T& _value) { + value_ = _value; + return *this; + } - /// Assigns the underlying object. - Flatten<_Type>& operator=(_Type&& _value) { - value_ = std::forward(_value); - return *this; - } + /// Assigns the underlying object. + Flatten& operator=(T&& _value) { + value_ = std::forward(_value); + return *this; + } - /// Assigns the underlying object. - template , - bool>::type = true> - Flatten<_Type>& operator=(const T& _value) { - value_ = _value; - return *this; - } + /// Assigns the underlying object. + template , + bool>::type = true> + Flatten& operator=(const U& _value) { + value_ = _value; + return *this; + } - /// Assigns the underlying object. - Flatten<_Type>& operator=(const Flatten<_Type>& _f) = default; + /// Assigns the underlying object. + Flatten& operator=(const Flatten& _f) = default; - /// Assigns the underlying object. - Flatten<_Type>& operator=(Flatten<_Type>&& _f) = default; - /// Assigns the underlying object. - template - Flatten<_Type>& operator=(const Flatten& _f) { - value_ = _f.get(); - return *this; - } + /// Assigns the underlying object. + Flatten& operator=(Flatten&& _f) = default; - /// Assigns the underlying object. - template - Flatten<_Type>& operator=(Flatten&& _f) { - value_ = std::forward(_f); - return *this; - } + /// Assigns the underlying object. + template + Flatten& operator=(const Flatten& _f) { + value_ = _f.get(); + return *this; + } - /// Assigns the underlying object. - void set(const Type& _value) { value_ = _value; } + /// Assigns the underlying object. + template + Flatten& operator=(Flatten&& _f) { + value_ = std::forward(_f); + return *this; + } - /// Assigns the underlying object. - void set(Type&& _value) { value_ = std::forward(_value); } + /// Assigns the underlying object. + void set(const Type& _value) { value_ = _value; } - /// The underlying value. - Type value_; + /// Assigns the underlying object. + void set(Type&& _value) { value_ = std::forward(_value); } + + /// The underlying value. + Type value_; }; } // namespace rfl diff --git a/include/rfl/internal/find_index.hpp b/include/rfl/internal/find_index.hpp index 462f03ed..f4cb628f 100644 --- a/include/rfl/internal/find_index.hpp +++ b/include/rfl/internal/find_index.hpp @@ -10,27 +10,26 @@ namespace rfl { namespace internal { /// Finds the index of the field signified by _field_name -template +template constexpr static int find_index() { - using FieldType = - std::decay_t::type>; + using FieldType = std::decay_t::type>; - constexpr bool name_i_matches = (FieldType::name_ == _field_name); + constexpr bool name_i_matches = (FieldType::name_ == _field_name); - if constexpr (name_i_matches) { - return I; + if constexpr (name_i_matches) { + return I; + } else { + constexpr bool out_of_range = I + 1 == std::tuple_size{}; + + static_assert(!out_of_range, "Field name not found!"); + + if constexpr (out_of_range) { + // This is to avoid very confusing error messages. + return I; } else { - constexpr bool out_of_range = I + 1 == std::tuple_size<_Fields>{}; - - static_assert(!out_of_range, "Field name not found!"); - - if constexpr (out_of_range) { - // This is to avoid very confusing error messages. - return I; - } else { - return find_index<_field_name, _Fields, I + 1>(); - } + return find_index<_field_name, Fields, I + 1>(); } + } } } // namespace internal diff --git a/include/rfl/internal/to_ptr_field.hpp b/include/rfl/internal/to_ptr_field.hpp index 45352c70..6468d5e4 100644 --- a/include/rfl/internal/to_ptr_field.hpp +++ b/include/rfl/internal/to_ptr_field.hpp @@ -10,28 +10,28 @@ namespace rfl { namespace internal { -template -inline auto to_ptr_field(Field<_name, _Type>& _field) { - using T = std::remove_reference_t<_Type>; - return Field<_name, T*>(&_field.value_); +template +inline auto to_ptr_field(Field<_name, Type>& _field) { + using T = std::remove_reference_t; + return Field<_name, T*>(&_field.value_); } -template -inline auto to_ptr_field(const Field<_name, _Type>& _field) { - using T = std::remove_cvref_t<_Type>; - return Field<_name, const T*>(&_field.value_); +template +inline auto to_ptr_field(const Field<_name, Type>& _field) { + using T = std::remove_cvref_t; + return Field<_name, const T*>(&_field.value_); } -template -inline auto to_ptr_field(Flatten<_Type>& _field) { - using T = std::remove_reference_t<_Type>; - return Flatten(&_field.value_); +template +inline auto to_ptr_field(Flatten& _field) { + using T = std::remove_reference_t; + return Flatten(&_field.value_); } -template -inline auto to_ptr_field(const Flatten<_Type>& _field) { - using T = std::remove_cvref_t<_Type>; - return Flatten(&_field.value_); +template +inline auto to_ptr_field(const Flatten& _field) { + using T = std::remove_cvref_t; + return Flatten(&_field.value_); } } // namespace internal diff --git a/include/rfl/named_tuple_t.hpp b/include/rfl/named_tuple_t.hpp index 87172f19..816e1fe9 100644 --- a/include/rfl/named_tuple_t.hpp +++ b/include/rfl/named_tuple_t.hpp @@ -15,9 +15,9 @@ namespace rfl { template struct remove_ptr; -template -struct remove_ptr> { - using FieldType = Field<_name, std::decay_t>>; +template +struct remove_ptr> { + using FieldType = Field<_name, std::decay_t>>; }; template @@ -25,8 +25,8 @@ struct remove_ptrs_nt; template struct remove_ptrs_nt> { - using NamedTupleType = - NamedTuple::FieldType...>; + using NamedTupleType = + NamedTuple::FieldType...>; }; /// Generates the named tuple that is equivalent to the struct T. diff --git a/include/rfl/parsing/Parser.hpp b/include/rfl/parsing/Parser.hpp index 035935c0..f8951ab1 100644 --- a/include/rfl/parsing/Parser.hpp +++ b/include/rfl/parsing/Parser.hpp @@ -146,6 +146,8 @@ struct Parser { } }; +// ---------------------------------------------------------------------------- + template requires AreReaderAndWriter struct Parser {