기본 콘텐츠로 건너뛰기

After end iterator

enditr.cpp
#include <list>
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
using namespace std;

template<typename _T>
void
testSeqItr(void)
{
 _T some;
 typename _T::const_iterator ib;
 typename _T::const_iterator ie;
 typename _T::const_iterator it;

 for ( int i = 0; i < 1024; i++ )
 {
        some.push_back(rand());
 }

 ib = some.begin();
 ie = some.end();
 it = ie;
 ++it;

 cerr << __PRETTY_FUNCTION__ << endl;
 cerr << "begin equal? " << (ib==it) << endl;
 cerr << "end equal? " << (ie==it) << endl;
}

template<typename _T>
void
testAssItr(void)
{
 _T some;
 typename _T::const_iterator ib;
 typename _T::const_iterator ie;
 typename _T::const_iterator it;

 for ( int i = 0; i < 1024; i++ )
 {
        some.insert(make_pair(rand(),rand()));
 }

 ib = some.begin();
 ie = some.end();
 it = ie;
 ++it;

 cerr << __PRETTY_FUNCTION__ << endl;
 cerr << "begin equal? " << (ib==it) << endl;
 cerr << "end equal? " << (ie==it) << endl;
}

int
main(int,char**)
{
 srand((unsigned int)time(NULL));

 testSeqItr< basic_string<int> >();
 testSeqItr< list<int> >();
 testSeqItr< deque<int> >();
 testSeqItr< vector<int> >();

 testAssItr< map<int,int> >();
 testAssItr< multimap<int,int> >();

 return 0;
}
$ make enditr
g++ enditr.cpp -o enditr
./enditr
void testSeqItr() [with _T = std::basic_string<int, std::char_traits<int>, std::allocator<int> >]
begin equal? 0
end equal? 0
void testSeqItr() [with _T = std::list<int, std::allocator<int> >]
begin equal? 1
end equal? 0
void testSeqItr() [with _T = std::deque<int, std::allocator<int> >]
begin equal? 0
end equal? 0
void testSeqItr() [with _T = std::vector<int, std::allocator<int> >]
begin equal? 0
end equal? 0
void testAssItr() [with _T = std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >]
begin equal? 0
end equal? 0
void testAssItr() [with _T = std::multimap<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >]
begin equal? 0
end equal? 0
/usr/include/c++/*/bits/stl_*.h를 헤집어보면 속도를 위해 바운더리 체크 아무것도 안 하는 것을 알 수 있다. orz OTL
뭐, 리스트(더블링크드리스트)는 꼬리에 처음을 머리로 해놨겠지. 암튼, 반복자 잘 관리해야할 듯.

댓글

이 블로그의 인기 게시물

Winget 해시 무시하기

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

설치한 패키지에서 RPM 추출하기

오래된 패키지를 관리할 저장소가 없어졌고, 기존 패키지로 다른 서버를 세팅해야할 일이 생겼다면 RPM의 리패키지 기능을 이용해보자. $ rpm -e --repackage [PACKAGE_NAME] 위와 같이 리패키지하면, /var/spool/repackage/ 에 생성한 RPM파일이 있다. :-)