Hi,
I have a class where I use a tuple as input for some of my methods. The
reason for this is that the number of parameters for these methods is a
compile-time variable. See sample code below.
template
class A
{
void f(boost::tuple);
}
So users can do something like
A a<3, char, char, char>
a.f(make_tuple('a', 'b', 'c');
The problem is that make_tuple is not a nice name, since it does not
reflect the semantics of the parameter. Suppose I would like to call it
key, so I can call
A a<3, char, char, char>;
a.f(key('a', 'b', 'c'));
So, in my context, everything gets much more clear. Does someone know an
elegant way of doing this? As I can thing, the only way I can do it, is
to create a templatized free function called key, for which I will need
to write 10 overloads (the max number of nparams, and also boost tuple,
if I am not mistaken).
Besides being a rather ugly solution, I will need to pay two copies of
my objects before sending them to the f() method (with make_tuple I pay
only one copy, which is also suboptimal, but, anyways...).
Using #define is not an option since key is a very common name (the
class is in a namespace). Ugly names such as MY_LIBRARY_KEY() are not a
very nice also.
Well, any tips? Solutions involving boost::mpl would be the best, but I
couldn't find none.
[]s
Davi de Castro Reis