 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
υα Guest
|
Posted: Sun Apr 17, 2005 2:26 pm Post subject: Template Parameter Forwarding |
|
|
There is a small proble I tried to solve.
Imagine this template(it's just an example):
template <typename T,typename T::type>
struct Something;
Now,everything is OK.
But imagine I want to default the first parameter,e.g. to some
metafunction.
To be able to default it,it must be at the end of the template parameter
list.
To be able to use it in the second parameter type,it must be at the front.
Nothing I tried seems to work,even traits.
Is there anything I could do in this situation?
Thanx. :-)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Carl Barron Guest
|
Posted: Sun Apr 17, 2005 9:20 pm Post subject: Re: Template Parameter Forwarding |
|
|
υα <efim.slobodov233432 (AT) arcor (DOT) de> wrote:
| Quote: | There is a small proble I tried to solve.
Imagine this template(it's just an example):
template <typename T,typename T::type
struct Something;
Now,everything is OK.
But imagine I want to default the first parameter,e.g. to some
metafunction.
To be able to default it,it must be at the end of the template parameter
list.
To be able to use it in the second parameter type,it must be at the front.
Nothing I tried seems to work,even traits.
Is there anything I could do in this situation?
Thanx. :-)
|
Use inheritance like this:
template
struct*/};
template <class T,class T::type> struct
something:something_base<T,T::type>
{ /* forwarding constructors */|;
template <> struct something
<
default_type,
default_type::type
| Quote: | | :something_base
default_type::type |
{ /* forwarding constructors */};
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ralph Zhang Guest
|
Posted: Mon Apr 18, 2005 9:10 am Post subject: Re: Template Parameter Forwarding |
|
|
why don't you just move that T::type into the class? like this:
template<typename T>
struct Something
{
typedef typename T::type type;
};
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
υα Guest
|
Posted: Mon Apr 18, 2005 3:14 pm Post subject: Re: Template Parameter Forwarding |
|
|
"> why don't you just move that T::type into the class? like this:
| Quote: |
template
struct Something
{
typedef typename T::type type;
};
|
Because I want that it is defaultable,but at the same time
specifiable( ).
Thanks for the answer,but just like I said,it wouldn't be nice if I had to
specify the default template parameters.
[ 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
|
|