模板typedefs - 你的工作是什么? [英] Template typedefs - What's your work around?
问题描述
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< U&
)和许多图书馆,包括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.
这是blo肿,但它是最好的替代99%的时间。在这里使用宏是不值得的许多缺点。
It's bloated, but it's the best alternative 99% of the time. Using macros here is not worth the many downsides.
(编辑:我修改了代码反映Boost / STL惯例由丹尼尔在他的评论指出。
( I've amended the code to reflect Boost/STL conventions as pointed out by Daniel in his comment.)
这篇关于模板typedefs - 你的工作是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!