bind2nd 컴파일 오류
아, 시바스 리갈 같은 상황. 이럴꺼면 뭣하러 STL써!
Call by value하면 허천나게 느리잖아! 만약 assign operator와 copy constructor를 private으로 막아놨다면 어떻게 할꺼야! 그렇다고 뽀인따로 죄다 바꿔!?
아, 시바스 리갈 같은 상황. 이럴꺼면 뭣하러 STL써!
#include <list>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
typedef struct mystorage
{
int i;
char c;
} mystorage;
#if defined(POINTER_TYPE)
typedef list<mystorage*> mylist;
#else
typedef list<mystorage> mylist;
#endif
#if defined(POINTER_TYPE)
inline
bool
check(const mystorage* _s, int id)
{
const mystorage& s(*_s);
#else
inline
bool
check(const mystorage s, int id)
// You can't use below function type.
// Standard C++ does not support ref of ref.
//check(const mystorage& s, int id)
{
#endif
return s.i == id;
}
void
addList(mylist& lst)
{
for ( size_t i(0); i<1000; i++ )
{
#if defined(POINTER_TYPE)
lst.push_front(new mystorage);
mystorage& s(**lst.begin());
#else
lst.push_front(mystorage());
mystorage& s(*lst.begin());
#endif
s.i = i;
s.c = i%26+'A';
}
}
int
main(int,char**)
{
mylist lst;
mylist::iterator ib;
addList(lst);
ib = find_if(lst.begin(), lst.end(),
bind2nd(ptr_fun(check), 10)
);
if ( ib != lst.end() )
{
#if defined(POINTER_TYPE)
const mystorage& s(**ib);
#else
const mystorage& s(*ib);
#endif
cout << "ib->i: " << s.i << endl;
cout << "ib->c: " << s.c << endl;
}
return 0;
}
Call by value하면 허천나게 느리잖아! 만약 assign operator와 copy constructor를 private으로 막아놨다면 어떻게 할꺼야! 그렇다고 뽀인따로 죄다 바꿔!?
댓글
댓글 쓰기