【发布时间】:2014-04-30 04:10:10
【问题描述】:
在llvm-3.4\include\llvm\ADT\STLExtras.h,我看到了这个函数:
/// Find the length of an array.
template<class T, std::size_t N>
inline size_t array_lengthof(T (&)[N]) {
return N;
}
此函数返回数组长度:
int main(){
const char spaces[] = "dededesdf sdf sdfs fdsf"
"dadsds jsdfdfs ffjsdklfj dsfds";
std::cout << array_lengthof(spaces); //prints 54
return 0;
}
有人能解释一下这个函数是如何工作的以及参数T (&)[N]是什么意思吗?
是否存在此功能不起作用的场景?
【问题讨论】:
标签: c++ arrays templates function-templates