-
Notifications
You must be signed in to change notification settings - Fork 68
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
implicit constructor not working #95
Comments
This is by design. The constructor of |
I'm not sure why the gotcha applies here. It's caused by |
Yes, you're right: the gotcha is not directly related to the design decision. Sorry. So, let me rephrase my response. |
Yeah, here's the thing though. Is
while
Doesn't work. People already complain about libraries that use boost::error_code instead of std::error_code (e.g. asio) and that use boost::string_view instead of std::string_view. I think there is benefit to enabling practical usage even if it comes at the expense of some esoteric theoretical use-cases. |
When template <typename T>
void genericFun(const T& v)
{
optional<T> optV = v;
assert(bool(optV)); // wil it pass for *every* T?
}
optional<int> myValue;
genericFun(myValue);
The definition of "better" is not clear here. With
Can you provide an example of how
I can see how this is problematic. Is this the only use case that really shows up in practice? Because this one could be addressed in a different way. I will investigate if enabling
The way I see it, we are talking here about the trade-off where you get a convenience feature that does what you expect in 95% of the cases, and in the remaining 5% cases it compiles and does something opposite to what you expect at runtime. This doesn't sound like the right trade-off for me. But I might be wrong about the "does something opposite to what you expect", so, as I said, I will investigate this. |
Comparing |
Thanks to Peter I am now unsure if the comparison should work. Because of this, I am trending away from optional entirely, in my interfaces (working on Boost.URL at the moment). However, I still think there could be value in offering a drop-in replacement for |
@pdimov what do you mean by "fails" here? I would take that word to mean that it either asserts, throws an exception, or is violating some precondition. But that doesn't seem to be the case: https://godbolt.org/z/dTTerTzch. It correctly evaluates to true, because That said, I could see the ordered relop results being surprising, but that is the cost of imposing a total order over all states of a type (assuming that |
"Fails" in the sense that it often behaves in a way that fails to meet the (original or maintenance) programmer's expectation. I know that it's formally correct, because |
This issue is similar to the closed #96. For now, it is only in branch |
Boost users on C++11 and C++14 have few choices for accessing
It is useful to have a diverging implementation, but this doesn't serve the need for users who just want to support older versions of C++ by using an identical polyfill. I think there is value in also having a |
Strictly speaking, is will never be a drop-in replacement for |
calls to
f3
andf4
do not compile:https://godbolt.org/z/K4c1edTK3
The text was updated successfully, but these errors were encountered: