473,756 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4065
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
2168
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 declaration (template or not) - .hxx files are template impl
2
2013
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 I decided to try it on some code I'm writing. The idea is to use template objects to perform what happens in traditional nested for() loops. for(int row = 0; row < num_rows; row++) { for(int col = 0; col < num_cols; col++) {
6
4007
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 as well. To support thin-template, I need to make virtual function as inline. Now, I know that compiler would generate an out-of-line copy when it
2
3690
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 false;
1
1990
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following: ****************************************************************** template<typename T> void from_string(const char Str, T &Obj); template<> void from_string(const char Str, long &); // template<> void from_string(const char Str, unsigned lon &); //
2
1779
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* set_addr(const T* addr, unsigned long n) {
3
1979
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 some_class { };
5
3620
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 anyone explain why loop unrolling doesn't play well with templates? Or better, can someone submit a code fragment to get desired results? Here are the command-lines I use to generate code: "g++ -DTEMPLATE=0 -o gotofun0 gotofun.cpp" works exactly as...
9
2063
by: wo3kie | last post by:
#include <iostream> #include <map> #include <utility> // // Base // / | \ // Derived1 Derived2 \ // \ | / // Derived3
21
4741
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 that gets the same result) works as expected in visualc++. I know that this is probably not the right behavior for a compiler but it's the kind of behavior I'm searching for so I was hoping there was a way to do the same thing in gcc. As you know...
0
9455
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9869
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.