473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

What's the difference betwwen explicit instantiaion and explicit specialization?

Hi,

I got a little confused on 'instantiation' and 'specialization',
espcially for explicit instantiation and explicit sepcialization. Can
anybody explain the difference?

Thanks a lot!

Andy

Jul 23 '05 #1
5 2211
Is an instantiation a process of producing a specialization?
Thanks,

andy

Jul 23 '05 #2
* Andy:

I got a little confused on 'instantiation' and 'specialization',
espcially for explicit instantiation and explicit sepcialization. Can
anybody explain the difference?


You specialize a template when you provide a definition for some actual
template parameter, e.g., saying "in general, use the general definition,
but for template parameter T=int, use this more specialized definition".

This specialized definition may or may not be actually used, so
specialization by itself does not cause a more thorough analyzis than
the original template definition.

You instantiate a template when you cause the compiler to generate code for
the template. This requires all template parameters given actual parameters,
and it causes full-blown analysis of this specialization of the template.
For example, you declare an object of the template type, or you call a
templated function. At that point the template definition is expanded to
actual, ordinary C++ code (the template instance), which is subject to the
usual C++ compilation (OK, some rules, e.g. about multiple definitions, are
slightly different). You can also instantiate a template without using it, via
special syntax.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #3

Andy wrote:
Hi,

I got a little confused on 'instantiation' and 'specialization',
espcially for explicit instantiation and explicit sepcialization. Can anybody explain the difference?

Thanks a lot!

Andy


If I have a templated class:

template <typename FOO> class Bar { ... };

I explicitly *instantiate* Bar<char> like this:

template <> class Bar<char>;

Notice that the implementation of Bar<char> does not change (i.e., it
is not specialised).

When I *specialise* Bar<char>, I do this:

template <> class Bar<char> { ... };

Now, Bar<char> has a new meaning (i.e., the template class 'Bar' now
does something "special" when used with 'char' as the template
argument).

Hope this helps,
-shez-

Jul 23 '05 #4
Shezan Baig wrote:


I explicitly *instantiate* Bar<char> like this:

template <> class Bar<char>;


The correct syntax for explicit instantiation is

template class Bar<char>;

(with no '<>'.)
MM


Jul 23 '05 #5

Max M. wrote:
Shezan Baig wrote:


I explicitly *instantiate* Bar<char> like this:

template <> class Bar<char>;


The correct syntax for explicit instantiation is

template class Bar<char>;

(with no '<>'.)
MM


Yes, this is correct. My bad.

-shez-

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it...
0
by: Patrick Kowalzick | last post by:
Dear all, the following code is illegeal (but compiles with MSVC 7.1): // *** illegal *** struct outer0 { template<typename inner_var> struct inner { }; template<>
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
6
by: Vyacheslav Lanovets | last post by:
Hello, All! I know that Explicit Instantiation actually emits code to obj files (so you can even export them from the module as plain functions or classes). But I found that MSVC7.1 compiler...
8
by: Ferdi Smit | last post by:
I've never understood the rationale of allowing partial, but not explicit specialization for classes at non-namespace scope. Ie.: struct A { template <typename T1, typename T2> struct B {}; ...
1
by: JohnPantango | last post by:
Can anyone give me a simple work around to fix this compiler error on VC7.1 .....cpp(23) : error C2912: explicit specialization; 'bool Equal<_F32>(const _F32::type,const _F32::type)' is not a...
12
by: Robert.Holic | last post by:
Hi All (first time caller, long time listener), I've stumbled across a problem that I have yet to figure out, although Im sure I'll kick myself when I figure it out. Here it is: I need to...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
0
by: greek_bill | last post by:
Hi, I have a template function for which I use SFINAE to restrict one of the parameters. Then I also have a partial specialization of this function.I would like to provide an explicit...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.