기본 콘텐츠로 건너뛰기

bind2nd 컴파일 오류2

bind2nd 컴파일 오류

아, 시바스 리갈 같은 상황. 이럴꺼면 뭣하러 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으로 막아놨다면 어떻게 할꺼야! 그렇다고 뽀인따로 죄다 바꿔!?



원본 위치: http://purewell.egloos.com/3517776

* 2014-04-30: C++11 표준은 위와 같은 문제를 해결해주었다.

댓글

이 블로그의 인기 게시물

Winget 해시 무시하기

가끔씩 Winget 에서 패키지를 다운로드 했을 때, "설치 관리자 해시가 일치하지 않습니다." 오류가 뜰 때가 있다. 보안 이슈가 있지만, 그냥 무시하고 싶을 때, 아래 순서로 무시해준다. 관리자 권한 winget settings --enable InstallerHashOverride 설치 winget install --ignore-security-hash --id NirSoft.NirCmd

Windows 11 기존 컨텍스트 메뉴 사용

Windows 11 에서, 컨텍스트 메뉴가 지저분한게 싫었는지, 모던 컨텍스트 메뉴라고 따로 필요한 것만 정리해서 보여준다. 그러나 이게 좀 불편하고, 기존의 꼭 필요한 메뉴가 보이지 않아 굳이 한 번 더 기존 메뉴를 불러오는데, 모든 앱들이 모던 컨텍스트 메뉴로 옮길 때까지는 기존 컨텍스트 메뉴를 기본으로 볼 수 있는 방법이 있다. REM 관리자 권한 REM 기존 컨텍스트 메뉴 reg.exe add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f /ve REM 모던 컨텍스트 메뉴로 되돌리기 reg.exe delete "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}" /f 이거 하고 탐색기를 재시작한다. 참조:  Restore old Right-click Context menu in Windows 11