mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 02:36:18 +08:00
Added Names to NamedTuple
This commit is contained in:
@@ -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,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;
|
||||
|
||||
Reference in New Issue
Block a user