0
基本上我有幾種情況,我使用boost::filter_iterator
來過濾某些條件的迭代器。有一種情況,我想同時過濾兩種情況,並且我們已經有一些預先存在的代碼,但是我想知道是否有一種慣用的方法可以通過增強或標準庫來實現:任何使用boost MPL或類似的迭代器過濾器的方法
/*! TODO: Surely there should be something in std/boost to achieve this??? */
/*! Filter for things that satisfy F1 and F2 */
template <
typename F1,
typename F2,
typename ArgT
>
struct filter_and
{
F1 f1;
F2 f2;
filter_and(F1 _f1, F2 _f2): f1(_f1), f2(_f2)
{}
inline bool operator() (ArgT const& arg) const
{
return f1(arg) && f2(arg);
}
};
如果解決方案需要C++ 11,只要最新的MSVC可以處理它就應該沒問題。
爲什麼不把兩個迭代器疊加在一起? – ipc 2013-02-26 20:17:18
@ipc,我其實並沒有想到這樣做,也許這是一個不錯的選擇。 – shuttle87 2013-02-26 20:43:42