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
How about using Boost.Preprocessor and have it write the 10 overloads for
you?
There should be examples available for you to look at (sorry, wouldn't know
how to write it by heart, I'm still fairly new to Boost.PP and have to
constantly look at the docs)
Pablo Aguilar
"Davi de Castro Reis"
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
"Pablo Aguilar"
How about using Boost.Preprocessor and have it write the 10 overloads for you?
There should be examples available for you to look at (sorry, wouldn't know how to write it by heart, I'm still fairly new to Boost.PP and have to constantly look at the docs)
Pablo Aguilar
An example is available in the ENUM_PARAMS_Z reference docs, I believe that's what you'd be looking for...
Pablo Aguilar wrote:
"Pablo Aguilar"
wrote in message news:d41k0s$1s2$1@sea.gmane.org... How about using Boost.Preprocessor and have it write the 10 overloads for you?
There should be examples available for you to look at (sorry, wouldn't know how to write it by heart, I'm still fairly new to Boost.PP and have to constantly look at the docs)
Pablo Aguilar
An example is available in the ENUM_PARAMS_Z reference docs, I believe that's what you'd be looking for...
Thanks for the help. I think that will be the right way to go. []s Davi de Castro Reis
participants (2)
-
Davi de Castro Reis
-
Pablo Aguilar