Skip to content

Support C++23 monadic operators in OptionalRef#210

Open
alexkaratarakis wants to merge 3 commits into
teslamotors:mainfrom
alexkaratarakis:optional_ref_monadic
Open

Support C++23 monadic operators in OptionalRef#210
alexkaratarakis wants to merge 3 commits into
teslamotors:mainfrom
alexkaratarakis:optional_ref_monadic

Conversation

@alexkaratarakis

Copy link
Copy Markdown
Collaborator

No description provided.

@alexkaratarakis alexkaratarakis changed the title Optional ref monadic Support C++23 monadic operators in OptionalRef Jan 16, 2026
@alexkaratarakis alexkaratarakis force-pushed the optional_ref_monadic branch 2 times, most recently from cdf5d14 to 7075713 Compare January 21, 2026 20:47
{
if (has_value())
{
return std::invoke(std::forward<F>(func), *val());

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.

Should this std::move val? Or will *val() already be an rvalue when we're inside this special kind of method

Comment on lines +194 to +196
using InvokeResult = std::invoke_result_t<F, reference>;
static_assert(std::is_reference_v<InvokeResult>,
"transform() function must return a reference for OptionalReference");

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.

I think having this requirement makes transform() pretty useless (how often does a real function return a reference?). I think returning a std::optional is much more reasonable here, at least as a valid choice. It could even intelligently choose between the two return types based on the function 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.

2 participants