-
std::string
- constructor
- string(const char*s)
- string(int n, char c)
c를 n개 반복
- string(const string& str)
copy constructor
- string()
empty string
- string(const char*s, int n)
s를 n자리까지만 자름
- template<class Iter> string(Iter begin, Iter end)
Iter의 begin~end 전까지 이어붙임
- string(const string& str, int pos, int n)
string의 pos에서 n개만 자름
- string(string && str) noexcept
move constructor: const로 취급하지 않음.
- compare
- s1<s2, s1==s2, s1> s2 가능
더 길거나 알파벳이 크면 크다.
- size
-
Smart Pointer
- constructor
tamplate<class Type> explicit auto_ptr(Type* ptr);
- no implicit type conversion allowed
shared_ptr<double> pd;
double *p = new double;
pd = p; //error
pd = shared_ptr<double>(p);
- delete가 필요 없다.
- *, -> 사용 가능
- 레퍼런스를 받으면 안됨; 레퍼런스를 delete 하기 때문
-
auto_ptr
only one pointer to one object
assignment: transfer ownership
***no more use
-
unique_ptr
only one pointer to one object
NO assignment allowed
-
shared_ptr
many pointers point one object
delete when counter=0
- making smart pointers
- constructor, destructor
- overload =, *, ->
- deep copy needed
- with arrays
use delete : delete[]아님!
- NOT ALLOWED:
shared_ptr<int> ptr(new int[n]);
- ALLOWED:
shared_ptr<int[]> ptr(new int [n]); (c++17)
-
<vector>
- vector<int> a(n,0);
- a.size()
- a.begin(), a.end()
- a.push_back()
- a.erase()
- a.insert()
- #include <algorithm>
sort(a.begin(), a.end());
random_shuffle(a.begin(), a.end());
for_each(a.begin(), a.end(), func); //func에 (*it) 하나씩 들어감
- 하나씩 가져오는 for_each
for_each(a.begin(), a.end(), []type& n){~}
- range based for loop
for(int x:a) cout<<x; //하나씩 출력
for(int &x:a) x = 2; //전부 2가 됨
-
iterators
generalization of pointer
*로 접근(dereferencing)
++로 이동 가능(incrementing)
-
Container
objects are owned by container
objects: copy constructable, assignable
- Sequence containers
vector, array, stack, queue, deque, priority_queue, list
- Associative containers
key-values
set, map, multiset, multimap
- Unordered Associative containers(C++11)
unordered key-values
unordered_set, unordered_map, unordered_multiset, unordered_multimap
-
Functor(펑터) = Function objects
함수처럼 ()과 함께 쓸 수 있는 것
- 함수 이름: func()
- 함수 포인터: (*func)()
- ()오버로드된 객체: myclass()
-
STL의 Functor
#include <functional>

ex) sort(a.begin(), a.end(), greater)
-
<initializer_list>
초기화 리스트이다.
{}로 묶여 있다.
vector(initializer_list<T> init, const Allocator&alloc = Allocator());
- vector<int> v1 {10}; //10 한개
//initiallizer_list를 생성하고 이를 인수로 받는 생성자가 호출된다.
- int func(initializer_list<int> ini){~}
func({1,2,3});