floating point non-type template parameters

幻夢之葉 2014-06-20 02:01:13
谁能解释下这个概念?
不是要中文的含义,是概念上的。
...全文
160 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
幻夢之葉 2014-06-24
  • 打赏
  • 举报
回复
引用 6 楼 FrankHB1989 的回复:
[quote=引用 5 楼 FrankHB1989 的回复:] [quote=引用 4 楼 FrankHB1989 的回复:] [quote=引用 3 楼 jianwen0529 的回复:] [quote=引用 2 楼 FrankHB1989 的回复:] 你用的编译器太烂,错误提示抽风。 blog.sina.com.cn/s/blog_4bc03a140100076x.html
这个我懂。 我只是不明白非类型的意思是指不是类类型?! [/quote] non-type不是non-class-type。模板非类型参数是指不以class和typename起始声明的type-parameter(非泛型);一般来说,还排除了type-parameter以template起始的模板模板参数(高阶参数化多态): N3936/14.1 137) Since template template-parameters and template template-arguments are treated as types for descriptive purposes, the terms non-type parameter and non-type argument are used to refer to non-type, non-template parameters and arguments. [/quote] 具体来说template<class T, float f> void func(T) {}里的float f这个parameter-parameter引入的模板参数f就不是类型参数,因为f表示具体类型的值而不是任意的类型(用Haskell的话来说,f不是一个类型变量)。 [/quote] …… parameter-parameter →template-parameter[/quote] 感谢回答,大体明白了。 现在也在看non-type的一些概念和模板参数的限定。 辛苦了
FrankHB1989 2014-06-24
  • 打赏
  • 举报
回复
引用 5 楼 FrankHB1989 的回复:
[quote=引用 4 楼 FrankHB1989 的回复:] [quote=引用 3 楼 jianwen0529 的回复:] [quote=引用 2 楼 FrankHB1989 的回复:] 你用的编译器太烂,错误提示抽风。 blog.sina.com.cn/s/blog_4bc03a140100076x.html
这个我懂。 我只是不明白非类型的意思是指不是类类型?! [/quote] non-type不是non-class-type。模板非类型参数是指不以class和typename起始声明的type-parameter(非泛型);一般来说,还排除了type-parameter以template起始的模板模板参数(高阶参数化多态): N3936/14.1 137) Since template template-parameters and template template-arguments are treated as types for descriptive purposes, the terms non-type parameter and non-type argument are used to refer to non-type, non-template parameters and arguments. [/quote] 具体来说template<class T, float f> void func(T) {}里的float f这个parameter-parameter引入的模板参数f就不是类型参数,因为f表示具体类型的值而不是任意的类型(用Haskell的话来说,f不是一个类型变量)。 [/quote] …… parameter-parameter →template-parameter
FrankHB1989 2014-06-24
  • 打赏
  • 举报
回复
引用 4 楼 FrankHB1989 的回复:
[quote=引用 3 楼 jianwen0529 的回复:] [quote=引用 2 楼 FrankHB1989 的回复:] 你用的编译器太烂,错误提示抽风。 blog.sina.com.cn/s/blog_4bc03a140100076x.html
这个我懂。 我只是不明白非类型的意思是指不是类类型?! [/quote] non-type不是non-class-type。模板非类型参数是指不以class和typename起始声明的type-parameter(非泛型);一般来说,还排除了type-parameter以template起始的模板模板参数(高阶参数化多态): N3936/14.1 137) Since template template-parameters and template template-arguments are treated as types for descriptive purposes, the terms non-type parameter and non-type argument are used to refer to non-type, non-template parameters and arguments. [/quote] 具体来说template<class T, float f> void func(T) {}里的float f这个parameter-parameter引入的模板参数f就不是类型参数,因为f表示具体类型的值而不是任意的类型(用Haskell的话来说,f不是一个类型变量)。
FrankHB1989 2014-06-24
  • 打赏
  • 举报
回复
引用 3 楼 jianwen0529 的回复:
[quote=引用 2 楼 FrankHB1989 的回复:] 你用的编译器太烂,错误提示抽风。 blog.sina.com.cn/s/blog_4bc03a140100076x.html
这个我懂。 我只是不明白非类型的意思是指不是类类型?! [/quote] non-type不是non-class-type。模板非类型参数是指不以class和typename起始声明的type-parameter(非泛型);一般来说,还排除了type-parameter以template起始的模板模板参数(高阶参数化多态): N3936/14.1 137) Since template template-parameters and template template-arguments are treated as types for descriptive purposes, the terms non-type parameter and non-type argument are used to refer to non-type, non-template parameters and arguments.
幻夢之葉 2014-06-23
  • 打赏
  • 举报
回复
引用 2 楼 FrankHB1989 的回复:
你用的编译器太烂,错误提示抽风。 blog.sina.com.cn/s/blog_4bc03a140100076x.html
这个我懂。 我只是不明白非类型的意思是指不是类类型?!
FrankHB1989 2014-06-20
  • 打赏
  • 举报
回复
你用的编译器太烂,错误提示抽风。 blog.sina.com.cn/s/blog_4bc03a140100076x.html
幻夢之葉 2014-06-20
  • 打赏
  • 举报
回复

// C2993.cpp
// compile with: /c
// C2993 expected
struct MyStruct {
   int a;char b;
};

template <class T, struct MyStruct S>   // C2993

// try the following line instead 
// template <class T, struct MyStruct * S>
class CMyClass {};
还有struct 为何被认为是floating point non-type template parameters 这个我理解
// C2993b.cpp
// compile with: /c
template<class T, float f> void func(T) {}   // C2993

// OK
template<class T>   void func2(T, float) {}

65,192

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧