Skip to content

Commit

Permalink
clang-12
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera committed Mar 25, 2022
1 parent 2042d5d commit fcf6522
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
21 changes: 20 additions & 1 deletion parser_library/include/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class sequence
static constexpr bool owns_resources = !std::is_trivially_destructible_v<storage>;
using counter_t = std::conditional_t<owns_resources, counter, size_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;
Expand All @@ -145,20 +148,36 @@ class sequence
{}
explicit operator std::vector<c_type>() const { return std::vector<c_type>(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<storage>)
{
if constexpr (trivial_storage_sequence<storage>) // clang-12 :(
return data()[index];
}
[[nodiscard]] auto data() const noexcept requires(trivial_storage_sequence<storage>)
{
return stor_.data();
}
*/

[[nodiscard]] c_type item(size_t index) const noexcept
{
if constexpr (trivial_storage_sequence<storage>)
return data()[index];
else
return item_impl(index);
}

[[nodiscard]] auto data() const noexcept requires(trivial_storage_sequence<storage>)
{
if constexpr (trivial_storage_sequence<storage>) // clang-12 :(
return stor_.data();
}

[[nodiscard]] size_t size() const noexcept { return size_; }

[[nodiscard]] auto begin() const noexcept
Expand Down
12 changes: 6 additions & 6 deletions parser_library/src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<completion_item, const lsp::completion_item_s*>::item(size_t index) const
completion_item sequence<completion_item, const lsp::completion_item_s*>::item_impl(size_t index) const
{
return completion_item(stor_[index]);
}
Expand All @@ -57,7 +57,7 @@ document_symbol_list document_symbol_item::children() const
}

template<>
document_symbol_item sequence<document_symbol_item, const lsp::document_symbol_item_s*>::item(size_t index) const
document_symbol_item sequence<document_symbol_item, const lsp::document_symbol_item_s*>::item_impl(size_t index) const
{
return document_symbol_item(stor_[index]);
}
Expand All @@ -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<position_uri, const location*>::item(size_t index) const
position_uri sequence<position_uri, const location*>::item_impl(size_t index) const
{
return position_uri(stor_[index]);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ stack_frame::stack_frame(const debugging::stack_frame& frame)
{}

template<>
stack_frame sequence<stack_frame, const debugging::stack_frame*>::item(size_t index) const
stack_frame sequence<stack_frame, const debugging::stack_frame*>::item_impl(size_t index) const
{
return stack_frame(stor_[index]);
}
Expand All @@ -170,7 +170,7 @@ scope::scope(const debugging::scope& impl)
{}

template<>
scope sequence<scope, const debugging::scope*>::item(size_t index) const
scope sequence<scope, const debugging::scope*>::item_impl(size_t index) const
{
return scope(stor_[index]);
}
Expand All @@ -186,7 +186,7 @@ variable::variable(const debugging::variable& impl)
{}

template<>
variable sequence<variable, const debugging::variable_store*>::item(size_t index) const
variable sequence<variable, const debugging::variable_store*>::item_impl(size_t index) const
{
return variable(*stor_->variables[index]);
}
Expand Down

0 comments on commit fcf6522

Please sign in to comment.