Simplifing tuples
chris
caj@cs.york.ac.uk
Sat Oct 9 11:03:00 GMT 2004
The boost::tuple class uses a really quite clever head, taill recursive
process to handle about half of the functions, and the definition of the
tuple classes themselves.
While this is quite cool, it also has 4 main disadvantages
1) Error messages tend to be about 10 lines long as it unrolls templates
2) Debugging unoptimised code is a bit painful as you have to work your
way through lots of template levels
3) (similarily) unoptimised performance really sucks compared to just a
simple tuple class
4) Unrolling and inlining all those templates probably causes some (but
not too much) pain.
Instead, I am currently playing with implementing tuples by just writing
out the classes (actually, generating the header from another program)
Disadvantages of this:
1) It's not as cool
2) The header will be somewhat (but not that much) bigger
3) While I'm fairly certain, I'm not yet 100% positive it will be
possible to implement everything in this manner.
The main method looks something like:
class __dummy{};
template<class T1=__dummy, ... , class TN=_dummy>
class tuple {
static const int size=N;
T1 t1;
...
TN tn;
public:
functions...
};
template<class T1,>
class tuple<T1,_dummy,...,__dummy> {
static const int size = 1;
T1 t1;
public:
functions...
};
...
I'm currently working my way through implementing this, writing a
sizeable test suite, etc. I just wondered if anyone had any positive /
negative comments on this kind of unfolding?
Chris
More information about the Libstdc++
mailing list