Last Updated on December 5, 2021 by Admin 2
What happens when you attempt to compile and run the following code?
#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
class B {
int val;
public:
B(int v):val(v){}
operator int() { return val;}
};
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<” “; } };
struct Sequence { int start;
Sequence(int start):start(start){}
int operator()() { return start++; } };
bool predicate(int v) { return v%2==0; }
int main() {
vector<int> v1(10);
generate_n(v1.begin(), 10, Sequence(1));
for_each(v1.begin(), remove_if(v1.begin(), v1.end(), predicate), Out<int>(cout));cout<<endl;
return 0;}
Program outputs:
- 1 3 5 7 9 6 7 8 9 10
- 1 3 5 7 9
- 2 4 6 8 10
- compilation error
- no output