On Wed, 27 Sep 2006 14:29:42 -0700, shuisheng wrote:
Quote:
If I have a template like
>
template<class _T, size_t nDim, size_t *p>
class TinyVector
{ };
>
Here nDim is number of dimensions of the array, p saves the size of the
array. This template will have lots of uses for my project.
>
such as p = {3, 4, 5}, nDim = 3, _T = double, I defines a 3D Array with
given size 3 * 4 * 5.
I don't have a rigorously worked out reason for this, but using an array to
specify compile-time constants seems wrong to me. Maybe you could try something
like:
#include <iostream>
template<int One = 0, int Two = 0, int Three = 0, int Four = 0, int Five = 0>
class dimensions
{
public:
static const int _1 = One;
static const int _2 = Two;
static const int _3 = Three;
static const int _4 = Four;
static const int _5 = Five;
};
int main()
{
typedef dimensions<3, 4, 5dim;
std::cout << "Dimensions: " << dim::_1 << ", " << dim::_2 << ", " << dim::_3 << std::endl;
}