|
Boost Users : |
From: Graham Reitz (graham.cpp_at_[hidden])
Date: 2007-07-26 11:00:14
Great discussion! Thanks folks.
Also, I didn't know that tuples and struct are interchangeable.
Graham
On 7/26/07, Jeff Flinn <TriumphSprint2000_at_[hidden]> wrote:
>
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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