473,799 Members | 3,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

template<int __inst> ...

so I see declarations for various template classes and functions which
start with:

template <int __inst>

unfortunately the compiler I use doesn't allow that so I can't
experiment... but I am guessing from the text that what is expected is
an integer value. I assume that that integer is used to further qualify
the template instantiation, so that there could be multiple
instantiations for the template that were unrelated to a change in type.

for example:

template <int __inst>
void myfunc( char *a)
{
....
}

we could have a myfunc<0> and a myfunc<1> and so forth...

I'm somewhat fresh on templates so if someone could clarify that this is
indeed what is the case I'd appreciate it. If not I would appreciate
some clarification on what exactly the intent of this is.

In any case I would also like to hear why one would want to use this
feature? If it helps the code I am reviewing is the SGI template
library...

Thanks,

David
Jul 22 '05 #1
1 2153
"David Lindauer" <ca*****@bluegr ass.net> wrote in message
news:41******** *******@bluegra ss.net...
so I see declarations for various template classes and functions which
start with:

template <int __inst>

unfortunately the compiler I use doesn't allow that so I can't
experiment... but I am guessing from the text that what is expected is
an integer value. I assume that that integer is used to further qualify
the template instantiation, so that there could be multiple
instantiations for the template that were unrelated to a change in type.
It's pretty much it. But why don't your read some book or tutorial
about templates?
For example, Thinking in C++ (Vol 1 chap 16, and Vol 2 chap 3),
has a decent intro, and can be downloaded here:
http://www.mindview.net/Books/TICPP/...ngInCPP2e.html

Also, BTW, there are many free C++ compilers that support templates
(gcc, versions from Microsoft or Borland, and many more).
In any case I would also like to hear why one would want to use this
feature? If it helps the code I am reviewing is the SGI template
library...

There are too many different possible uses to mention.
A classic starter might be:
#include <iostream>

template<int i> struct factorial
{ enum { value=i*factori al<i-1>::value }; };

// specialize the function to end recursion
template<> struct factorial<1> { enum { value = 1 }; };

int main()
{
// the factorial value is computed at compile-time.
std::cout << factorial<5>::v alue << std::endl;
}

A more practical example could be a small vector linear
algebra library that uses the following definition of
a vector type:
template<int N>
struct vect { double m[N]; }

hth,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Jul 22 '05 #2

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

Similar topics

3
5816
by: Andreas Krueger | last post by:
Hi! I am fed up with vector<int> iv; iv.push_back(42); iv.push_back(9); iv.push_back(11); ... and would rather use a function "fillVector": vector<int> iv = fillVector(42,9,11); like in Mathematica(tm): someList={42,9,11};
3
2270
by: Rakesh Sinha | last post by:
This is about the vector template defined in standard C++ . Suppose I want to create a *huge* vector , as follows. void f1() { vector < int > data(1024); //may be not very huge, but for //demonstration purposes //Process 'data'
20
17842
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; std::vector<double>::size_type size = src.size(); dest.reserve(size); for (std::vector<int>::size_type i = 0;
4
2641
by: Stuart Moore | last post by:
Hi, I'm quite new to templates and I seem to be getting myself messed up. I want to write a function that takes a map<T, int> and a set<T>, iterates over the set, and increments the corresponding int in the map (or sets it to 1 if it doesn't already exist). I can write the function itself for a given type, but I can't figure out what template statement(s) I need to put before it to make it generalise. Stuff I've tried unsuccessfully is...
4
5085
by: Gary li | last post by:
Hi, all I find "template template" class cann't been compiled in VC6 but can ok in Redhat9. I write a test program like as: template< template<class> class T> class A { }; int main() { return 0;
4
2318
by: Grizlyk | last post by:
Hello. Why were base class "typedefs" hidden by template<and explicit usage of them does not work too? Try open only one of the lines in the example below //using Tparent::Tptr; //typedef Tparent::Tptr Tptr; Consider example:
10
6078
by: arnuld | last post by:
WANTED: /* C++ Primer - 4/e * * Exercise: 9.26 * STATEMENT * Using the following definition of ia, copy ia into a vector and into a list. Use the single iterator form of erase to remove the elements with odd values from your list * and the even values from your vector.
6
2903
by: year1943 | last post by:
For template <typename Tclass My ; I can define partial spec-ns somewhat like template <typename Tclass My<T*; or template <typename Tclass My<Another<T ; And full spec-n, say template <class My<int; What if I have a template class template <typename T, typename Uclass My ;
9
1821
by: jabbah | last post by:
yeah i know that the title is not really a question - sorry - i fail to put my question into one sentence so i put it into a storry: background is i am using two different 'ARRAY's in my code. (ie. things with access in constant time via operator ) namely std::vector and something from another library. but, still i do mostly the same things one both so, a while ago i decided to implement most in templates so i can easily change between...
0
9688
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
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
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
10243
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
10030
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...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.