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

template template parameters

I have this code from the book C++ Templates: The Complete Guide:

#ifndef ACCUM8_HPP_
#define ACCUM8_HPP_

#include "accumtraits4.hpp"
#include "sumpolicy2.hpp"

template <typename T,
template<typename,typenameclass Policy = SumPolicy,
typename Traits = AccumulationTraits<T
class Accum {
public:
typedef typename Traits::AccT AccT;
static AccT accum (T const* beg, T const* end) {

AccT total = Traits::zero();

while (beg != end) {
Policy<AccT,T>::accumulate(total, *beg);
++beg;
}
return total;
}
};

#endif /*ACCUM8_HPP_*/


Is it correct that it defines a class template with 3 template parameters:

1) typename T
2) template<typename,typenameclass Policy = SumPolicy
3) typename Traits = AccumulationTraits<T>
I read 2) as a template class "Policy" that has two unnamed template
parameters <typename,typename>.
In the while loop the line:

Policy<AccT,T>::accumulate(total, *beg);

AccT corresponds to the first "typename" in:

....
template<typename,typenameclass Policy = SumPolicy,
....

and "T" corresponds to the second.

Is this a correct interpretation?
May 2 '07 #1
2 1836
desktop wrote:
I have this code from the book C++ Templates: The Complete Guide:

#ifndef ACCUM8_HPP_
#define ACCUM8_HPP_

#include "accumtraits4.hpp"
#include "sumpolicy2.hpp"

template <typename T,
template<typename,typenameclass Policy = SumPolicy,
typename Traits = AccumulationTraits<T
class Accum {
public:
typedef typename Traits::AccT AccT;
static AccT accum (T const* beg, T const* end) {

AccT total = Traits::zero();

while (beg != end) {
Policy<AccT,T>::accumulate(total, *beg);
++beg;
}
return total;
}
};

#endif /*ACCUM8_HPP_*/


Is it correct that it defines a class template with 3 template parameters:

1) typename T
2) template<typename,typenameclass Policy = SumPolicy
3) typename Traits = AccumulationTraits<T>
I read 2) as a template class "Policy" that has two unnamed template
parameters <typename,typename>.
In the while loop the line:

Policy<AccT,T>::accumulate(total, *beg);

AccT corresponds to the first "typename" in:

...
template<typename,typenameclass Policy = SumPolicy,
...

and "T" corresponds to the second.

Is this a correct interpretation?
Sounds about right.
May 2 '07 #2
desktop wrote:
I have this code from the book C++ Templates: The Complete Guide:

#ifndef ACCUM8_HPP_
#define ACCUM8_HPP_

#include "accumtraits4.hpp"
#include "sumpolicy2.hpp"

template <typename T,
template<typename,typenameclass Policy = SumPolicy,
typename Traits = AccumulationTraits<T
class Accum {
public:
typedef typename Traits::AccT AccT;
static AccT accum (T const* beg, T const* end) {

AccT total = Traits::zero();

while (beg != end) {
Policy<AccT,T>::accumulate(total, *beg);
++beg;
}
return total;
}
};

#endif /*ACCUM8_HPP_*/


Is it correct that it defines a class template with 3 template
parameters:
The term commonly used is "arguments", not "parameters", although
I've seen "parameters" used in place of "formal arguments"...
>
1) typename T
2) template<typename,typenameclass Policy = SumPolicy
3) typename Traits = AccumulationTraits<T>
Yes.
I read 2) as a template class "Policy" that has two unnamed template
parameters <typename,typename>.
The names of those arguments are not important (just like names of
formal arguments in a function declaration).
>

In the while loop the line:

Policy<AccT,T>::accumulate(total, *beg);

AccT corresponds to the first "typename" in:

...
template<typename,typenameclass Policy = SumPolicy,
...

and "T" corresponds to the second.

Is this a correct interpretation?
Yes. And 'AccT' is a typedef, it's a member type that comes from
'Traits', the third argument of 'Accum'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 2 '07 #3

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

Similar topics

3
by: Gianni Mariani | last post by:
I was a little surprised by this: It seems like the code below should not compile but the Comeau 4.3.3 compiler accepts it and the gcc 3.4(prerel) compiler rejects it and MSVC++7.1 ICE's. ...
11
by: Alexander Stippler | last post by:
Hi, I have a little problem to design some template classes in a realizable way. I have some Container classes and some Proxy classes (proxies for elements). Looks like this: // P is the...
3
by: Erik Wikström | last post by:
I've been trying for a while now to understand how template template parameters work. But I just can't wrap my head around it and was hoping that someone might help me. As best I can figure the...
6
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on...
4
by: Dan Krantz | last post by:
I have the following template to ensure that a given number (val) falls into a range (between vmin & vmax): template<typename T> T ForceNumericRange( const T& val, const T& vmin, const T& vmax)...
8
by: Paul Roberts | last post by:
Hi, I'm hoping somebody here can help me with a simple problem of template syntax. Here's an example: template<typename T, int iclass A { static int a;
8
by: Jess | last post by:
Hi, I have a template function that triggered some compiler error. The abridged version of the class and function is: #include<memory> using namespace std; template <class T>
2
by: Pierre Yves | last post by:
Hi there, Sorry for the double subject but I feel they are related. I'm not pretty sure there would be an answer but I reckon there must be a way to make it work. I would like to write the...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
4
by: * Tong * | last post by:
First of all, thanks mlimber for answering my previous question. Now... I'm following the example in "C++ Templates: The Complete Guide", section 5.4 Template Template Parameters, and I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.