Boost logo

Boost :

Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2012-02-13 16:39:30

> 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
> 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
> because I had to create a dummy vector to be used as the default
> (The other alternative would have been to use a pointer, but then the
> 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 (,
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?


Boost list run by bdawes at, gregod at, cpdaniel at, john at