Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add maybe concept and maybe_view #1659

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

huixie90
Copy link
Contributor

@huixie90 huixie90 commented Sep 20, 2021

In the original famous Pythagorian Triples blog, there is a maybe_view in the example.

There was also a proposal to the standard to have maybe_view but there isn't any update on that paper
http://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p1255r6.html

However, I don't agree with paper about the nullable concept.

First, why don't we call the concept maybe given that the view is called maybe_view.
Second, I don't think it is a good idea to couple operator bool and operator * with the concept. In the paper itself, there was already a special case reference_wrapper. In real world use case, I believe there will be lots of types, which can represent a null value without operator *. For example, std::function, std::future, std::variant<std::monostate, Foo, Bar>

I think it might be a good idea to create some Customisation Points, which can default to operator bool and operator *. Originally the paper had two customisation points maybe_has_value and maybe_value but they got removed from R0 version, which I can't find the reason for

I propose to have two customisation points and support types that can represent null but don't have operator bool or operator *:
is_just and get_just

In this pull request, except the concept, the implementation is pretty much the same as what it was proposed in that paper.

Feedback welcome!

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.

None yet

1 participant