|
Boost : |
From: Joao Abecasis (jpabecasis_at_[hidden])
Date: 2005-03-01 13:44:14
Fernando Cacciola wrote:
>>Maybe boost::reference_wrapper can be used internally to wrap reference
>>types and solve this issue.
>>
>
> How?
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.
Anyway, I haven't tested any of this so...
> We're not talking about an implementation problem here; this is about the
> "correct" behaviour and whether is ok to change to it given the potential
> impact on user programs.
I see. In that case, please disregard my previous suggestion... I'll
make a new one, hopefully more helpful ;)
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),
ori2(orw2),
ori3(orw3.get());
orw1 = boost::ref(b);
}
Best regards,
João
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk