 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mario Guest
|
Posted: Fri Feb 13, 2004 11:14 am Post subject: multiple parameters |
|
|
Hi together
I have to support interfaces with different number
of parameters. My template solution looks like this:
template <typename T1>
classA(T1 t1)
....
template <typename T1, typename T2>
classA(T1 t1, T2 t2)
....
template <typename T1, typename T2, typename T3>
classA(T1 t1, T2 t2, T3 t3)
....
and so on...
Is there a way to generalize/simplify this problem to
one interface?
Thanks
Mario
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Thu Feb 19, 2004 1:38 pm Post subject: Re: multiple parameters |
|
|
"Mario" <chruetli (AT) gmx (DOT) net> wrote
| Quote: | Hi together
I have to support interfaces with different number
of parameters. My template solution looks like this:
template
classA(T1 t1)
...
template
classA(T1 t1, T2 t2)
...
template
classA(T1 t1, T2 t2, T3 t3)
...
and so on...
Is there a way to generalize/simplify this problem to
one interface?
|
I can't say whether the interface can be simplified without knowing
more. Your interface follows a common pattern, however, and if you
can't simplify it there is no particular reason to avoid it.
You might save yourself some typing and maintenance problems by using
the Boost Preprocessor library:
http://www.boost.org/libs/preprocessor/doc/index.html
Jonathan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Hendrik Schober Guest
|
Posted: Sat Feb 21, 2004 4:22 am Post subject: Re: multiple parameters |
|
|
Mario <chruetli (AT) gmx (DOT) net> wrote:
| Quote: | Hi together
I have to support interfaces with different number
of parameters. My template solution looks like this:
template <typename T1
classA(T1 t1)
...
template
classA(T1 t1, T2 t2)
...
template
classA(T1 t1, T2 t2, T3 t3)
...
and so on...
|
I'm not sure what the 'classA(T1,T2,T3)'
syntax refers to.
| Quote: | Is there a way to generalize/simplify this problem to
one interface?
|
I have used compile-time lists for calling
functions. The basic idea is like this:
class nil {};
template< typename Head, typename Tail >
class ct_list {
Head head;
Tail tail;
};
typedef ct_list< int
, ct_list< float
, ct_list< string
, ct_list< X
, nil > > > > my_list;
template< typename func, class list >
void call_func( func f, list l );
If 'f' can be called with the objects
in 'l', it would be called. (Otherwise
it wouldn't compile.)
Maybe this could be used?
Schobi
--
[email]SpamTrap (AT) gmx (DOT) de[/email] is never read
I'm Schobi at suespammers dot org
"Sometimes compilers are so much more reasonable than people."
Scott Meyers
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|