■29861 / ) |
Re[5]: テンプレート変数からイテレータ変数の宣言 |
□投稿者/ あんどちん (33回)-(2008/12/15(Mon) 23:52:19)
|
STLのコンテナしか受けないのならその処理の部分だけテンプレート関数にするのはダメですか?
#include <iostream> #include <vector> #include <list> using namespace std;
template<typename T> inline void func(T& v) { for(typename T::iterator it = v.begin(); it != v.end(); ++it) { cout << *it << endl; } }
int main() { int ia[] = { 1, 2, 3, 4, 5 }; double da[] = { 1.1, 2.2, 3.3, 4.4, 5.5 };
list<int> il(ia, ia + 5); vector<double> dv(da, da + 5);
func(il); func(dv); }
|
|