diff --git a/parser_library/include/sequence.h b/parser_library/include/sequence.h index 0f8be7830..6e09924fa 100644 --- a/parser_library/include/sequence.h +++ b/parser_library/include/sequence.h @@ -135,6 +135,9 @@ class sequence static constexpr bool owns_resources = !std::is_trivially_destructible_v; using counter_t = std::conditional_t; + // needs to be specialized for every type unless the storage is trivial + [[nodiscard]] c_type item_impl(size_t index) const; + public: sequence() = default; sequence(const sequence&) = default; @@ -145,13 +148,28 @@ class sequence {} explicit operator std::vector() const { return std::vector(begin(), end()); } + /* + * clang-14+ needed // needs to be specialized for every type unless the storage is trivial [[nodiscard]] c_type item(size_t index) const; [[nodiscard]] c_type item(size_t index) const noexcept requires(trivial_storage_sequence) { - if constexpr (trivial_storage_sequence) // clang-12 :( + return data()[index]; + } + + [[nodiscard]] auto data() const noexcept requires(trivial_storage_sequence) + { + return stor_.data(); + } + */ + + [[nodiscard]] c_type item(size_t index) const noexcept + { + if constexpr (trivial_storage_sequence) return data()[index]; + else + return item_impl(index); } [[nodiscard]] auto data() const noexcept requires(trivial_storage_sequence) @@ -159,6 +177,7 @@ class sequence if constexpr (trivial_storage_sequence) // clang-12 :( return stor_.data(); } + [[nodiscard]] size_t size() const noexcept { return size_; } [[nodiscard]] auto begin() const noexcept diff --git a/parser_library/src/protocol.cpp b/parser_library/src/protocol.cpp index 1434102e4..f83f0c174 100644 --- a/parser_library/src/protocol.cpp +++ b/parser_library/src/protocol.cpp @@ -36,7 +36,7 @@ std::string_view completion_item::documentation() const { return item_.documenta std::string_view completion_item::insert_text() const { return item_.insert_text; } template<> -completion_item sequence::item(size_t index) const +completion_item sequence::item_impl(size_t index) const { return completion_item(stor_[index]); } @@ -57,7 +57,7 @@ document_symbol_list document_symbol_item::children() const } template<> -document_symbol_item sequence::item(size_t index) const +document_symbol_item sequence::item_impl(size_t index) const { return document_symbol_item(stor_[index]); } @@ -70,7 +70,7 @@ position position_uri::pos() const { return item_.pos; } std::string_view position_uri::file() const { return item_.file; } template<> -position_uri sequence::item(size_t index) const +position_uri sequence::item_impl(size_t index) const { return position_uri(stor_[index]); } @@ -150,7 +150,7 @@ stack_frame::stack_frame(const debugging::stack_frame& frame) {} template<> -stack_frame sequence::item(size_t index) const +stack_frame sequence::item_impl(size_t index) const { return stack_frame(stor_[index]); } @@ -170,7 +170,7 @@ scope::scope(const debugging::scope& impl) {} template<> -scope sequence::item(size_t index) const +scope sequence::item_impl(size_t index) const { return scope(stor_[index]); } @@ -186,7 +186,7 @@ variable::variable(const debugging::variable& impl) {} template<> -variable sequence::item(size_t index) const +variable sequence::item_impl(size_t index) const { return variable(*stor_->variables[index]); }