Skip to content

[libcu++] Change inplace_vector return type for try_meow methods#9130

Open
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:fix_inplace_vector_try_return_type
Open

[libcu++] Change inplace_vector return type for try_meow methods#9130
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:fix_inplace_vector_try_return_type

Conversation

@davebayer
Copy link
Copy Markdown
Contributor

@davebayer davebayer commented May 26, 2026

This PR implements part of P3981R2 that changes inplace_vector return types for try_meow methods.

I've not updated the feature testing macro value, because there is another paper that we don't currently implement and they share the same macro value.

This is a source breaking change, but it's consistent what other standard libraries do when a feature is changed before the standard release.

@davebayer davebayer requested a review from a team as a code owner May 26, 2026 13:41
@davebayer davebayer requested a review from ericniebler May 26, 2026 13:41
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 26, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 26, 2026
#include <cuda/std/__memory/uninitialized_algorithms.h>
#include <cuda/std/__new/device_new.h>
#include <cuda/std/__new/launder.h>
#include <cuda/std/__optional/optional_ref.h>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@miscco should I only include this header or rather full <cuda/std/optional>?

@davebayer davebayer force-pushed the fix_inplace_vector_try_return_type branch from 643ec6f to bc683a6 Compare May 26, 2026 13:44
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2740df5c-fa6d-438b-8a6e-6c70f5f7a93a

📥 Commits

Reviewing files that changed from the base of the PR and between 8623dab and bc683a6.

📒 Files selected for processing (2)
  • libcudacxx/include/cuda/std/inplace_vector
  • libcudacxx/test/libcudacxx/std/containers/sequences/inplace_vector/emplace.pass.cpp

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • inplace_vector methods try_emplace_back and try_push_back now return optional<reference> instead of raw pointers.
    • Capacity failures return nullopt instead of nullptr for improved type safety and consistent error handling.

Walkthrough

The PR changes inplace_vector's try_* insertion methods (try_emplace_back, try_push_back with const and rvalue variants) from returning raw pointers to returning optional<reference>. When the vector is full, these methods return nullopt; on success, they return an optional engaged with a reference to the inserted element. Both the general template and zero-capacity specialization are updated, along with test assertions.

Changes

Try_ API contract change*

Layer / File(s) Summary
Try_ return type update to optional reference*
libcudacxx/include/cuda/std/inplace_vector
Include optional_ref.h. Update try_emplace_back and both try_push_back overloads in the general template to return nullopt when full, otherwise an engaged optional<reference> from unchecked_emplace_back. Update zero-capacity specialization to always return nullopt.
Test assertions for optional-based try_ results*
libcudacxx/test/libcudacxx/std/containers/sequences/inplace_vector/emplace.pass.cpp
Include <cuda/std/optional>. Update all try_* test assertions to expect optional<reference> return type, using res.value() for element access and assert(!res) for full-capacity failure cases.

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

@github-actions
Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 15m: Pass: 100%/116 | Total: 5d 05h | Max: 3h 14m | Hits: 39%/2072236

See results here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

1 participant