C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template template function parameters?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Ivan Godard
Guest





PostPosted: Fri Apr 22, 2005 1:30 pm    Post subject: template template function parameters? Reply with 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<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





PostPosted: Sat Apr 23, 2005 2:29 am    Post subject: Re: template template function parameters? Reply with quote



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





PostPosted: Sat Apr 23, 2005 9:21 am    Post subject: Re: template template function parameters? Reply with quote



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





PostPosted: Sat Apr 23, 2005 9:21 am    Post subject: Re: template template function parameters? Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.