그러다가 local function object는 stl algorithm 류의 함수들의 인자로 사용하지 못한다는 것을 최근에
알게되었습니다. 예를 들면 다음과 같은 함수, 컴파일이 안됩니다.
void foo(const std::vector<int>& v) {
using namespace std;
struct IntPrinter: public unary_function<int, void> {
IntPrinter(ostream& os, const string& delim): os(os), delim(delim) {}
void operator()(int n) const { this->os << n << this->delim; }
ostream& os;
const string& delim;
};
for_each(v.begin(), v.end(), IntPrinter(cout, "\t"));
cout << endl;
}
정확히 알고 계신분들이 이 글 보신다면 지적 부탁드립니다.
@ 참고로 위 코드는 걍 예제로 써먹기 좋은 코드를 쓴 것 뿐입니다. stl을 활용하면 아래와 같겠죠. :(
void foo(const std::vector<int>& v) {
using namespace std;
copy(v.begin(), v.end(), ostream_iterator<int>(cout, "\t"));
cout << endl;}