C++ boost 模板参数特征
我相信我在boost中见过恢复模板模板参数的宏,例如:
template<class>
struct parameters;
#define parameters(T) template<class A> \
struct parameters<T<A> > { typedef A type1; };
有这样的宏吗,还是我错了?
谢谢
I believe I had seen macro in boost that recovers template template parameters, for example:
template<class>
struct parameters;
#define parameters(T) template<class A> \
struct parameters<T<A> > { typedef A type1; };
is there one like this, or am I wrong?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C++0x 中的
delctype
支持使得实现起来相当简单:(尽管您需要为具有 2、3、4 等参数的模板单独定义 get_type。)
不幸的是,我认为没有是一种无需 decltype 即可实现此目的的方法,因为这样做需要自动执行函数模板提供的类型推导(这不适用于类模板),因此无法以这种方式创建 typedef。
我不知道 boost 是否已经有类似的东西,但如果他们这样做,它仍然需要你的编译器支持
decltype
,但由于 decltype 太新了,所以没有太多东西在 boost 中还使用它(尽管有一些)。delctype
support in C++0x makes this fairly trivial to implement:(Though you need a separate get_type definition for templates with 2, 3, 4, etc parameters.)
Unfortunately, I don't think there is a way to do this without decltype, because to do so required automatic the type-deduction provided by function templates (which is not available for class templates) and so there's no way to make a typedef that way.
I don't know off-hand if boost has anything like this already, but if they do it will still require your compiler to support
decltype
, but since decltype is so new there is not a lot of stuff in boost that uses it yet (though there is some).我已经学会相信约翰内斯的陈述,所以我有点困惑,因为这似乎用 VC10 对我来说编译好并打印预期的
int
:当然,因为我没有检查任何其他编译器,这可能只是 VC 再次愚弄我......
I have learned to trust Johannes' statements, so I'm a bit confused, since this seems to compile Ok for me with VC10 and prints the expected
int
:Of course, since I didn't check with any other compilers, this could just be VC fooling me again...