 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ivan Godard Guest
|
Posted: Fri Apr 22, 2005 1:30 pm Post subject: template template function parameters? |
|
|
I have need of a class template one of whose arguments is a function
template - *not* a single instance of a template function, but the
actual function template itself to be called with different argument
types at different points. I expected something like:
template<typename U, template struct Foo {
... X x; Y y;
... if (pred(x) && pred(y))...
};
template<typename T>
bool predAct(T& t) {...}
Foo<int, predAct> f;
but no joy. Some Googling shows class template template parameters, but
no function template template parameters. Do they not exist in the
language, or do I have the syntax wrong? If the former, is there an
idiom that provides the effect?
Thanks
Ivan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Cyril Guest
|
Posted: Sat Apr 23, 2005 2:29 am Post subject: Re: template template function parameters? |
|
|
Create a object with an () operator in which you've included your
function definition.
Then use this object as a template (no need for "function template"
like you named them)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Alex Beluga Guest
|
Posted: Sat Apr 23, 2005 9:21 am Post subject: Re: template template function parameters? |
|
|
The idiom which might help you is functor template.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Sat Apr 23, 2005 9:21 am Post subject: Re: template template function parameters? |
|
|
Ivan Godard wrote:
| Quote: | I have need of a class template one of whose arguments is a function
template - *not* a single instance of a template function, but the
actual function template itself to be called with different argument
types at different points. I expected something like:
template<typename U, template struct Foo {
... X x; Y y;
... if (pred(x) && pred(y))...
};
template<typename T
bool predAct(T& t) {...}
Foo
but no joy. Some Googling shows class template template parameters, but
no function template template parameters. Do they not exist in the
language, or do I have the syntax wrong? If the former, is there an
idiom that provides the effect?
|
They don't exist in the language. You can use a function object class
as a wrapper:
template<typename U, typename Pred> struct Foo {
... X x; Y y; Pred pred;
... if (pred(x) && pred(y))...
};
struct predAct {
template<typename T> bool operator()(T& t) const {...}
};
Foo<int, predAct> f;
--
Ben Hutchings
Having problems with C++ templates? Your questions may be answered by
<http://womble.decadentplace.org.uk/c++/template-faq.html>.
[ 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
|
|