Boost logo

Boost Users :

From: Davi de Castro Reis (davicastro_at_[hidden])
Date: 2005-04-18 19:41:50


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 <uchar nparams, typename T1, typename T2 = none, typename T3 =
none ...>
class A
{
        void f(boost::tuple<char, char, ..., char>);
}

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


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