我在C++高度模板代码和代码工作是推动我疯了,因为我经常要惹这样的可憎各地:C++如何使模板代码更加清晰
std::pair<typename P<A, B>::const iterator, std::pair<long, typename P<A, B>::const_iterator> p;
(没有C++ 11元组)
这:
template <A, B, C, D, E>
class MyClass {
private:
P <A, B> p;
Q <C, D> q;
// (does nothing with A, B, C, D but has to use the template because
// this class uses other templated classes P<A, B> and Q<C, D>)
// ...
};
有没有一种方法,使代码更清洁,更具有可读性喜欢使用typedef
或其他的技巧?
编辑: 认为P和Q为std :: maps,我不知道类型。
这里是〜我的代码是如何工作的
template<A, B, C, D>
class MapWrapper {
private:
std::map< map<A, B>::const_iterator, map<C, D>::const_iterator > _map;
public:
void insert_in_map (map<A, B>::const_iterator one, map<C, D>::const_iterator two) {
_map[one] = two;
}
};
是的,用'typedef'或'using'。但你已经说过,在这个问题上,所以我不确定你在找什么...... –
我如何使用typedef来减少模板?我不能使用,因为模板的一个副作用是我必须把所有代码放在.h –
您的问题中的长表达式std :: pair <...'是无效的... – Danvil