draconisplusplus/include/rfl/get.hpp

48 lines
1.4 KiB
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_GET_HPP_
#define RFL_GET_HPP_
#include "internal/Getter.hpp"
#include "internal/StringLiteral.hpp"
namespace rfl {
2024-06-08 14:10:59 -04:00
/// Gets a field by index.
template <int _index, class NamedTupleType>
inline auto& get(NamedTupleType& _tup) {
2024-05-31 22:59:00 -04:00
return internal::Getter<NamedTupleType>::template get<_index>(_tup);
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// Gets a field by name.
template <internal::StringLiteral _field_name, class NamedTupleType>
inline auto& get(NamedTupleType& _tup) {
2024-05-31 22:59:00 -04:00
return internal::Getter<NamedTupleType>::template get<_field_name>(_tup);
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// Gets a field by the field type.
template <class Field, class NamedTupleType>
inline auto& get(NamedTupleType& _tup) {
2024-05-31 22:59:00 -04:00
return internal::Getter<NamedTupleType>::template get<Field>(_tup);
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// Gets a field by index.
template <int _index, class NamedTupleType>
inline const auto& get(const NamedTupleType& _tup) {
2024-05-31 22:59:00 -04:00
return internal::Getter<NamedTupleType>::template get_const<_index>(_tup);
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// Gets a field by name.
template <internal::StringLiteral _field_name, class NamedTupleType>
inline const auto& get(const NamedTupleType& _tup) {
2024-06-16 00:13:15 -04:00
return internal::Getter<NamedTupleType>::template get_const<_field_name>(_tup);
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// Gets a field by the field type.
template <class Field, class NamedTupleType>
inline const auto& get(const NamedTupleType& _tup) {
2024-05-31 22:59:00 -04:00
return internal::Getter<NamedTupleType>::template get_const<Field>(_tup);
2024-06-08 14:10:59 -04:00
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
} // namespace rfl
2024-05-31 22:59:00 -04:00
#endif