STL

위키백과 ― 우리 모두의 백과사전.

다른 뜻·사람에 대해서는 STL (동음이의) 문서를 참고하십시오.

STL은 Standard Template Library의 약자로서, C++에서 일반적인 자료 구조와 알고리즘을 구현해 놓은 라이브러리의 집합이다. 지원하는 자료구조에는 vector, map, set 등이 있으며, 여러 가지 탐색 변경 알고리즘을 지원해 주고 있다. vector와 같은 자료 구조에 삽입할 변수의 형이 정해지 있지 않고, 일반적인 형이라고 가정한 뒤 vector와 같은 컨테이너가 구현되어 있다. 즉 이 때는 C++언어의 template 기능을 이용하고 있다. 이처럼 자료의 유형에 상관없이 구현되어 있기 때문에 generic이라고 말하기도 한다.

목차

[편집] 컨테이너

[편집] vector

[편집] 개요

[편집] 함수 목록

원형 설명
vector<T>::vector<T>() vector<T> c; 빈 vector c를 생성한다.
vector<T>::vector<T>(const T& t) vector<int> c1(c2); 같은 type의 원소를 갖는 vector c1을 c2로부터 생성한다. 즉 c2를 복사하여 c1을 만든다.
vector<T>::vector<T>(size_type vector_size) vector<double> c(10); T의 default 생성자를 호출하여 만든 type T의 instance n로 c를 채운다.
vector<T>::vector<T>(size_type element_number, const T& element) vector<int> c(10,0); type T인 element 원소를 element_number개 생성하여 c에 복사한다.
vector<T>::vector<T>(iterator first_pos, iterator last_pos) code>vector<int> c(old.begin(), old.end()); [beg, end)의 원소를 c로 복사하여 초기화한다.
vector<T>::~vector<T>() c.~(); 메모리를 해제한다. 이 함수를 명시적으로 호출하는 경우는 별로 없다.
검사 함수
size_type vector<T>::size() int size = (int)c.size(); 벡터 안에 들어 있는 원소의 갯수를 반환한다. int 타입임을 보장할 수 없는 것에 주의해야 한다. size_type은 compiler마다 다르게 정의되어 있다.
bool vector<T>::empty() if(matrix.empty() == false){ 벡터 안에 원소가 하나라도 있으면 false를 반환한다. size()==0; 을 호출하는 것보다 효율적이다.
size_type vector<T>::max_size()
size_type vector<T>::capacity()
void vector<T>::reserve(size_type new_size) a.reserve(file_size); 벡터에 new_size의 갯수를 저장할 수 있는 공간을 미리 확보한다.
bool vector<T>::operator==(const vector<T>& new_value) if(old_vector == new_vector){
bool vector<T>::operator!=(const vector<T>& v);
bool vector<T>::operator<(const vector<T>& v);
bool vector<T>::operator>(const vector<T>& v);
bool vector<T>::operator<=(const vector<T>& v);
bool vector<T>::operator>=(const vector<T>& v);
할당 관련 동작
vector<T>& operator=(const vector<T>& v);
assign(n, elem)
assign(beg, end)
void vector<T>::swap(vector<T>& target_vector)
swap(c1, c2)
at(idx)
T& vector<T>::operator[](size_type index);
const T& vector<T>::front() const
T& vector<T>::back()
반복자 관련 함수들
const_iterator vector<T>::begin() const
const_iterator vector<T>::end() const
reverse_iteator vector<T>::rbegin()
reverse_iterator vector<T>::rend()
원소의 수정
iterator vector<T>::insert(iterator pos, const T& t)
void vector<T>::insert(iterator pos, size_type n, const T& t)
void vector<T>::insert(iterator pos, InputIterator begin, InputIterator end)
void vector<T>::push_back(const T& t)
void vector<T>::pop_back()
iterator vector<T>::erase(iterator pos)
iterator vector<T>::erase(iterator beg, iterator end)
void vector<T>::resize(size_type num)
void vector<T>::resize(size_type num, const T& t)
void vector<T>::clear()
  • deque
  • list
  • set과 multiset
  • map과 multimap

[편집] 알고리즘

이 문서는 컴퓨터에 관한 토막글입니다. 서로의 지식을 모아 알차게 문서를 완성해 갑시다.