Skip to content

Should & keep lvalue-reference payloads of optional<T&>? #449

Description

@Bronek

operator& copies out of lvalue-reference payloads. On main, optional<int&> & optional<int> is optional<pack<int, int>> and optional<int&> & optional<long&> is optional<pack<int, long>>: each factor is the carrier's value_type, which is T for optional<T&>.

The change for #448 makes the disjunction keep reference payloads: optional<int&> | optional<long&> becomes optional<copack<int&, long&>>. After it, | and & treat the same operands differently. This issue asks whether & should also take its factors from the payload type, so that optional<int&> & optional<int> is optional<pack<int&, int>>.

For keeping references

For copying

  • Appending a plain value to a product copies it: as_pack(x) & y is pack<int&, long>. A reference enters a product only through an explicit lift, and a carrier operand could be read as a plain value.

Affected either way

The referent's cv-qualification leaks into the product: optional<int const&> & optional<long&> is optional<pack<int const, long>>. Keeping references gives pack<int const&, long>; copying should give pack<int, long>.

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions