473,320 Members | 2,164 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,320 software developers and data experts.

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 2114
"David Lindauer" <ca*****@bluegrass.net> wrote in message
news:41***************@bluegrass.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*factorial<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>::value << 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
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...
3
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...
20
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; ...
4
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...
4
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() {...
4
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...
10
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...
6
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...
9
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....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.