Zeljko Vrba wrote:
I'm operating on two vectors of pairs of numbers, currently represented by std::pair
. The first vector is a list of (net,pin) pairs, while the second vector is a list of (pin, net) pairs. In order to raise a bit the understandability / abstraction level of my code, I think that it'd be nice to be able to write at_key<pin>(x) and at_key<net>(x) instead of x.first or using tie().
Looking at fusion manual, it seems that of all the containers, map suits the purpose:
struct pin; struct net;
First question: are Map1 and Map2 different types?
typedef map
, pair > Map1; typedef map , pair > Map2;
Yes.
According to a simple test program that I wrote, which basically boils down to Map m1; Map m2; m1 = m2; they, are different because the compilation fails. Hmm, so far, so good.
Second question: some algorithms are common both for both types, e.g. sort, where I want to have lexicographical comparison between the elements. Is it possible to somehow transform Map1 and Map2 so that they both appear as
typedef vector
> Pair
Yes: transform_view. It won't be a fusion vector, but the effect is what you want.
with proper lexicographical ordering? OK, there are conversion metafunctions, but I want something more; the following code
std::vector<Map1> m; std::sort(m.begin(), m.end());
should process vector elements (Map1s) _as_if_ they were Pairs or ordinary std::pair. I see there are conversion metafunctions defined in documentation, but I don't know how to use them to convert std::vector<Map1> to std::vector<Pair> when giving m as argument to sort() [if this is possible at all].
Sorry for the long post and if it is somewhat vague.
===
(I could probably avoid using fusion by manually defining two different struct types, each holding pin/net members and defining operator< for each, but I want to finally get my hands dirty with fusion on a concrete, not too complex problem that I'm facing right now.)
Sounds good. One step at a time. Tell us if you need some help/advice on various issues. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net