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 

How much is it possible to examine templated functions?

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





PostPosted: Wed Mar 23, 2005 11:02 pm    Post subject: How much is it possible to examine templated functions? Reply with quote



Is it possible to somehow "capture" or study templated functions without
a specific instansation, so they can be passed around?

I came across this problem a while ago and couldn't figure out any way
of doing it without wrapping it in a class

ie given:

template<class T>
void foo(T& t);

I can't somehow pass "foo" around without instansating it.

However given:

struct c {
template <class T>
void foo(T& t);
};

I can pass around a c, and use that to get to f.

Now I'm coming at this from the other end. I currently have a templated
function like:

template<class It, class val>
It find(It,It,const val&);

and I want to replace this with:

template<class It, class val>
typename my_enable_if<It,condition>::type find(It,It,const val&);

template<class It, class val>
typename my_enable_if<It,!condition>::type find(It,It,const val&);

(my_enable_if is a template very much like enable_if)

Is there any way at all to detect I've done this? If there is I can hide
this, but if it's impossible to detect then I may as well leave it like
this :)

Thank you,

Chris

[ 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





PostPosted: Thu Mar 24, 2005 11:58 am    Post subject: Re: How much is it possible to examine templated functions? Reply with quote



In article <d1sf31$g9t$1 (AT) pump1 (DOT) york.ac.uk>, Chris Jefferson
<caj (AT) cs (DOT) york.ac.uk> wrote:

Quote:

and I want to replace this with:

template<class It, class val
typename my_enable_if
how about:

template <class It,class Val>
It find(typename my_enable_if<It,condition>::type begin,It end,const
Val &val);
?

seems like this will only succeed [assuming my_enable_if<It,cond> is
the same as boost::enable_if_c<cond,It>. as this then requires the
first arg to match the condition, and the second arg. If the condition
falis there is no type member, so its not used to find a find template
that matched.
using boost it is

template <class It,class Val>
It find(typename boost::enable_if_c<some_boolean::type
first, It second,Val const &val) { /* ...*/} or forwarded with only a ;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Gabriel Dos Reis
Guest





PostPosted: Fri Mar 25, 2005 1:06 am    Post subject: Re: How much is it possible to examine templated functions? Reply with quote



Carl Barron <cbarron413 (AT) adelphia (DOT) net> writes:

Quote:
In article <d1sf31$g9t$1 (AT) pump1 (DOT) york.ac.uk>, Chris Jefferson
[email]caj (AT) cs (DOT) york.ac.uk[/email]> wrote:


and I want to replace this with:

template<class It, class val
typename my_enable_if
how about:
template <class It,class Val
It find(typename my_enable_if Val &val);
?

That is not exactly the same thing. With Chris' version, the first
two arguments must be of the same type. With your version, that
requirement is lifted.

--
Gabriel Dos Reis
[email]gdr (AT) integrable-solutions (DOT) net[/email]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Chris Jefferson
Guest





PostPosted: Fri Mar 25, 2005 11:58 am    Post subject: Re: How much is it possible to examine templated functions? Reply with quote

Carl Barron wrote:
Quote:
In article <d1sf31$g9t$1 (AT) pump1 (DOT) york.ac.uk>, Chris Jefferson
[email]caj (AT) cs (DOT) york.ac.uk[/email]> wrote:


and I want to replace this with:

template<class It, class val
typename my_enable_if

how about:
template <class It,class Val
It find(typename my_enable_if Val &val);
?

The problem I'm having stems from the fact that I want to know if it's
possible for someone to detect if
template<class It, class val>
It find(It,It,val);

is being implemented by two seperate functions, at most one of which
will be valid for any particular It (by using enable_if). It is true
that I might be able to put the enable_if in different places, but the
important question (to me) is can the existance of two functions be
detected? :)

Chris

[ 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





PostPosted: Sat Mar 26, 2005 5:33 pm    Post subject: Re: How much is it possible to examine templated functions? Reply with quote

In article <4243E834.3060903 (AT) cs (DOT) york.ac.uk>, Chris Jefferson
<caj (AT) cs (DOT) york.ac.uk> wrote:

Quote:
The problem I'm having stems from the fact that I want to know if it's
possible for someone to detect if
template It find(It,It,val);

is being implemented by two seperate functions, at most one of which
will be valid for any particular It (by using enable_if). It is true
that I might be able to put the enable_if in different places, but the
important question (to me) is can the existance of two functions be
detected? :)

Enable_if and the others on the same 'sublibrary' can restrict the

selection process, to eliminate unwanted matches by SFINAE but they do
not detect that that is more than one candidate if they were not used.

[ 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.