Skip to content

Add replacements for various STD types#58

Open
Shakai-Dev wants to merge 2 commits into
Redot-Engine:masterfrom
Shakai-Dev:std-replacements
Open

Add replacements for various STD types#58
Shakai-Dev wants to merge 2 commits into
Redot-Engine:masterfrom
Shakai-Dev:std-replacements

Conversation

@Shakai-Dev

@Shakai-Dev Shakai-Dev commented Jul 17, 2026

Copy link
Copy Markdown
Member
  • Adds replacements for various STD types such as std::vector, std::span, std::optional & std::expected

Summary by CodeRabbit

  • New Features
    • Added a dynamic, type-safe array with resizing, insertion, removal, clearing, iteration, and capacity management.
    • Added Optional for values that may be absent, including default-value access and reset support.
    • Added Expected and Unexpected for representing successful results or errors.
    • Added bounds-checked Span views for contiguous data, including subrange access.
  • Chores
    • Consolidated the container utilities under the shared containers module via public re-exports.

…pm), `std::expected` (Expected.cppm) & `std::optional` (Optional.cppm)
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dbad0fb8-f867-4836-9ea9-cff27994b7d4

📥 Commits

Reviewing files that changed from the base of the PR and between 73ae97e and e7770df.

📒 Files selected for processing (4)
  • Engine/cpp/Runtime/Core/Containers/Array.cppm
  • Engine/cpp/Runtime/Core/Containers/Expected.cppm
  • Engine/cpp/Runtime/Core/Containers/Optional.cppm
  • Engine/cpp/Runtime/Core/Containers/Span.cppm
🚧 Files skipped from review as they are similar to previous changes (4)
  • Engine/cpp/Runtime/Core/Containers/Expected.cppm
  • Engine/cpp/Runtime/Core/Containers/Optional.cppm
  • Engine/cpp/Runtime/Core/Containers/Span.cppm
  • Engine/cpp/Runtime/Core/Containers/Array.cppm

📝 Walkthrough

Walkthrough

Adds exported C++20 modules for owning dynamic arrays, optional and expected value states, and non-owning spans. The aggregate containers module now re-exports all four modules.

Changes

Core container modules

Layer / File(s) Summary
Dynamic array storage and API
Engine/cpp/Runtime/Core/Containers/Array.cppm
Adds allocator-backed storage, growth and relocation handling, RAII ownership, move support, insertion and removal operations, accessors, and iterators for Array<T>.
Optional and Expected value states
Engine/cpp/Runtime/Core/Containers/Optional.cppm, Engine/cpp/Runtime/Core/Containers/Expected.cppm
Adds union-backed Optional<T> and Expected<T, E> types with lifecycle management, state queries, checked accessors, and error wrappers.
Non-owning spans and public exports
Engine/cpp/Runtime/Core/Containers/Span.cppm, Engine/cpp/Runtime/Core/Containers/Containers.cppm
Adds bounds-checked Span<T> construction, access, iteration, and subspan operations, then re-exports the container modules.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: mcdubhghlas, olddev78

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding replacement implementations for several standard library container types.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Engine/cpp/Runtime/Core/Containers/Array.cppm`:
- Around line 48-54: Update Reserve to reject negative newCapacity and itemSize
values, and validate that itemSize is nonzero and newCapacity does not exceed
the maximum representable size divided by itemSize before evaluating newCapacity
* itemSize. Return the appropriate error for invalid or overflowing inputs while
preserving the existing allocation path for valid capacities.
- Around line 209-240: Update Array::Push overloads and Emplace to preserve
arguments that reference existing elements across internal.GrowCapacity, since
growth may relocate and free the source storage before construction. Stage
aliased lvalue, rvalue, and Emplace arguments before growth, or change the
growth sequence so insertion occurs before releasing the old buffer, while
preserving existing error handling and insertion behavior.
- Around line 167-183: Update Array::operator=(Array&&) to transfer
other.internal.allocator to the destination before or alongside stealing its
buffer, size, and capacity, ensuring the moved-to array frees the allocation
with the original allocator; reset the moved-from allocator as appropriate for
its empty state.
- Around line 109-123: Update RelocateElements to handle exceptions from T’s
move constructor: require and enforce nothrow move construction, or catch
failures to destroy all already-constructed destination elements and release the
newly allocated buffer before rethrowing. Preserve the existing trivially
copyable memcpy path.
- Around line 271-274: Update Array::end() and its const overload in
Engine/cpp/Runtime/Core/Containers/Array.cppm (lines 271-274) to return Data()
directly when internal.size is zero, avoiding null-pointer arithmetic while
preserving normal end-pointer calculation for non-empty arrays. Apply the same
change to Span end iterators in Engine/cpp/Runtime/Core/Containers/Span.cppm
(lines 37-38), returning buffer directly when count is zero.

In `@Engine/cpp/Runtime/Core/Containers/Optional.cppm`:
- Around line 85-93: Update Optional’s move assignment operator near
Engine/cpp/Runtime/Core/Containers/Optional.cppm:85-93 to use T’s nothrow
move-constructibility, matching its placement-new reconstruction. Also update
Expected’s move constructor near
Engine/cpp/Runtime/Core/Containers/Expected.cppm:51-56 so its noexcept condition
requires both T and E to be nothrow move-constructible.

In `@Engine/cpp/Runtime/Core/Containers/Span.cppm`:
- Around line 19-20: Update the Span(T* ptr, isize size) constructor to reject
negative sizes, and update Subspan to accept only length == -1 or nonnegative
lengths. Validate requested lengths against count - offset rather than offset +
length, while preserving existing bounds behavior and preventing invalid
negative-sized spans.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e660228-67ca-4706-b153-aad71fa56ab5

📥 Commits

Reviewing files that changed from the base of the PR and between 53097f5 and 73ae97e.

📒 Files selected for processing (5)
  • Engine/cpp/Runtime/Core/Containers/Array.cppm
  • Engine/cpp/Runtime/Core/Containers/Containers.cppm
  • Engine/cpp/Runtime/Core/Containers/Expected.cppm
  • Engine/cpp/Runtime/Core/Containers/Optional.cppm
  • Engine/cpp/Runtime/Core/Containers/Span.cppm

Comment thread Engine/cpp/Runtime/Core/Containers/Array.cppm
Comment thread Engine/cpp/Runtime/Core/Containers/Array.cppm
Comment thread Engine/cpp/Runtime/Core/Containers/Array.cppm
Comment thread Engine/cpp/Runtime/Core/Containers/Array.cppm Outdated
Comment thread Engine/cpp/Runtime/Core/Containers/Array.cppm Outdated
Comment thread Engine/cpp/Runtime/Core/Containers/Optional.cppm Outdated
Comment thread Engine/cpp/Runtime/Core/Containers/Span.cppm Outdated
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