M
Matt Taylor
I am trying to use templates to create an optimal structure for a fixed-size
buffer that holds a homogenous array of elements. For brevity, this problem
is somewhat simplified from my implementation:
template<typename T1, size_t len>
struct buffer_t
{
// Array of elements
T1 ary[len / sizeof(T1)];
// Align upward to a multiple of sizeof(T1)
char pad[len - ((len / sizeof(T1)) * sizeof(T1))];
};
The problem is that, when len is a multiple of sizeof(T1), the pad variable
has length 0. For some reason the compiler finds this to be absurd. I need
to find some way to make this compile in that case. Is there any simple
resolution to this?
I am also wondering about the following:
template<typename T>
struct A
{
int a;
T b;
};
struct INGET
{
};
Why is A<INGET> legal but not A<void>? Semantically they would be the same,
right?
-Matt
buffer that holds a homogenous array of elements. For brevity, this problem
is somewhat simplified from my implementation:
template<typename T1, size_t len>
struct buffer_t
{
// Array of elements
T1 ary[len / sizeof(T1)];
// Align upward to a multiple of sizeof(T1)
char pad[len - ((len / sizeof(T1)) * sizeof(T1))];
};
The problem is that, when len is a multiple of sizeof(T1), the pad variable
has length 0. For some reason the compiler finds this to be absurd. I need
to find some way to make this compile in that case. Is there any simple
resolution to this?
I am also wondering about the following:
template<typename T>
struct A
{
int a;
T b;
};
struct INGET
{
};
Why is A<INGET> legal but not A<void>? Semantically they would be the same,
right?
-Matt