Skip to content

Commit

Permalink
Added Names to NamedTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Mar 31, 2024
1 parent 9163234 commit 1dcd6af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions include/rfl/NamedTuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "Field.hpp"
#include "Literal.hpp"
#include "get.hpp"
#include "internal/StringLiteral.hpp"
#include "internal/find_index.hpp"
Expand All @@ -29,8 +30,8 @@ template <class... FieldTypes>
class NamedTuple {
public:
using Fields = std::tuple<std::remove_cvref_t<FieldTypes>...>;
using Values =
std::tuple<typename std::remove_cvref<FieldTypes>::type::Type...>;
using Names = Literal<std::remove_cvref_t<FieldTypes>::name_...>;
using Values = std::tuple<typename std::remove_cvref_t<FieldTypes>::Type...>;

public:
/// Construct from the values.
Expand Down Expand Up @@ -555,6 +556,7 @@ template <>
class NamedTuple<> {
public:
using Fields = std::tuple<>;
using Names = Literal<>;
using Values = std::tuple<>;

NamedTuple(){};
Expand Down
4 changes: 3 additions & 1 deletion include/rfl/internal/make_tag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "../Literal.hpp"
#include "../field_names_t.hpp"
#include "../named_tuple_t.hpp"
#include "../to_view.hpp"
#include "StringLiteral.hpp"
#include "get_type_name.hpp"
Expand All @@ -16,7 +17,8 @@ template <internal::StringLiteral _discriminator, class T>
static inline auto make_tag(const T& _t) noexcept {
if constexpr (internal::has_reflection_type_v<T>) {
return make_tag<typename T::ReflectionType>();
} else if constexpr (field_names_t<T>::template contains<_discriminator>()) {
} else if constexpr (named_tuple_t<T>::Names::template contains<
_discriminator>()) {
return *to_view(_t).template get<_discriminator>();
} else if constexpr (internal::has_tag_v<T>) {
using LiteralType = typename T::Tag;
Expand Down

0 comments on commit 1dcd6af

Please sign in to comment.