6
これは、パラメータとしてboost rangeを受け入れる独自の機能(例:DoSomethingWithRange
)を実装する良い方法ですか?boost :: Rangeをパラメータとして持つ関数の記述方法は?
#include <iostream>
#include <vector>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
using namespace std;
template <typename RangeType>
void DoSomethingWithRange(const RangeType &range)
{
typename RangeType::const_iterator beginIt = boost::begin(range);
typename RangeType::const_iterator endIt = boost::end(range);
for(typename RangeType::const_iterator it = beginIt; it != endIt; ++it)
{
cout << *it << endl;
}
}
bool IsPos(int i)
{
return i>0;
}
int main(int , char**)
{
vector<int> test;
test.push_back(1);
test.push_back(-1);
DoSomethingWithRange(test | boost::adaptors::filtered(IsPos));
}