fixing typo bugs

This commit is contained in:
Claudius Holeksa 2021-12-18 20:54:51 +01:00
parent 3c2cf1bdfd
commit e55ff39192
3 changed files with 44 additions and 22 deletions

View File

@ -65,14 +65,14 @@ public:
public:
Builder(MessageType &msg) : message{msg} {}
Reader asReader() { return Reader{MessageType & message}; }
Reader asReader() { return Reader{message}; }
/*
* Initialize a member by index
*/
template <size_t i> typename Container::ElementType<i>::Builder init() {
return typename Container::ElementType<i>::Builder{
message.container.get<i>()};
message.container.template get<i>()};
}
/*
@ -81,10 +81,10 @@ public:
*/
template <StringLiteral Literal>
typename Container::ElementType<
MessageParameterKeyIndex<Literal, Keys...>::Value>::Builder
MessageParameterKeyPackIndex<Literal, Keys...>::Value>::Builder
init() {
constexpr size_t i =
MessageParameterKeyIndex<Literal, Keys...>::Value;
MessageParameterKeyPackIndex<Literal, Keys...>::Value;
return init<i>();
}
@ -104,7 +104,7 @@ public:
*/
template <size_t i> typename Container::ElementType<i>::Reader get() {
return typename Container::ElementType<i>::Reader{
message.container.get<i>()};
message.container.template get<i>()};
}
/*
@ -113,11 +113,11 @@ public:
*/
template <StringLiteral Literal>
typename Container::ElementType<
MessageParameterKeyIndex<Literal, Keys...>::Value>::Reader
MessageParameterKeyPackIndex<Literal, Keys...>::Value>::Reader
get() {
// The index of the first match
constexpr size_t i =
MessageParameterKeyIndex<Literal, Keys...>::Value;
MessageParameterKeyPackIndex<Literal, Keys...>::Value;
return get<i>();
}
@ -159,7 +159,7 @@ public:
template <size_t i> typename Container::ElementType<i>::Builder init() {
return typename Container::ElementType<i>::Builder{
message.container.get<i>()};
message.container.template get<i>()};
}
};
@ -174,12 +174,12 @@ public:
template <size_t i> typename Container::ElementType<i>::Reader get() {
return typename Container::ElementType<i>::Reader{
message.container.get<i>()};
message.container.template get<i>()};
}
template <StringLiteral Literal>
constexpr size_t index() const noexcept {
return MessageParameterPackIndex<Literal, Keys...>::Value;
return MessageParameterKeyPackIndex<Literal, Keys...>::Value;
}
};
};
@ -241,7 +241,7 @@ Container::MessageType::Reader{message.container.get<i>()};
/*
* Tuple message class. Wrapper around a tuple schema
*/
template <class... T>
template <class... T, class Container>
class Message<schema::Tuple<T...>, Container> final : public MessageBase {
private:
using SchemaType = schema::Tuple<T...>;
@ -267,7 +267,7 @@ public:
template <size_t i> typename Container::MessageType::Builder init() {
return typename Container::MessageType::Builder{
message.container.get<i>()};
message.container.template get<i>()};
}
};
class Reader {
@ -281,7 +281,7 @@ public:
template <size_t i> typename Container::MessageType::Reader get() {
return typename Container::MessageType::Reader{
message.container.get<i>()};
message.container.template get<i>()};
}
};
};
@ -369,7 +369,7 @@ public:
Builder asBuilder() { return Builder{message}; }
std::string_view get() { return message.container.get(); }
}
};
};
template <class Schema, class Container = MessageContainer<Schema>>

View File

@ -30,17 +30,30 @@ struct MessageParameterPackIndex<T, TL0, TL...> {
1u + MessageParameterPackIndex<T, TL...>::Value;
};
template <StringLiteral... ValueKeys> struct MessageParameterKeyIndex;
template <StringLiteral V, StringLiteral... Keys>
struct MessageParameterKeyIndex<V, V, Keys...> {
static constexpr size_t Value = 0u;
/*
* Nightmare inducing compiler problems found here. Somehow non-type
* StringLiterals cannot be resolved as non-type primitive template values can.
* This is the workaround
*/
template <StringLiteral V, StringLiteral Key0, StringLiteral... Keys>
struct MessageParameterKeyPackIndexHelper {
static constexpr size_t Value =
(V == Key0)
? (0u)
: (1u + MessageParameterKeyPackIndexHelper<V, Keys...>::Value);
};
template <StringLiteral V, StringLiteral Key0, StringLiteral... Keys>
struct MessageParameterKeyIndex<V, Key0, Keys...> {
template <StringLiteral V, StringLiteral Key0>
struct MessageParameterKeyPackIndexHelper<V, Key0> {
static constexpr size_t Value = (V == Key0) ? (0u) : (1u);
};
template <StringLiteral V, StringLiteral... Keys>
struct MessageParameterKeyPackIndex {
static constexpr size_t Value =
1u + MessageParameterKeyIndex<V, Keys...>::Value;
MessageParameterKeyPackIndexHelper<V, Keys...>::Value;
static_assert(Value < sizeof...(Keys),
"Provided StringLiteral doesn't exist in searched list");
};
template <class... V, StringLiteral... Keys>

View File

@ -22,6 +22,15 @@ public:
constexpr std::string_view view() const noexcept {
return std::string_view{data.data()};
}
constexpr bool operator==(const StringLiteral<CharT, N> &) const
noexcept = default;
template <class CharTR, size_t NR>
constexpr bool operator==(const StringLiteral<CharTR, NR> &) const
noexcept {
return false;
}
};
template <typename T, T... Chars>