Boost logo

Boost :

Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-02-13 17:15:01


> From: akrzemi1_at_[hidden]
>
> > I use optional references in my code, in cases like the following:
>
> > I have an operation, which processes some elements, and some of the
> > elements constitute special cases. The caller of the operation may or may
> > not want to know about the special cases that arose, so they can
> optionally
> > pass in a container which will be populated with the special cases:
>
> > void some_operation(inputs, optional<vector<case>&> special_cases = none)
> > {
> > for (...)
> > {
> > ...
> > if (special_case)
> > {
> > ...
> > if (special_cases)
> > special_cases->push_back(current_case);
> > }
> > }
> > }
>
> > Before I discovered optional, I used a plain reference, but that was
> annoying
> > because I had to create a dummy vector to be used as the default
> argument.
> > (The other alternative would have been to use a pointer, but then the
> caller
> > has to use the uglier syntax of passing in "&special_cases" rather than
> > "special_cases").
>
> Nathan, going back to the same question I asked Andrey (
> http://groups.google.com/group/boost-developers-archive/msg/704971a1eb63b3d2),
> it looks like your use case would still work if we disabled any sort of
> assignment for optional references (even the assignment from boost::none
> for resetting). Am I correct?

You are correct. I was providing a use case for optional references in general,
not one for assignment to optional references. (That's not to say I think use
cases for assignment to optional references don't exist - I just  don't have one
in mind right now).

Regards,
Nate
                                               


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk