Skip to content

Conversation

@dranikpg
Copy link
Contributor

@dranikpg dranikpg commented Jan 17, 2026

Just a PR to play with c++20 features:

  1. Use concepts in memory accounting code
  2. Use ranges instead of my own compound iterator from helio for ArgRange
  3. Use ranges instead of hand written transform iterator in BackedArgumetns
  4. Use spaceship in string_or_view

-> remove 100 loc from a total of 500 loc

Signed-off-by: Vladislav Oleshko <[email protected]>
Copilot AI review requested due to automatic review settings January 17, 2026 09:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes common utilities in the Dragonfly codebase to use C++20 features. The changes replace legacy template metaprogramming with modern concepts, constraints, and the spaceship operator.

Changes:

  • Replaced traditional comparison operators with C++20 spaceship operator in StringOrView class
  • Converted template metaprogramming (SFINAE) to C++20 concepts and requires clauses in heap_size.h
  • Renamed namespace from heap_size_detail to detail for consistency

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/common/string_or_view.h Modernized comparison operators using spaceship operator and relocated empty() method
src/common/heap_size.h Converted SFINAE-based constraints to concepts and requires clauses, introduced StackOnly concept
Comments suppressed due to low confidence (1)

src/common/heap_size.h:135

  • The AccumulateContainer function is still defined in the heap_size_detail namespace (line 123), but it's forward-declared in the detail namespace (line 37) and called as detail::AccumulateContainer throughout the file. This creates a mismatch - the function definition should be in the detail namespace to match the forward declaration and usage.
namespace heap_size_detail {
template <typename Container> size_t AccumulateContainer(const Container& c) {
  size_t size = 0;

  if constexpr (!detail::StackOnly<typename Container::value_type>) {
    for (const auto& e : c) {
      size += HeapSize(e);
    }
  }

  return size;
}
}  // namespace heap_size_detail

Copilot AI review requested due to automatic review settings January 18, 2026 08:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.

vector<string_view> mapped(vals.Size() + 1);
mapped[0] = key;
std::copy(vals.begin(), vals.end(), mapped.begin() + 1);
std::ranges::copy(vals.view(), mapped.begin() + 1);
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required header for C++20 ranges. The code uses std::ranges::copy which requires including the <ranges> header. Add #include <ranges> at the top of the file.

Copilot uses AI. Check for mistakes.
Comment on lines +40 to 62
// Overload for types that have defined UsedMemory
template <typename T>
requires requires(T t) {
{ t.UsedMemory() } -> std::convertible_to<size_t>;
}
size_t HeapSize(const T& t) {
return t.UsedMemory();
}

template <typename T, std::enable_if_t<heap_size_detail::StackOnlyType<T>(), bool> = true>
// Overload for types that should be explicitly excluded from calculations
template <typename T>
requires requires {
typename T::is_stackonly;
}
size_t HeapSize(const T& t) {
return 0;
}

template <typename T> size_t HeapSize(absl::Span<T>) {
// Overload for trivial types we don't have to account for
template <typename T> size_t HeapSize(const T& t) {
static_assert(std::is_trivial_v<T> || std::is_same_v<std::string_view, T>);
return 0;
}
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required header for C++20 concepts. The code uses requires expressions which require including the <concepts> header (or at minimum <type_traits> which is already included, but <concepts> is more appropriate for modern C++20 code). Add #include <concepts> at the top of the file.

Copilot uses AI. Check for mistakes.
Comment on lines +76 to 79
auto view() const {
return std::views::iota(size_t{0}, size()) |
std::views::transform([this](size_t i) { return at(i); });
}
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required header for C++20 ranges. The view() method uses std::views::iota and std::views::transform which require including the <ranges> header. Add #include <ranges> at the top of the file.

Copilot uses AI. Check for mistakes.
Comment on lines +41 to 44
auto view() const {
return std::views::iota(size_t{0}, Size()) |
std::views::transform([this](size_t i) { return (*this)[i]; });
}
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required header for C++20 ranges. The view() method uses std::views::iota and std::views::transform which require including the <ranges> header. Add #include <ranges> at the top of the file.

Copilot uses AI. Check for mistakes.
Comment on lines +108 to 113
auto sub_view = args_->view() | std::views::drop(index_);
static_assert(std::ranges::sized_range<decltype(sub_view)>);

scratch->reserve(std::ranges::distance(sub_view));
std::ranges::copy(sub_view, std::back_inserter(*scratch));
return ArgSlice{scratch->data(), scratch->size()};
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required header for C++20 ranges. The code uses std::views::drop, std::ranges::sized_range, std::ranges::distance, and std::ranges::copy which require including the <ranges> header. Add #include <ranges> at the top of the file.

Copilot uses AI. Check for mistakes.
vector<string_view> mapped(vals.Size() + 1);
mapped[0] = key;
std::copy(vals.begin(), vals.end(), mapped.begin() + 1);
std::ranges::copy(vals.view(), mapped.begin() + 1);
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required header for C++20 ranges. The code uses std::ranges::copy which requires including the <ranges> header. Add #include <ranges> at the top of the file.

Copilot uses AI. Check for mistakes.
@dranikpg dranikpg changed the title chore(common): Use come c++20 chore(common): Use wome c++20 Jan 18, 2026
@dranikpg dranikpg changed the title chore(common): Use wome c++20 chore(common): Use some c++20 Jan 18, 2026
@kostasrim kostasrim self-requested a review January 19, 2026 07:27
@dranikpg dranikpg added this to the 1.38 milestone Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant