我在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