Pub*_*bby 5 c++ templates sizeof template-specialization c++11
我正在尝试使用 GCC 4.7 快照做一些类似的事情:
\n\ntemplate <int n, int... xs>\nstruct foo { \n static const int value = 0;\n};\n\n// partial specialization where n is number of ints in xs:\n\ntemplate <int... xs>\nstruct foo<sizeof...(xs), xs...> { // error: template argument \xe2\x80\x98sizeof (xs ...)\xe2\x80\x99\n // involves template parameter(s)\n static const int value = 1;\n};\n\ntemplate <int... xs>\nstruct foo<sizeof(xs), xs...> { // This compiles fine. sizeof(xs) is sizeof int \n // even though packs aren't expanded\n static const int value = 2;\n};\nRun Code Online (Sandbox Code Playgroud)\n\n该错误很奇怪,因为在这种情况下, sizeof 而不是 sizeof... 起作用。两者似乎都可以在编译时轻松计算。
\n\n编译器是否正确,我不能sizeof...在模板参数中使用专业化?
| 归档时间: |
|
| 查看次数: |
1664 次 |
| 最近记录: |