N
nooneinparticular314159
I'm trying to understand template metaprogramming syntax. It's been
years since I've touched C++, so this may actually be a C++ syntax
issue (although it seems that the language has changed somewhat.)
The following example comes from http://www.codeproject.com/KB/cpp/crc_meta.aspx
template< int i >
class FACTOR{
public:
enum {RESULT = i * FACTOR<I-1>::RESULT};
};
class FACTOR< 1 >{
public:
enum {RESULT = 1};
};
In the line enum {RESULT = i * FACTOR<I-1>::RESULT};, what is the
purpose of the ::RESULT? As I understand it, this should be calling a
method called RESULT, but I don't think this is what is actually
happening.
Also, why is everything done on one line with enumerated types in
every template example I see? Why are enumerated types used instead
of normal loops? Is this because the loops must be evaluated as
constants at compile time?
Thanks!
years since I've touched C++, so this may actually be a C++ syntax
issue (although it seems that the language has changed somewhat.)
The following example comes from http://www.codeproject.com/KB/cpp/crc_meta.aspx
template< int i >
class FACTOR{
public:
enum {RESULT = i * FACTOR<I-1>::RESULT};
};
class FACTOR< 1 >{
public:
enum {RESULT = 1};
};
In the line enum {RESULT = i * FACTOR<I-1>::RESULT};, what is the
purpose of the ::RESULT? As I understand it, this should be calling a
method called RESULT, but I don't think this is what is actually
happening.
Also, why is everything done on one line with enumerated types in
every template example I see? Why are enumerated types used instead
of normal loops? Is this because the loops must be evaluated as
constants at compile time?
Thanks!