更新时间:2023-11-30 22:33:22
很多用例,所以让我们来看看它们是不可或缺的一些情况:
There are many use-cases, so let's look at a couple of situations where they are indispensable:
固定大小的数组或 matrix 类,请参阅示例C ++ 11 std :: array 或 boost :: array
Fixed sized array or matrix classes, see for example C++11 std::array or boost::array.
std :: begin ,或任何需要固定大小C样式数组大小的代码,例如:
A possible implementation of std::begin for arrays, or any code that needs the size of a fixed size C style array, for example:
返回数组的大小:
template <typename T, unsigned int N>
unsigned int size(T const (&)[N])
{
return N;
}
它们在模板元编程中也非常有用。
They are also extremely useful in template metaprogramming.