Witam mam problem z ***H = *B ** w search_iter , nie wiem dlaczego nie mogę przypisać do listy wartości z vectora. Search_iter miał się zachowywac jak remove_copy_if . Czy znalazł by się ktoś i napisał, gdzie błędnie rozumuje ?
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <random>
#include <vector>
#include <iterator>
#include <list>
using namespace std;
struct Kula {
int r;
Kula()
: r(0)
{
}
Kula(int r_)
: r(r_)
{
}
};
struct Gen {
int x, y;
Gen(int x_, int y_)
: x(x_)
, y(y_)
{
}
Kula operator()()
{
int seed = rand() % (y - x + 1) + x;
if (seed == 15 || seed == 21) {
return Kula(15);
}
return Kula(seed);
}
};
ostream& operator<<(ostream& out, const Kula& ob)
{
return out << ob.r;
}
struct wedlugR {
bool operator()(const Kula& ob, const Kula& ob2)
{
return ob.r > ob2.r;
}
};
struct Mnoz {
int operator()(const Kula& ob)
{
return ob.r * ob.r * 3.14 * 4;
}
};
template <typename IterWej, typename IterWyj, typename Pred>
IterWyj search_iter(IterWej B, IterWej E, IterWyj H, Pred P)
{
for (; B != E; B++) {
if (P(*B)) {
// *H = *B;
H++;
}
}
return H;
}
int main()
{
srand(time(NULL));
vector<Kula> vec(10);
generate(vec.begin(), vec.end(), Gen(10, 20));
copy(vec.begin(), vec.end(), ostream_iterator<Kula>(cout, " "));
cout << endl;
sort(vec.begin(), vec.end(), wedlugR());
copy(vec.begin(), vec.end(), ostream_iterator<Kula>(cout, " "));
list<Kula> lst;
transform(vec.begin(), vec.end(), back_inserter(lst), Mnoz());
cout << endl;
copy(lst.begin(), lst.end(), ostream_iterator<Kula>(cout, " "));
int tab[] = { 1, 2, 3, 4 };
vector<int> v(tab, tab + 4);
list<vector<int>::iterator> lst2(4);
list<vector<int>::iterator>::iterator out = search_iter(v.begin(), v.end(), lst2.begin(), bind2nd(greater<int>(), 1));
return 0;
}