Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
syntax about function template, or not
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
yuanfang  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 02:03
Newsgroups: comp.lang.c++.moderated
From: yuanfang <tabloid.adr...@gmail.com>
Date: Fri, 6 Nov 2009 20:03:03 CST
Local: Sat 7 Nov 2009 02:03
Subject: syntax about function template, or not
Forgive my ignorance, I ran into this "little" function coming from
LLVM source base about so called "enhanced RTTI", still couldn't
figure out what does it mean.

1 // Define reference traits in terms of base traits...
2 template<class FromCl>
3 struct isa_impl_cl<FromCl&> {
4   template<class ToCl>
5   static bool isa(FromCl &Val) {
6     return isa_impl_cl<FromCl>::template isa<ToCl>(&Val);
7   }
8 };

especially, at line 3, how come there is another template-like thing.
Thank you guys who is willing to reply.

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Maeder  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:19
Newsgroups: comp.lang.c++.moderated
From: Thomas Maeder <mae...@glue.ch>
Date: Sat, 7 Nov 2009 09:19:30 CST
Local: Sat 7 Nov 2009 15:19
Subject: Re: syntax about function template, or not

yuanfang <tabloid.adr...@gmail.com> writes:
> 1 // Define reference traits in terms of base traits...
> 2 template<class FromCl>
> 3 struct isa_impl_cl<FromCl&> {
> 4   template<class ToCl>
> 5   static bool isa(FromCl &Val) {
> 6     return isa_impl_cl<FromCl>::template isa<ToCl>(&Val);
> 7   }
> 8 };

> especially, at line 3, how come there is another template-like thing.

This is a partial specialization of a base template.

There has to be a base template isa_impl_cl somewhere higher up in the
code, along the lines of

template <class T>
struct isa_impl_cl
{
  ...

};

Imagine the base template as a generic version of what isa_impl_cl
should look like for most types T.

Now isa_impl_cl seems to have to be something different if it is
instantiated on a reference type. That's where the code you posted
comes in. If isa_impl_cl is instantiated on a reference type, the
compiler will use this more specialized version.

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bo Persson  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:21
Newsgroups: comp.lang.c++.moderated
From: "Bo Persson" <b...@gmb.dk>
Date: Sat, 7 Nov 2009 09:21:30 CST
Local: Sat 7 Nov 2009 15:21
Subject: Re: syntax about function template, or not

This is a specialization for template parameters that are references.

There must also be a main template preceding this one.

Bo Persson

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tohava  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:22
Newsgroups: comp.lang.c++.moderated
From: tohava <toh...@gmail.com>
Date: Sat, 7 Nov 2009 09:22:12 CST
Local: Sat 7 Nov 2009 15:22
Subject: Re: syntax about function template, or not
On Nov 7, 4:03 am, yuanfang <tabloid.adr...@gmail.com> wrote:

This function simply calls another version of this function that gets
a pointer instead of a reference. The thing in line 3 is a partial
specialization of the struct for templates only.

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Schwab  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:20
Newsgroups: comp.lang.c++.moderated
From: Jeff Schwab <j...@schwabcenter.com>
Date: Sat, 7 Nov 2009 09:20:28 CST
Local: Sat 7 Nov 2009 15:20
Subject: Re: syntax about function template, or not

That's a partial specialization.  There should already have been a
declaration (and probably a definition, called the "primary template")
template<class FromCl> struct isa_impl_cl.  In the code you posted, the
author has effectively told the compiler "when you instantiate the
isa_impl_cl template, if the template argument is a reference type, use
this special definition instead of the original."  In the body, the
"isa" member function template just delegates to a similarly named
member function template in the primary template definition.  The point
apparently is that the original "isa" accepts a pointer, whereas this
specialization accepts a reference (and just passes the address of the
referenced object down to the original definition),

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google