Boost logo

Boost Users :

Subject: [Boost-users] mpl: POD decoration with constructors and getters/setters
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-12-10 10:08:44

I posted a question to comp.lang.c++ first and now realize this maybe a mpl
or PP question as well.
Here is the original question:

> 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?
>> 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.

A response came as:
> 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;
> };

My intial email not being clear, further clarifications are here:

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 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::optimize function would then return the "optimal" S, along with the
maximum/minimum double found.
The details and meaning of the optimization would be specific to

Best regards,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at