Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] named parameter technique with fusion::map
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-11-08 00:33:09


On 11/06/10 08:26, Christopher Schmidt wrote:
> comments inline...
>
> alfC schrieb:
[snip]
>> One question: Why I can not interchange the order of p and q in the
>> last call, after all it is a map at the library could in principle
>> differentiate the pairs? making it possible to call an unordered named
>> parameter. e.g.
>> cout << H(
>> map<pair<p, double>, pair<q, double> >(
>> make_pair<q>(2.), // was p
>> make_pair<p>(1.) // was q
>> )
>> );
>> Is it possible to interchange the order to give more flexibility to
>> the user?
>
> I don't think that this is a good idea. Reordering is a quite expensive
> operation and it would really slow down compile times. On top of that,
> fusion::map is a forward sequence which has a definite order (!) on its
> elements. Reordering does not feel natural here.
> Having that said, you can easily write your own, reordering associative
> sequence or you can construct your map from another another fusion
> sequence that you reorder on the fly, for example via fusion::nview .
>
The attached produces output:

-------------------------
default values for tuple:
-------------------------
at1=ti<1>(-1)
at2=ti<2>(-1)
at3=ti<3>(-1)
-------------------------------
named/default values for tuple:
-------------------------------
at1=ti<1>(1)
at2=ti<2>(2)
at3=ti<3>(-1)
================================

The args to pairs_nam_ti1_3_t CTOR could be the
args to some map-like structure and then, inside
that CTOR, a pairs_nam_ti1_3_t could be constructed
and used to fill the map.

It doesn't look too compile-time expensive, but
I've done no measurements.

HTH.

-Larry




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net