- 242 名前:デフォルトの名無しさん mailto:sage [2009/10/25(日) 16:54:33 ]
- >>239 です
>>241 さんありがとうございます、ファクトリー関数を検索したのですが、具体的にイメージができません 下記のFooクラスおHogeクラスの間で継承関係を持たせ、operator() を自在に呼び出せないでしょうか。 #include <algorithm> #include <iostream> #include <vector> template<class T> class Foo { typedef typename std::iterator_traits<T>::value_type value_type; public: void operator()( const value_type& val ) { std::cout << val << "\n"; } }; template<class T> class Hoge { public: typedef typename std::iterator_traits<T>::value_type value_type; int operator()(const value_type& val) { return val; } }; int main() { std::vector<int> lhs, rhs; lhs.push_back(1); lhs.push_back(2); lhs.push_back(3); std::for_each(lhs.begin(), lhs.end(), Foo<std::vector<int>::iterator>()); std::transform(lhs.begin(), lhs.end(), std::back_inserter(rhs), Hoge<std::vector<int>::iterator>()); copy(rhs.begin(), rhs.end(), std::ostream_iterator<int>(std::cout, " ")); return 0; }
|

|