Skip to content

[v26.2.x] core: put c++23 range c-tor back in chunked_vector#294

Merged
WillemKauf merged 1 commit into
redpanda-data:v26.2.xfrom
WillemKauf:chunked-hash-map-v26.2.x
Jun 30, 2026
Merged

[v26.2.x] core: put c++23 range c-tor back in chunked_vector#294
WillemKauf merged 1 commit into
redpanda-data:v26.2.xfrom
WillemKauf:chunked-hash-map-v26.2.x

Conversation

@WillemKauf

Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings June 30, 2026 19:27

Copilot AI left a comment

Copy link
Copy Markdown

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 restores a C++23 std::from_range constructor for seastar::chunked_vector, guarded by the standard library feature macro, and adds unit tests to validate construction from common ranges and move/copy element behavior.

Changes:

  • Add chunked_vector(std::from_range_t, Range&&) constructor (C++23, feature-gated) with sized_range pre-reserve.
  • Add unit tests for from_range construction from sized/unsized ranges and move-only element scenarios (feature-gated).

Reviewed changes

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

File Description
include/seastar/core/chunked_vector.hh Adds C++23 std::from_range constructor for chunked_vector.
tests/unit/chunked_vector_test.cc Adds unit tests covering from_range construction and element move/copy semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +154 to +163
template <typename Range>
requires(std::ranges::range<Range>)
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
chunked_vector(std::from_range_t, Range &&range) : chunked_vector() {
if constexpr (std::ranges::sized_range<Range>) {
reserve(std::ranges::size(range));
}
std::copy(std::ranges::begin(range), std::ranges::end(range),
std::back_inserter(*this));
}
Comment on lines +593 to +598
BOOST_AUTO_TEST_CASE(FromRangeUnsized) {
std::list<int32_t> input{1, 2, 3, 4, 5};
auto vec = chunked_vector<int32_t>(std::from_range, input);
ASSERT_VALID(vec);
BOOST_REQUIRE(std::ranges::equal(vec, input));
}
Comment on lines +611 to +632
BOOST_AUTO_TEST_CASE(FromRangeMove) {
static_assert(
!(std::is_copy_constructible_v<move_only_t>
|| std::is_copy_assignable_v<move_only_t>));

auto src = chunked_vector<move_only_t>();
src.emplace_back();
src.emplace_back();

// From ref.
auto vec = chunked_vector<move_only_t>(
std::from_range, src | std::views::as_rvalue);
ASSERT_VALID(vec);
BOOST_REQUIRE_EQUAL(vec.size(), 2u);

// From temporary.
auto vec2 = chunked_vector<move_only_t>(
std::from_range, chunked_vector<move_only_t>() | std::views::as_rvalue);
ASSERT_VALID(vec2);
BOOST_REQUIRE(vec2.empty());
}

@WillemKauf WillemKauf changed the title core: put c++23 range c-tor back in chunked_vector [v26.2.x] core: put c++23 range c-tor back in chunked_vector Jun 30, 2026
@WillemKauf WillemKauf merged commit 4027b6e into redpanda-data:v26.2.x Jun 30, 2026
20 checks passed
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.

3 participants