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

support references as bounded types? #5

Open
HDembinski opened this issue Feb 17, 2019 · 3 comments
Open

support references as bounded types? #5

HDembinski opened this issue Feb 17, 2019 · 3 comments

Comments

@HDembinski
Copy link

variant2 cannot have references as bounded types, https://godbolt.org/z/mnP-CU, which is conforming with std::variant, but this could be another improvement over std::variant if it is not too much work to implement. boost::variant is supporting them and I am using this in boost.histogram in this function
https://github.com/HDembinski/histogram/blob/5ae08d40c26f8db0613545b84a4c0b60c3729102/include/boost/histogram/detail/axes.hpp#L47
which allows me to get a reference to an element of a std::tuple with a run-time index.

Related SO question:
https://stackoverflow.com/questions/54218595/why-are-references-forbidden-in-stdvariant

@pdimov
Copy link
Member

pdimov commented Feb 17, 2019

As explained in the SO answer, there's disagreement over assignment. To take your case as an example, if I assign to the return value of axis_get, what should happen?

@HDembinski
Copy link
Author

HDembinski commented Feb 17, 2019

I argued in the SO question discussion that I would except a variant which currently holds a reference to act like a reference, so assignment should pass through, not rebind. But I understand from your comments on cpplang slack that you want to keep this open as long as it is open for std::variant, which makes perfect sense.

@HDembinski
Copy link
Author

I think this should be closed. If variant2 is to be a drop-in replacement for std::variant with the exact same interface and behavior, support for references cannot be implemented.

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

No branches or pull requests

2 participants