|
13 | 13 | #include "Result.hpp"
|
14 | 14 | #include "Tuple.hpp"
|
15 | 15 | #include "internal/StringLiteral.hpp"
|
| 16 | +#include "internal/find_index.hpp" |
16 | 17 | #include "internal/no_duplicate_field_names.hpp"
|
17 | 18 |
|
18 | 19 | namespace rfl {
|
@@ -95,31 +96,24 @@ class Literal {
|
95 | 96 |
|
96 | 97 | /// Determines whether the literal contains any of the strings in the other
|
97 | 98 | /// literal at compile time.
|
98 |
| - template <class OtherLiteralType, int _i = 0> |
| 99 | + template <class OtherLiteralType> |
99 | 100 | static constexpr bool contains_any() {
|
100 |
| - if constexpr (_i == num_fields_) { |
101 |
| - return false; |
102 |
| - } else { |
103 |
| - constexpr auto name = find_name_within_own_fields<_i>(); |
104 |
| - return OtherLiteralType::template contains<name>() || |
105 |
| - contains_any<OtherLiteralType, _i + 1>(); |
106 |
| - } |
| 101 | + return []<int... _is>(const std::integer_sequence<int, _is...>&) { |
| 102 | + return (false || ... || |
| 103 | + OtherLiteralType::template contains< |
| 104 | + find_name_within_own_fields<_is>()>()); |
| 105 | + }(std::make_integer_sequence<int, num_fields_>()); |
107 | 106 | }
|
108 | 107 |
|
109 | 108 | /// Determines whether the literal contains all of the strings in the other
|
110 | 109 | /// literal at compile time.
|
111 |
| - template <class OtherLiteralType, int _i = 0, int _n_found = 0> |
| 110 | + template <class OtherLiteralType> |
112 | 111 | static constexpr bool contains_all() {
|
113 |
| - if constexpr (_i == num_fields_) { |
114 |
| - return _n_found == OtherLiteralType::num_fields_; |
115 |
| - } else { |
116 |
| - constexpr auto name = find_name_within_own_fields<_i>(); |
117 |
| - if constexpr (OtherLiteralType::template contains<name>()) { |
118 |
| - return contains_all<OtherLiteralType, _i + 1, _n_found + 1>(); |
119 |
| - } else { |
120 |
| - return contains_all<OtherLiteralType, _i + 1, _n_found>(); |
121 |
| - } |
122 |
| - } |
| 112 | + return []<int... _is>(const std::integer_sequence<int, _is...>&) { |
| 113 | + return (true && ... && |
| 114 | + OtherLiteralType::template contains< |
| 115 | + find_name_within_own_fields<_is>()>()); |
| 116 | + }(std::make_integer_sequence<int, num_fields_>()); |
123 | 117 | }
|
124 | 118 |
|
125 | 119 | /// Determines whether the literal has duplicate strings at compile time.
|
@@ -332,18 +326,9 @@ class Literal {
|
332 | 326 | }
|
333 | 327 |
|
334 | 328 | /// Finds the value of a string literal at compile time.
|
335 |
| - template <internal::StringLiteral _name, int _i = 0> |
| 329 | + template <internal::StringLiteral _name> |
336 | 330 | static constexpr int find_value_of() {
|
337 |
| - if constexpr (_i == num_fields_) { |
338 |
| - return -1; |
339 |
| - } else { |
340 |
| - using FieldType = tuple_element_t<_i, FieldsType>; |
341 |
| - if constexpr (FieldType::name_ == _name) { |
342 |
| - return _i; |
343 |
| - } else { |
344 |
| - return find_value_of<_name, _i + 1>(); |
345 |
| - } |
346 |
| - } |
| 331 | + return internal::find_index_or_minus_one<_name, FieldsType>(); |
347 | 332 | }
|
348 | 333 |
|
349 | 334 | /// Whether the literal contains this string.
|
|
0 commit comments