D
desktop
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,typename> class 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,typename> class 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,typename> class Policy = SumPolicy,
....
and "T" corresponds to the second.
Is this a correct interpretation?
#ifndef ACCUM8_HPP_
#define ACCUM8_HPP_
#include "accumtraits4.hpp"
#include "sumpolicy2.hpp"
template <typename T,
template<typename,typename> class 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,typename> class 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,typename> class Policy = SumPolicy,
....
and "T" corresponds to the second.
Is this a correct interpretation?