Boost logo

Boost Users :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2007-07-26 08:46:41


Graham Reitz wrote:
> Ok good. So it sounds like my concern isn't justified.
>
> To be certain. Because of tuples I prefer this:
>
> typedef boost::tuples::tuple<unsigned int, double> some_pair;
> typedef std::vector<some_pair > some_pairs;
>
> to this:
> struct some_pair
> { unsigned int i; double d; };
> typedef std::vector<some_pair > some_pairs;
>
> Is tuples meant to be used like the first example?

I use tuples or fusion containers when the names of the data members
have no meaning, and you want to iterate over the members in some way.
Your example, with it's members i and d, obviously falls into this
category. ;)

I've also used tie to get the best of both worlds:

class tire_size
{
    int width;
    int aspect_ratio;
    string speed_rating;
    int wheel_diameter;
public:

    ...

    bool operator<( const tire_size& rhs )const
    {
       return tie( width
                 , aspect_ratio
                 , speed_rating
                 , wheel_diameter
                 )
            < tie( rhs.width,
                 , rhs.aspect_ratio
                 , rhs.speed_rating
                 , rhs.wheel_diameter
                 );
    }
};

int main()
{
    tire_size summer911turbo(295,30,"Z",18);
    tire_size winter911rurbo(265,35,"H",18);

    bool b = winter911turbo < summer911turbo;

    return 0;
};

Jeff Flinn


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