Skip to content

Add tuple protocol support for singular copacks - #435

Merged
Bronek merged 2 commits into
mainfrom
bronek/singular_copack_tuple_like
Sep 25, 2026
Merged

Bronek merged 2 commits into
mainfrom
bronek/singular_copack_tuple_like

Conversation

@Bronek

@Bronek Bronek commented Sep 24, 2026

Copy link
Copy Markdown
Member

A copack with exactly one alternative now supports structured bindings through tuple traits and ADL get<0>. Bindings expose the alternative instead of the public data and index members, including when accessing a singular choice's payload through value(). The protocol is limited to singular copacks. Both get overloads reject volatile copacks through constraints, avoiding the previous hard error when probing index-less access.

Closes #416

Provide tuple_size, tuple_element and ADL get<0> for copack<T>.
Structured bindings now expose the alternative rather than the
public storage members. Empty and wider copacks remain excluded.

Preserve const qualification and value category in get, and reject
volatile copacks through constraints. A pack alternative remains
one tuple element; fn::apply still expands its fields.

Cover tuple traits, reference access, structured bindings, choice
payload mutation and apply dispatch.

Assisted-by: Claude:claude-opus-5-5
@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@augmentcode

augmentcode Bot commented Sep 24, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR makes singular fn::copack<T> model the C++ tuple protocol.



Changes:

  • Adds `std::tuple_size` and `std::tuple_element<0>` specializations for one-alternative copacks.
  • Adds constrained ADL-visible `fn::get<0>` that forwards to the existing index-less accessor.
  • Constrains both copack `get` overloads through `some_copack`, excluding volatile operands cleanly.
  • Keeps empty and multi-alternative copacks outside the tuple protocol.
  • Preserves a pack alternative as one tuple element, while `fn::apply` continues to unpack it.
  • Documents the protocol in the type algebra, API reference, and changelog.
  • Expands tests for cv/ref categories, constraints, traits, ADL, structured bindings, and choice payloads.
  • Adds functional coverage distinguishing `fn::apply` copack dispatch from `pfn::apply` tuple-like rules.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot 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.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@sonarqubecloud

Copy link
Copy Markdown

@Bronek
Bronek merged commit 1e06ba1 into main Sep 25, 2026
59 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.

Give the singular copack the tuple protocol

1 participant