|
쉽게 설명해주셔서 감사합니다.
영어가 짧아서 그런지 모르겠지만 헬프에서도 워쉽님의 설명은 안보이는것 같던데..
덕분에 아주 쉽게 이해되었습니다.
WARSHIP 님이 쓰신 글 :
: 이돈진 님이 쓰신 글 :
: : 제목과 같습니다.
: :
: : STL 함수중에서 bind1st와 bind2nd의 차이점이 뭔가요?
:
: 두개의 파라메터중에
: 첫번째를 고정할지 두번째를 고정시킬지에 따라 선택하게 됩니다. ^^
:
: #include <stdio.h>
: #include <vector>
: #include <algorithm>
: #include <functional>
:
: using namespace std;
:
:
: int main(int argc, char *argv[])
: {
: vector<int> IntVec;
: for(int i=0;i<100;++i) IntVec.push_back(i);
:
: printf( "bind1st(greater<int>(),30) : %d\n",*find_if(IntVec.begin(),IntVec.end(),
: bind2nd(greater<int>(),30)));
: printf( "bind2st(greater<int>(),30) : %d\n",*find_if(IntVec.begin(),IntVec.end(),
: bind1st(greater<int>(),30)));
:
: return 0;
: }
:
: 결과 :
: bind1st(greater<int>(),30) : 0
: bind2st(greater<int>(),30) : 31
:
: bind1st 의 경우 30을 첫번째 파라메터에 고정시켰기 때문에
: if ( 30 > *Iterator ) 로 검사를 하기 때문에 바로 0 에서 true로 리턴해 버리구요
:
: bin2nd 의 경우 30을 두번째 파라메터에 고정시켰기 때문에
: if ( *Iterator > 30 ) 로 검사를 하기 때문에 원하는 31에서 true로 리턴하게 됩니다.
:
: 아마 쉽게 이해가 되셨으리라고 생각합니다 ^^;
|