Repository navigation
Conversation
Add `just<T&>` with rebinding assignment and emplace. Access preserves the lvalue reference regardless of the carrier's constness or value category. Transform can preserve supported reference results. Reject copack referents and joins of differing result types that include reference payloads. Document the lifetime limitations and cover reference construction, rebinding, callable operations, and joins in tests. Assisted-by: Claude:claude-opus-5-5
🤖 Augment PR SummarySummary: This PR adds non-owning lvalue-reference payload support to
🤖 Was this summary useful? React with 👍 or 👎 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Member
Author
|
augment review |
Assisted-by: Claude:claude-opus-5-5
An rvalue owning `just` passes its payload to the callback as an rvalue, so a reference result may refer into a payload that expires with the carrier. `optional<T>` accepts such results as C++26 specifies; `just` diverges deliberately. Assisted-by: Claude:claude-opus-5-5
Member
Author
|
augment review |
How a reference to a product or a sum takes part in conjunction, disjunction and grading is an open question, so `just<T&>` and `fn::optional<T&>` refuse both until the type algebra answers it. Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-opus-5-5
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



just<T&>now supports references to object types other than arrays,std::in_place_typetags and copacks, providing an always-engaged counterpart to C++26optional<T&>. Rvalue-reference payloads remain unsupported, as inoptionalandpack.Semantics
emplacerebind the reference; they do not assign to the referent.value()returnsT&, and callables receiveT&, regardless of the carrier's value category or constness.value_typeisT, as foroptional<T&>.int x,just{x}deducesjust<int>. An explicit type tag permits reference deduction:just(std::in_place_type<int&>, x)deducesjust<int&>.apply_typetags the payload withstd::in_place_type<T&>.Effects on composition
transformcallback returningU&producesjust<U&>, which refers to the returned object. Value results still produce owning carriers.justused as an rvalue rejects atransformcallback returningU&: the reference may refer into the payload, which expires with the carrier. For example,auto r = make_cfg_just() | fn::transform(&Cfg::get);withint const &Cfg::get() constwould otherwise leaverdangling, and neither GCC nor Clang warns about it at-O0. The member rejects the result through astatic_assert, and the pipeline functor through its constraints.optional<T>accepts such a result, as C++26 specifies;justdeliberately diverges here. Lvalue carriers andjust<T&>of any value category still producejust<U&>.and_thenreturns the samejust<U&>type, the result retains that type. A join of different result types is rejected if any is a referencejust, because references cannot be alternatives of the resulting choice. This matches the existing restriction on reference results in optional joins. A constrained partial specialization of_joining_superset_typelets both the member and pipeline functor reject these joins through constraints rather than hard errors.&and|copy the referent, as they do foroptional<T&>. The unitjust<void>is an exception:&returns the other operand, sojust<void>{} & just<T&>{x}still producesjust<T&>.Copack references remain unsupported
A
static_assertrejectsjust<copack<Ts...> cv &>for everyTs.... Atransformcallback returning a copack reference also remains unsupported. Such a carrier would dispatch on the referent's active alternative, introducing control flow based on state it does not own. #434 discusses the tradeoffs and open questions. The empty case,just<copack<> &>, is uninhabited and remains unsupported regardless of that decision.Known limitations and follow-up work
optional<T&>, binding to a temporary is not rejected:just<int const&> j{42};compiles but leaves a dangling reference. The C++26 guard requires the C++23 traitreference_constructs_from_temporary; the doc comment records this limitation.|does not handle const referents correctly:just<int const&> | just<int const&>andjust<int const&> | just<int>produce hard errors.optional<int const&> | just<int>has the same problem onmain.&works; fixing|is shared follow-up work.just<T&>::and_thensharesand_thenoverlooks the copy when a callback returns a carrier by reference #436 with the other carriers'and_then: when a callback returns a carrier by lvalue reference, the member copies it but neither itsnoexceptnor its constraints account for that copy.and_thenoverlooks the copy when a callback returns a carrier by reference #436 tracks the fix across all carriers.TYPE_ALGEBRA.mdstill says that carriers other thanoptionalreject references. That sentence is updated onbronek/type_algebra_articleto avoid a merge conflict. Section 15 is updated here.Tests
The new
just of referencetest case covers construction, deduction, special members, use as a structural template argument, accepted and rejected referent types, rebinding, access, comparisons, and composition. Callable tests verify that even an rvalue carrier passesT&, with owningjustcases for comparison.and_then.cppcovers joins with matching and differing result types through the member, pipeline functor, and identityexpectedcrossing, plus a bridge tooptional<int&>.transform.cppnow checks that lvalue-reference results are accepted from lvalue carriers and from a temporaryjust<T const&>, rejected from rvalue owning carriers, and that rvalue-reference results remain rejected.Local validation passed with g++ 16.2.1 and clang++ 22.1.8 in Debug, Release, and C++23-validate configurations, plus GCC's
LIBFN_CXX26configuration and Clang with libc++ and sanitizers. Documentation signature and coverage checks using the host Doxygen found no new mismatches against aHEADbaseline. Znai and MSVC validation remain for CI.Closes #417