|
Boost Users : |
Subject: Re: [Boost-users] [Tuple] What's the point?
From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2009-07-10 04:35:24
On Fri, Jul 10, 2009 at 09:13:39AM +0100, Robert Jones wrote:
>
> So have I entirely missed the point of tuples?
>
The point is that tuple<int,int> is the same type as any other tuple<int,int>.
With ad-hoc structures,
struct A {int x, y; };
struct B {int x, y; };
the two are completely different types, so you can't write f.ex., a=b, whereas
you could do that with tuples. So tuples help to minimize the number of ad-hoc
structures in your program, and enable you to write code that is more generic..
[i.e., you can pass tuple<int,int> from one subsystem of your program to
another with no problems, whereas it'd be more harder to pass A from subsys1
to subsys2 expecting B. you *could* implement implicit conversion operators
from A to B and vice-versa, but that sounds like calling for trouble..]
+ they predefine a number of useful operations for you, such as lexicographic
comparison, I/O operators, etc. With fusion maps, you get to use names,
instead of indexes. (fusion maps, in effect, replace a.x syntax with
at_key<x>(a) syntax.. somewhat more verbose, with the net win of the extra
functionality..)
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