diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-05-27 20:19:15 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-05-27 20:19:15 +0200 |
commit | 60e44cb3c8933e26d535414c49b9991cbca39154 (patch) | |
tree | e4d58a3f5a4e2d26bfec1df1726dfc153fc5078c | |
parent | 1269cc5023bce875d4bb69ef9de082990e061265 (diff) |
c++: Added support for literal handling
-rw-r--r-- | src/codec/schema.h | 8 | ||||
-rw-r--r-- | src/core/templates.h | 25 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/codec/schema.h b/src/codec/schema.h index 5021d33..df9f443 100644 --- a/src/codec/schema.h +++ b/src/codec/schema.h @@ -28,6 +28,14 @@ struct Union<Member<V, K>...> {}; template <typename T> struct Array {}; +template <class T> struct is_array { + constexpr static bool value = false; +}; + +template <class T> struct is_array<schema::Array<T>> { + constexpr static bool value = true; +}; + template<typename T, size_t S> struct FixedArray {}; template <typename... T> struct Tuple {}; diff --git a/src/core/templates.h b/src/core/templates.h index c363a16..9b4bcac 100644 --- a/src/core/templates.h +++ b/src/core/templates.h @@ -25,5 +25,30 @@ struct parameter_pack_type<N, TN, T...> { static_assert(sizeof...(T) > 0, "Exhausted parameters"); using type = typename parameter_pack_type<N - 1, T...>::type; }; +/* + * Nightmare inducing compiler problems found here. Somehow non-type + * string_literals cannot be resolved as non-type primitive template values can. + * This is the workaround + */ +template <string_literal V, string_literal Key0, string_literal... Keys> +struct parameter_key_pack_index_helper { + static constexpr size_t value = + (V == Key0) + ? (0u) + : (1u + parameter_key_pack_index_helper<V, Keys...>::value); +}; + +template <string_literal V, string_literal Key0> +struct parameter_key_pack_index_helper<V, Key0> { + static constexpr size_t value = (V == Key0) ? (0u) : (1u); +}; + +template <string_literal V, string_literal... Keys> +struct parameter_key_pack_index { + static constexpr size_t value = + parameter_key_pack_index_helper<V, Keys...>::value; + static_assert(value < sizeof...(Keys), + "Provided string_literal doesn't exist in searched list"); +}; } |