使用模板参数计算某些值的 C++ 方法是什么?
template<typename T, size_t SIZE>
class ThreadSafeArray
{
private:
static const size_t BLOCK_SIZE = SIZE > 32 ? 16 : 4;
static const size_t MUTEX_COUNT = SIZE / BLOCK_SIZE + 1;
...
};
或这个
template<typename T, size_t SIZE>
class ThreadSafeArray
{
private:
enum
{
BLOCK_SIZE = SIZE > 32 ? 16 : 4,
MUTEX_COUNT = SIZE / BLOCK_SIZE + 1
};
....
};
或以其他方式?