【C++】template 統合スレ -- Part6at TECH【C++】template 統合スレ -- Part6 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト200:デフォルトの名無しさん 05/01/09 13:29:34 スマートポインタを使ってるならただのポインタに変えてみる。 ただのポインタなら実体に変えてみる。 実体ならポインタに変えてみる。 201:デフォルトの名無しさん 05/01/09 13:33:31 set_intersection の result は OutputIterator なので、 *result = common (or *result++ = common) がカウントアップの動作をするような擬似イテレータを作れば、 コピーのコストを無くすことができそうだ。 202:デフォルトの名無しさん 05/01/09 13:39:05 うっ、そこを触ることになりますか… Iteratorの中身について理解が出来ていないので全くの手探りになりますが、資料ひっくり返して勉強します ありがとうございました 203:デフォルトの名無しさん 05/01/09 14:48:42 暇つぶしにやってみた。 boost::counting_iterator がそのまま使えるかと思ったけど OutputIterator じゃなかった。 しょうがないから結局ファンクタ書く羽目になった。 #include <cstddef> #include <algorithm> #include "boost/function_output_iterator.hpp" template<typename Incrementable> class increment { Incrementable* m_target; // not reference to make this class Assignable public: increment(Incrementable& target) : m_target(&target) {} template<typename T> void operator () (T const&) { ++*m_target; } }; template<typename InputIterator1, typename InputIterator2> std::size_t count_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2) { std::size_t result = 0; std::set_intersection(first1, last1, first2, last2 , boost::make_function_output_iterator(increment<std::size_t>(result))); return result; } lambda 使えば、 increment くらい消せるかも。 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch