473,394 Members | 1,703 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,394 software developers and data experts.

Template code inline

Hi all,

Is template code "always" inlined???
Or will compilers instantiate template functions separately if they
are large?

Also, what happens to the code if explicit instantiation mechanism is
used? ]
Are template functions, objects and member functions then placed as
separate entities within the object file, as with any non templated
functions.???
Jul 19 '05 #1
2 4042
On 14 Nov 2003 03:17:34 -0800, me@stevejpurves.info (Steve) wrote:
Hi all,

Is template code "always" inlined???
No. It might be if you define the functions inside the class
definition, since that implicitly inlines the code.
Or will compilers instantiate template functions separately if they
are large?
Yes. The function may be instantiated in multiple translation units
and the code used in a number of places, but compilers employ a number
of techniques to ensure that you only end up with a single copy of the
code in your exe (instantiation databases and linker based
instantiation merging are two techniques). Of course, the
implementation may choose to inline the code anyway.
Also, what happens to the code if explicit instantiation mechanism is
used? ]
You control the translation unit that gets the instantiation, and
avoid having the template implicitly instantiated in multiple
translation units.
Are template functions, objects and member functions then placed as
separate entities within the object file, as with any non templated
functions.???


Yes. Templates are never compiled to object code, only template
specializations. These can be explicit specializations, implicit
instatiations or explicit instantiations. This is independent of
inlining.

Tom
Jul 19 '05 #2
Steve wrote:
Hi all,

Is template code "always" inlined???
Templates don't have any special connections to inline functions.
Or will compilers instantiate template functions separately if they
are large?
They can do that and probably will. There are even cases in which it's
impossible to inline a function (think recursion or calling the
function through a pointer)
Also, what happens to the code if explicit instantiation mechanism is
used? ]
Code for the template instance is generated.
Are template functions, objects and member functions then placed as
separate entities within the object file, as with any non templated
functions.???


Yes.

Jul 19 '05 #3

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

Similar topics

5
by: Nomak | last post by:
Hello all, i have two template classes which needs each other. I tried to write some fwd decl / decl / impl in a good way but i can't get it to compile. Explanations: - .hh files are for...
2
by: Steven T. Hatton | last post by:
While thunbing through _C++ Templates, The Complete Guide_ (reckon I aught to read it?) I came across a discussion of using templates to "unroll" loops. I thought that looked like a good idea, so...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
2
by: Michael Stembera | last post by:
Here is a very simple piece of code to repro this bug. template<typename T, int N> inline bool foo( void ) { return true; } template<typename T> inline bool foo<T, 1>( void ) { return...
1
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following:...
2
by: Yang Zhang | last post by:
I have a small program like this: //////////////////////////////////////////////// #include <iostream> using namespace std ; // set bits in an address template <typename T> inline T*...
3
by: Thomas Pajor | last post by:
Hey everybody, I got into serious trouble with template programming. I have a class which uses three template arguments, say template<typename Atype, typename Btype, typename Ctype> class...
5
by: iapx86 | last post by:
My parser project calls for a computed goto (see code below). The C preprocessor delivers the desired result, but is ugly. Template metaprogramming delivers results I do not understand. Can...
9
by: wo3kie | last post by:
#include <iostream> #include <map> #include <utility> // // Base // / | \ // Derived1 Derived2 \ // \ | / // Derived3
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.