Skip to content

Add initializer-list operator= to VariableLengthArray (#70) - #240

Merged
thirtytwobits merged 1 commit into
mainfrom
claude/issue-70-vla-initializer-list-assign
Oct 18, 2026
Merged

thirtytwobits merged 1 commit into
mainfrom
claude/issue-70-vla-initializer-list-assign

Conversation

@thirtytwobits

Copy link
Copy Markdown
Member

Adds operator=(std::initializer_list) to cetl::VariableLengthArray, matching std::vector::operator= (3).

Both the general and the packed-bool specializations forward to assign(std::initializer_list) (from #238), so the operator has the same guarantees as that overload:

  • the allocator and max_size() are kept, and existing storage is reused when it is large enough
  • a list longer than max_size() throws std::length_error; with exceptions disabled the list is truncated to max_size()
  • allocation failure throws std::bad_alloc
  • returns *this

vla = {} now resolves to the new overload and clears the array, the same as std::vector.

Tests

New cases in test_variable_length_array_assign.cpp, typed over int and bool:

  • growing, shrinking, clearing, and re-growing across packed-byte boundaries, checked against std::vector
  • the returned reference
  • the logical maximum, with and without exceptions
  • reusing storage without allocating, and keeping the allocator and max_size()

Validation

  • GCC 13, C++14: all 11 VLA test suites pass in Debug and DebugEP (-fno-exceptions)
  • Clang, C++14 and C++20, with and without exceptions: the assign suite compiles cleanly with -Wall -Wextra -Werror -Wconversion -Wsign-conversion
  • clang-format 19.1.7 from toolshed:ts24.4.3 (the CI image) reports no changes for either file; git diff --check is clean

Closes #70.

🤖 Generated with Claude Code

Like std::vector::operator=(std::initializer_list), replace the contents
with the list while keeping the allocator and max_size(). Both the
general and the packed-bool specializations forward to
assign(std::initializer_list), so the operator shares its guarantees:
storage is reused when it suffices, lists longer than max_size() throw
std::length_error (or truncate with exceptions disabled), and
allocation failure throws std::bad_alloc.

Tests cover growing, shrinking, and clearing against std::vector,
`= {}` selecting the new overload, the returned reference, the logical
maximum, and storage, allocator, and max_size() retention.

Closes #70.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thirtytwobits

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T14:50:33.956019Z 0b999e9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 0b999e923b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@thirtytwobits
thirtytwobits merged commit 92e6302 into main Oct 18, 2026
29 checks passed
@thirtytwobits
thirtytwobits deleted the claude/issue-70-vla-initializer-list-assign branch October 18, 2026 15:02
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.

Add operator= that takes an initializer list to VLA

1 participant