"Victor Bazarov" <> wrote in message
news:hfohnd$vvh$...
> Hicham Mouline wrote:
>> I have functions that each take 1 parameter. This parameter is of type
>>
>> struct S {
>> <arithmetic_or_bool_type_1> member_name_1;
>> <arithmetic_or_bool_type_n> member_name_n;
>> }; // n can be of order 10 or so
>>
>> class C {
>> public:
>> return_type apply( const S& ) const;
>> };
>>
>> Now I want to optimize the returned value.
>
> "Optimize"?
>
>> I would optimize by fixing any subset of the n members fixed, ie none at
>> all, or just member 5, or members 4 and 8, or members 7,3 and n, or n-1
>> members of the {1....n} set.
>>
>> How can I do this?
>
> If your 'return_type' has to be the same *type*, there is no better
> solution than to return an 'S', if the members that you don't want to
> "return" are set to some "invalid" value. As an alternative you could
> consider supplying another member to 'S', which would indicate the "valid"
> or "active" members. You can have another (nested) struct in 'S' with bit
> fields:
>
> struct S {
> ... // as you have now
> struct {
> unsigned use_1:1;
> unsigned use_2:1;
> ...
> unsigned use_n:1;
> } which_members_to_use;
> };
>
>>
>> maybe
>>
>> class C{
>> public:
>> pair<return_type, S> optimize(...) const; // returns the optimum S
>> that gives the best return value
>
> What's "return_type" here? What does it mean for the return value to be
> "the best"?
>
>> };
>>
>> Some interface like this looks nice to me (as a user).
>>
>> The question is how to pass the fixed members to optimize.
>
> It is unclear what solution would be better since you've not explained
> what problem you're trying to solve with this mechanism.
>
> V
I apologize for being unclear.
return_type is just double.
C c;
S s1;
c.apply( s1 ); //// returns double , say 15.0
By optimize, I mean in most cases maximize, but sometimes minimize.
So I'm trying to get the largest double by changing parts or all of s1.
I was thinking of some metaprogramming magic that would generate
automatically S constructors with arguments all the possible subsets of the
member fields, and depending on the ctor selected by the user, would set
those bits or bools in the nested struct appropriately. This could generate
also getters/setters that the optimize function could use .
This could be a metafunction that returns a type SS based on the type S.
I realize this is definitely a question for boost as well.
The C:

ptimize function would then return the "optimal" S, along with the
maximum double found.
The details and meaning of the optimization would be specific to
C:

ptimize.
Best regards,