Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Select Numbers less than 10
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
using namespace std;
template <class T>
void print(T& c){
for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
std::cout << *i << endl;
}
}
template<class InputIterator, class OutputIterator, class Predicate >
OutputIterator copy_if( InputIterator start, InputIterator stop,OutputIterator out, Predicate select ){
while( start != stop ){
if( select( *start ) )
*out++ = *start;
++start;
}
return out;
}
int main( )
{
const int numbers = 7;
const int num[numbers] = { 5, 0, 3, 2, 1, 4, 7 };
vector<int> v1( num, num+numbers );
print( v1 );
vector<int> v2;
copy_if( v1.begin(), v1.end(), back_inserter( v2 ),bind2nd( less<int>(), 10 ) );
print( v2 );
}