C++ 0x 具有模板别名(有时称为模板 typedef).请参阅此处.C++ 的当前规范没有.
C++ 0x has template aliases (sometimes referred to as template typedefs). See here. Current spec of C++ does not.
你喜欢用什么来解决?容器对象还是宏?你觉得值得吗?
What do you like to use as work around ? Container objects or Macros ? Do you feel its worth it ?
你喜欢用什么来解决?容器对象还是宏?你觉得值得吗?
What do you like to use as work around ? Container objects or Macros ? Do you feel its worth it ?
规范的方法是使用像这样的元函数:
The canonical way is to use a metafunction like thus:
template <typename T>
struct my_string_map {
typedef std::map<std::string, T> type;
};
// Invoke:
my_string_map<int>::type my_str_int_map;
这也用于 STL (allocator::rebind) 和许多库,包括 Boost.我们在生物信息库中广泛使用它.
This is also used in the STL (allocator::rebind<U>) and in many libraries including Boost. We use it extensively in a bioinformatical library.
它很臃肿,但在 99% 的情况下都是最好的选择.在这里使用宏是不值得的.
It's bloated, but it's the best alternative 99% of the time. Using macros here is not worth the many downsides.
(我修改了代码以反映 Daniel 在评论中指出的 Boost/STL 约定.)
( I've amended the code to reflect Boost/STL conventions as pointed out by Daniel in his comment.)
这篇关于模板 typedefs - 你的工作是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
std::reference_wrapper 和简单指针的区别?Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和简单指针的区别?)
常量之间的区别.指针和引用?Difference between const. pointer and reference?(常量之间的区别.指针和引用?)
c++ - 如何从指向向量的指针访问向量的内容?How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何从指向向量的指针访问向量的内容?)
*& 的含义和**&在 C++ 中Meaning of *amp; and **amp; in C++(*amp; 的含义和**amp;在 C++ 中)
为什么我不能对普通变量进行多态?Why can#39;t I do polymorphism with normal variables?(为什么我不能对普通变量进行多态?)
取消引用已删除的指针总是会导致访问冲突?Dereferencing deleted pointers always result in an Access Violation?(取消引用已删除的指针总是会导致访问冲突?)