Adds forwarding make_optional helpers, resolves #30#31
Adds forwarding make_optional helpers, resolves #30#31akrzemi1 merged 1 commit intoboostorg:developfrom
Conversation
|
The code you highlighted triggers uses |
| return optional<BOOST_DEDUCED_TYPENAME boost::decay<T>::type>(cond,boost::forward<T>(v)); | ||
| } | ||
|
|
||
| #else |
There was a problem hiding this comment.
Was it intended to remove the l-value methods with this #else?
I'm getting a compile error trying to make an optional from a variable, e.g. float x = 1; make_optional<float>(x);
(without -DBOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
There was a problem hiding this comment.
Function make_optional is not intended to be used like this, with template arguments specified explicitly. The only purpose of function make_optional is to spare you the trouble of specifying the type of optional value. If you want to specify it yourself, you have a simpler version:
float x = 1; boost::optional<float>(x);Macro BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES is not intended to be defined by users. The library defines it when it detects old compilers without rvalue reference support.
There was a problem hiding this comment.
Sorry I missed some detail… I was attempting to use boost::make_optional<T>(bool, T) to simplify the following:
float value;
bool valid = GetValidAndValue(&value);
// return valid ? boost::optional<float>(value) : boost::none;
return boost::make_optional<float>(valid, value);
True it is not a huge simplification - but should that be possible?
There was a problem hiding this comment.
Again, same response. If you can afford spelling out the type of optional value use:
return boost::optional<float>(valid, value);If you want to the type of optional value to be deduced use:
return boost::make_optional(valid, value);There was a problem hiding this comment.
IOW, make_optional is only used for type deduction.
For #30. The varargs overloads probably make no sense with the
boolargument at the second position?I don't quite understand why the
test/optional_test_fail_copying_a_moveable_type.cppfails to compile here (unrelated to this changeset) - shouldn't construction from a moveable-only type work?Also how can I provide docs for the overload depending on if rvalue refs are enabled or not? I found the quickbook files in
docI'm just wondering what the best way to document the overloads is.cc @akrzemi1