From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2005-03-01 22:37:03
Joao Abecasis wrote:
> Fernando Cacciola wrote:
>>> Maybe boost::reference_wrapper can be used internally to wrap
>>> reference types and solve this issue.
> I was suggesting the use of reference_wrapper to avoid singling out
> reference types everywhere in the code. The new assignment operators
> might just work.
Ha, well, optional<> uses make_reference_content<> (from variant<>) so I
don't even need to distinguish between reference and non-reference types
except were explicitely needed.
In fact, the new assignment operators "just work" in this case with no need
of special dispatching code.
> Anyway, I haven't tested any of this so...
> I suggest you document how users may workaround this issue in their
> code using boost::reference_wrapper/ref/cref. Here's a small snippet
> you can use.
> #include <boost/optional.hpp>
> #include <boost/none.hpp>
> #include <boost/ref.hpp>
> int main()
> int a = 32;
> int b = 1279;
> boost::reference_wrapper<int> ra(a);
> boost::optional<boost::reference_wrapper<int> >
> orw1, // default constructor
> orw2(boost::none), // none_t constructor
> orw3(ra), // value constructor
> orw4(boost::ref(a)); // make reference
> boost::optional<int &> ori1(orw1),
> orw1 = boost::ref(b);
> Best regards,
I can at least tell users how to get the "old" semantics if they really need
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk