我刚刚发现 boost::array::static_size 不是 tr1::array 的一部分,或者至少它不在我的实现中(GCC 4.2.1),并且我在任何 tr1 文档中都找不到它。
是否有另一种方法可以对 tr1 数组中的元素数量执行编译时断言?
例如,以下内容适用于 boost 数组,但不适用于 tr1 数组:
template<typename T>
void CheckArray(const T& input) {
BOOST_STATIC_ASSERT(T::static_size >= 2);
}
我知道我可以只使用 boost 的数组,但我很好奇。
如果没有办法做到这一点,也许有人知道为什么 static_size 没有包含在 tr1 中?难道只是tr1创建后为boost添加的一个功能?
I just found out that boost::array::static_size isn't part of tr1::array, or at least it's not in my implementation (GCC 4.2.1) and I can't find it in any tr1 documentation.
Is there another way to perform a compile-time assertion on the number of elements in a tr1 array?
e.g. The following works with a boost array but not a tr1 array:
template<typename T>
void CheckArray(const T& input) {
BOOST_STATIC_ASSERT(T::static_size >= 2);
}
I know I can just use boost's array instead, but I'm curious.
If there's no way to do it, maybe someone knows why static_size wasn't included in tr1? Is it just a feature that was added to boost after tr1 was created?
发布评论
评论(1)
TR1 本身表示 std::tuple_size >::value 返回
N
,即数组的大小。TR1 itself says that
std::tuple_size<array<T, N> >::value
returnsN
, the size of the array.