Boost logo

Boost :

Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2012-02-13 16:58:26

Nathan Ridge wrote:

>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) ;

That's an interesting use case.

Default arguments are equivalent to overloading. You could write it as two functions:

void some_operation(inputs, vector<case>& special_cases, bool optimize_out_special_cases = false) ;

void some_operation(inputs) {
        vector<case> dummy;
        some_operation(inputs, dummy, true);

I think it would be more convenient for the users to use the overloaded functions over wrapping their vector in an optional.


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