Hi, I get it (on VC++2003) as the problem being a lack of return_type typedefs. Hossein Haeri wrote:
#include <iostream> #include <algorithm> #include <iterator> #include <vector> #include <boost/bind.hpp> #include <boost/mem_fn.hpp>
using std::ostream; using std::cin; using std::cout; using std::copy; using std::for_each; using std::ostream_iterator; using std::vector; using boost::bind; using boost::mem_fn;
template <class Container, size_t i> struct print {
typedef ostream& result_type;
ostream& operator () (const Container& c, ostream& out) const { if(out) { typedef typename Container::value_type value_type; typedef print<value_type, i - 1> NewPrint; NewPrint newPrint; /* for(typename Container::const_iterator j = c.begin(); j != c.end(); ++j) newPrint(*j, out); */ for_each(c.begin(), c.end(), bind(newPrint, _2, out)); //Error! } return out; } };
template <class Container> struct print<Container, 1> {
typedef ostream& result_type;
ostream& operator () (const Container& c, ostream& out) const { if(out) copy(c.begin(), c.end(), ostream_iterator<typename Container::value_type>(out, " ")); return out; } ostream& DoIt (const Container& c, ostream& out) const { if(out) copy(c.begin(), c.end(), ostream_iterator<typename Container::value_type>(out, " ")); return out; } };
int main() { int a1[] = {1, 2, 3, 4}; const size_t n(sizeof(a1)/sizeof(*a1));
vector<int> v(a1, a1 + n); print<vector<int>, 1> () (v, cout);
int a2[n] = {5, 6, 7, 8}; vector<vector<int> > m; m.push_back(v); m.push_back(vector<int>(a2, a2 + n)); print<vector<vector<int> >, 2> () (m, cout);
cin.get(); return 0; }
Bye, Steve