S
suresh
Hi
My following code compiles but I do not know how to write this without using decltype. I have written my failed attempts in commented lines below the line which uses decltype.My motivation is the STL copy algorithm which accepts an output iterator as the 3rd argument.
Thanks
suresh
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
template<class Out>
class Fill{
public:
Fill(){}
void fill(Out x){
for(int i = 0; i != 10; i++)*x++ = i;
}
};
int main(){
vector<int> v;
Fill<decltype(back_inserter(v))> f; //works
//does not work
//Fill<vector<int>::iterator> g;
//does not work
//Fill<back_insert_iterator<vector<int>> h;
f.fill(back_inserter(v));
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
}
My following code compiles but I do not know how to write this without using decltype. I have written my failed attempts in commented lines below the line which uses decltype.My motivation is the STL copy algorithm which accepts an output iterator as the 3rd argument.
Thanks
suresh
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
template<class Out>
class Fill{
public:
Fill(){}
void fill(Out x){
for(int i = 0; i != 10; i++)*x++ = i;
}
};
int main(){
vector<int> v;
Fill<decltype(back_inserter(v))> f; //works
//does not work
//Fill<vector<int>::iterator> g;
//does not work
//Fill<back_insert_iterator<vector<int>> h;
f.fill(back_inserter(v));
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
}