Added Names to NamedTuple

This commit is contained in:
Patrick Urbanke
2024-03-31 17:45:09 +02:00
parent 916323495c
commit 1dcd6af373
2 changed files with 7 additions and 3 deletions
+4 -2
View File
@@ -8,6 +8,7 @@
#include <utility>
#include "Field.hpp"
#include "Literal.hpp"
#include "get.hpp"
#include "internal/StringLiteral.hpp"
#include "internal/find_index.hpp"
@@ -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.
@@ -555,6 +556,7 @@ template <>
class NamedTuple<> {
public:
using Fields = std::tuple<>;
using Names = Literal<>;
using Values = std::tuple<>;
NamedTuple(){};
+3 -1
View File
@@ -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"
@@ -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;