Skip to content

Commit 43981f6

Browse files
Made everything consteval
1 parent 3ac42d5 commit 43981f6

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

include/rfl/Literal.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class Literal {
4747
/// Copy constructor - constructs a Literal from another literal with the same
4848
/// fields.
4949
/// @param _other The literal to copy from
50-
Literal(const Literal<fields_...>& _other) = default;
50+
constexpr Literal(const Literal<fields_...>& _other) = default;
5151

5252
/// Move constructor - constructs a Literal from another literal with the same
5353
/// fields.
5454
/// @param _other The literal to move from
55-
Literal(Literal<fields_...>&& _other) noexcept = default;
55+
constexpr Literal(Literal<fields_...>&& _other) noexcept = default;
5656

5757
/// Constructs a Literal from a string value.
5858
/// @param _str The string representing one of the literal's allowed values
@@ -61,7 +61,7 @@ class Literal {
6161
Literal(const std::string& _str) : value_(find_value(_str).value()) {}
6262

6363
/// Default constructor - initializes to the first value (index 0).
64-
Literal() : value_(0) {}
64+
constexpr Literal() : value_(0) {}
6565

6666
/// Destructor.
6767
~Literal() = default;
@@ -87,7 +87,7 @@ class Literal {
8787
/// @tparam _value The index of the value (must be less than num_fields_)
8888
/// @return A Literal representing the value at the specified index
8989
template <ValueType _value>
90-
static Literal<fields_...> from_value() {
90+
static constexpr Literal<fields_...> from_value() {
9191
static_assert(_value < num_fields_,
9292
"Value cannot exceed number of fields.");
9393
return Literal<fields_...>(_value);

include/rfl/internal/concat_literals.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ struct LiteralWrapper {
1414
};
1515

1616
template <StringLiteral... _names>
17-
auto wrap_literal(const Literal<_names...>& _literal) {
17+
consteval auto wrap_literal(const Literal<_names...>& _literal) {
1818
return LiteralWrapper<_names...>{_literal};
1919
}
2020

2121
template <StringLiteral... _names1, StringLiteral... _names2>
22-
auto operator+(const LiteralWrapper<_names1...>&,
23-
const LiteralWrapper<_names2...>&) {
22+
consteval auto operator+(const LiteralWrapper<_names1...>&,
23+
const LiteralWrapper<_names2...>&) {
2424
return LiteralWrapper<_names1..., _names2...>{
25-
rfl::Literal<_names1..., _names2...>::template from_value<0>()};
25+
rfl::Literal<_names1..., _names2...>()};
2626
}
2727

2828
template <class Head, class... Tail>
29-
auto concat_literals(const Head& _head, const Tail&... _tail) {
29+
consteval auto concat_literals(const Head& _head, const Tail&... _tail) {
3030
return (wrap_literal(_head) + ... + wrap_literal(_tail)).literal_;
3131
}
3232

3333
// Special case - every literal contains exactly one value.
3434
template <StringLiteral _head, StringLiteral... _tail>
35-
auto concat_literals(const rfl::Literal<_head>&,
36-
const rfl::Literal<_tail>&...) {
37-
return rfl::Literal<_head, _tail...>::template from_value<0>();
35+
consteval auto concat_literals(const rfl::Literal<_head>&,
36+
const rfl::Literal<_tail>&...) {
37+
return rfl::Literal<_head, _tail...>();
3838
}
3939

4040
// Special case - no literals.
41-
inline auto concat_literals() { return rfl::Literal<>(); }
41+
consteval inline auto concat_literals() { return rfl::Literal<>(); }
4242

4343
} // namespace rfl::internal
4444

include/rfl/internal/cpp26/get_field_names.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
namespace rfl::internal::cpp26 {
1818

1919
template <class T>
20-
auto get_field_names();
20+
consteval auto get_field_names();
2121

2222
template <class T, class FieldName>
23-
auto get_field_names_impl() {
23+
consteval auto get_field_names_impl() {
2424
using Type = std::remove_cvref_t<std::remove_pointer_t<T>>;
2525
if constexpr (is_rename_v<Type>) {
2626
using Name = typename Type::Name;
@@ -33,7 +33,7 @@ auto get_field_names_impl() {
3333
}
3434

3535
template <class T>
36-
auto get_field_names() {
36+
consteval auto get_field_names() {
3737
using Type = std::remove_cvref_t<T>;
3838
if constexpr (std::is_pointer_v<Type>) {
3939
return get_field_names<std::remove_pointer_t<Type>>();

0 commit comments

Comments
 (0)