[C++ STL] vector

์˜ค์ ผยท2022๋…„ 8์›” 27์ผ
0

[C++ STL]

๋ชฉ๋ก ๋ณด๊ธฐ
1/11

https://cplusplus.com/reference/vector/vector/?kw=vector

template < class T, class Alloc = allocator<T> > class vector;

Description

  • Vectors are sequence containers representing arrays that can change in size.

    ๐Ÿ‘‰ vector๋Š” ์‚ฌ์ด์ฆˆ๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋Š” ๋ฐฐ์—ด์„ ๋‚˜ํƒ€๋‚ด๋Š” sequence ์ปจํ…Œ์ด๋„ˆ

  • Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.

    ๐Ÿ‘‰ ๋ฐฐ์—ด์ฒ˜๋Ÿผ ์ธ์ ‘ํ•œ storage location์„ ์‚ฌ์šฉํ•จ. ๋”ฐ๋ผ์„œ element๋Š” ์ผ๋ฐ˜์ ์ธ ํฌ์ธํ„ฐ offset์œผ๋กœ๋„ ์•ก์„ธ์Šค ํ•  ์ˆ˜ ์žˆ์Œ. ๋ฐฐ์—ด๊ณผ ๋‹ค๋ฅธ ์ ์€ ๋™์ ์œผ๋กœ ์‚ฌ์ด์ฆˆ๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ. ์‚ฌ์ด์ฆˆ๋Š” ์ปจํ…Œ์ด๋„ˆ ์ž์ฒด์—์„œ ์ž๋™์œผ๋กœ ๋‹ค๋ฃธ.

  • Internally, vectors use a dynamically allocated array to store their elements. This array may need to be reallocated in order to grow in size when new elements are inserted, which implies allocating a new array and moving all elements to it. This is a relatively expensive task in terms of processing time, and thus, vectors do not reallocate each time an element is added to the container.

    ๐Ÿ‘‰ vector๋Š” ์žฌํ• ๋‹น ๋  ์ˆ˜ ์žˆ์Œ. ์ด๋Š” ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ƒˆ๋กœ ํ• ๋‹นํ•˜๊ณ  ๊ธฐ์กด์˜ ์›์†Œ๋ฅผ ์ƒˆ ๋ฐฐ์—ด์— ๋ชจ๋‘ ์ด๋™์‹œํ‚ค๋Š” ๊ฒƒ์„ ๋œปํ•จ. ๋น„์šฉ์ด ๋งŽ์ด ๋“œ๋Š” ์ž‘์—…์ด๊ธฐ ๋•Œ๋ฌธ์— ์›์†Œ ์ถ”๊ฐ€ํ•  ๋•Œ๋งˆ๋‹ค ๋งค๋ฒˆ ๋ฒกํ„ฐ๋ฅผ ์žฌํ• ๋‹นํ•˜์ง„ ์•Š์Œ.

  • Instead, vector containers may allocate some extra storage to accommodate for possible growth, and thus the container may have an actual capacity greater than the storage strictly needed to contain its elements (i.e., its size).

  • Libraries can implement different strategies for growth to balance between memory usage and reallocations, but in any case, reallocations should only happen at logarithmically growing intervals of size so that the insertion of individual elements at the end of the vector can be provided with amortized constant time complexity.

    ๐Ÿ‘‰ ๋ฒกํ„ฐ ์žฌํ• ๋‹น ๋ฐฉ๋ฒ•์€ libraries ์ „๋žต์— ๋”ฐ๋ผ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Œ but ํฌ๊ธฐ๊ฐ€ ๋Œ€์ˆ˜์ ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ๊ฐ„๊ฒฉ์—์„œ๋งŒ ์žฌํ• ๋‹น์ด ์ด๋ค„์ ธ์•ผ ํ•จ. ์ผ์ •ํ•œ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ์ œ๊ณต ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ.

Member types

Member functions

OCCF

constructor

  • https://cplusplus.com/reference/vector/vector/vector/
  • constructor์—์„œ ๋™์ ํ• ๋‹น ์ผ์–ด๋‚˜์•ผ ํ•จ
  • https://cplusplus.com/reference/memory/allocator/construct/
  • ๋™์ ํ• ๋‹น ํ›„ ๋ฒกํ„ฐ ์›์†Œ๋ฅผ ์ฑ„์šฐ๋Š” ๊ฑด _allocator.construct ๋กœ ํ•ด์ค˜์•ผ ํ•จ. ์›์†Œ value_type์ด ํ…œํ”Œ๋ฆฟ ํƒ€์ž…์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‹จ์ˆœ int, char ๋“ฑ์˜ ํƒ€์ž…์œผ๋กœ ์ƒ๊ฐํ•˜๋ฉด ์•ˆ ๋จ. ๊ฐ์ฒด๋กœ ์ƒ๊ฐํ•˜๊ณ  ์ ‘๊ทผ. std::allocator.construct๊ฐ€ ๊ฐ์ฒด ์ƒ์„ฑํ•˜๋Š” ์—ญํ• .
  • vector(size_type n, const value_type &val)๊ณผ vector(InputIterator first, InputIterator last) ์‚ฌ์ด์˜ ์˜ค๋ฒ„๋กœ๋”ฉ์„ ๋ช…ํ™•ํ•˜๊ฒŒ ํ•ด์ฃผ๊ธฐ ์œ„ํ•ด enable_if๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
  • https://modoocode.com/255
  • type_traits.hpp์—์„œ enable_if์™€ is_iterator๋ฅผ ๊ตฌํ˜„ํ•ด์ฃผ๊ณ  ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ InputIterator๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ ์ดํ„ฐ๋ ˆ์ดํ„ฐ์ธ ๊ฒฝ์šฐ์—๋งŒ range constructor๋กœ ์˜ค๋ฒ„๋กœ๋”ฉ ๋˜๊ฒŒ ํ•œ๋‹ค.
template < class InputIterator >
  vector(
    typename ft::enable_if < ft::is_iterator < InputIterator > ::value, InputIterator > ::type first,
    InputIterator last,
    const allocator_type & alloc = allocator_type()): _allocator(alloc), _capacity(last - first), _size(last - first) {
    _data = _allocator.allocate(_capacity);
    for (InputIterator it = first; it != last; it++)
      *(_data++) = *it;
  } // range

destructor

  • constructor์—์„œ ๋™์ ํ• ๋‹น ํ•ด์คฌ๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œํ•ด์ค˜์•ผ ํ•จ

operator=

Iterators

begin

end

rbegin

  • https://cplusplus.com/reference/vector/vector/rbegin/
  • ๋ฒกํ„ฐ ๋งˆ์ง€๋ง‰ ์š”์†Œ ๊ฐ€๋ฆฌํ‚ค๋Š” reverse_iterator ๋ฐ˜ํ™˜.
  • reverse_iterator, reverse_const_iterator ๋ฒ„์ „ ๋‘ ๊ฐœ
  • reverse_iterator(end()) ์œผ๋กœ initialization constructor ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ๋  ๋“ฏ

rend

  • https://cplusplus.com/reference/vector/vector/rend/
  • ๋ฒกํ„ฐ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ ๊ฐ€๋ฆฌํ‚ค๋Š” reverse_iterator ๋ฐ˜ํ™˜.
  • reverse_iterator, reverse_const_iterator ๋ฒ„์ „ ๋‘ ๊ฐœ
  • reverse_iterator(begin()) ์œผ๋กœ initialization constructor ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ๋  ๋“ฏ

cbegin

cend

Capacity

size

max_size

  • https://cplusplus.com/reference/vector/vector/max_size/
  • ํ• ๋‹น๊ฐ€๋Šฅํ•œ ๋ฒกํ„ฐ ์ตœ๋Œ€ ์‚ฌ์ด์ฆˆ ๋ฐ˜ํ™˜
  • std::allocator์— max_size ํ•จ์ˆ˜ ์žˆ์Œ. ๊ทธ๊ฑฐ ์‚ฌ์šฉ
  • ๋Œ€์‹  PTRDIFF_MAX๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜๋Š” ์—†์Œ. _allocator.max_size()๊ฐ€ PTRDIFF_MAX ๋ณด๋‹ค ์ปค๋„ PTRDIFF_MAX๋ฅผ ๋ฐ˜ํ™˜.
  • https://cplusplus.com/reference/memory/allocator/max_size/
  • !! https://stackoverflow.com/questions/28516686/does-max-size-of-stdvectorchar-have-a-bug &
    https://gcc.gnu.org/ml/gcc/2011-08/msg00221.html
  • ex) 64๋น„ํŠธ ์šด์˜์ฒด์ œ๋ผ๋ฉด charํ˜•์€ 2^64 - 1 ๋งŒํผ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•˜์ง€๋งŒ, ๊ทธ๋ ‡๊ฒŒ ํ• ๋‹นํ•ด๋ฒ„๋ฆฌ๋ฉด end - begin์ด ptrdiff_t์˜ ๋ฒ”์œ„๋ฅผ ์ดˆ๊ณผํ•˜๊ฒŒ ๋จ. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์• ์ดˆ์— std::vector์—์„œ๋Š” ptrdiff_t๊ฐ€ ๊ฐ๋‹นํ•  ์ˆ˜ ์žˆ๋Š” ๋ฒ”์œ„๋กœ ์ œํ•œํ•˜๊ณ  ์žˆ๋Š”๋“ฏ.

resize

  • https://cplusplus.com/reference/vector/vector/resize/
  • n๊ฐœ์˜ ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๋„๋ก ์ปจํ…Œ์ด๋„ˆ์˜ ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
  • n์ด current size๋ณด๋‹ค ์ž‘์œผ๋ฉด, ๋„˜์น˜๋Š” ๋ถ€๋ถ„์„ destroy.
  • n์ด ํ˜„์žฌ ์ปจํ…Œ์ด๋„ˆ ํฌ๊ธฐ๋ณด๋‹ค ํฌ๋ฉด n ํฌ๊ธฐ์— ๋„๋‹ฌํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋งŒํผ์˜ ์š”์†Œ๋ฅผ ๋์— ์‚ฝ์ž…ํ•˜์—ฌ ์ฝ˜ํ…์ธ ๋ฅผ ํ™•์žฅํ•ฉ๋‹ˆ๋‹ค.
  • n์ด ํ˜„์žฌ ์ปจํ…Œ์ด๋„ˆ ์šฉ๋Ÿ‰๋ณด๋‹ค ํฌ๋ฉด ํ• ๋‹น๋œ ์ €์žฅ ๊ณต๊ฐ„์ด ์ž๋™์œผ๋กœ ์žฌํ• ๋‹น๋ฉ๋‹ˆ๋‹ค.

capacity

empty

reserve

  • https://cplusplus.com/reference/vector/vector/reserve/
  • ๋งค๊ฐœ๋ณ€์ˆ˜ n์ด vector capacity ๋ณด๋‹ค ํฌ๋ฉด nํ˜น์€ n๋ณด๋‹ค ํฌ๊ฒŒ ๋ฒกํ„ฐ๋ฅผ ์žฌํ• ๋‹น ํ•ด์„œ ์›์†Œ ์ด์ „.
  • ์žฌํ• ๋‹นํ•  ๋•Œ 2๋ฐฐ์”ฉ capacity๋ฅผ ํ‚ค์›Œ์ค€๋‹ค๊ณ  ํ•จ.
  • ํ…Œ์ŠคํŠธํ•ด๋ณด๋‹ˆ ์ด์ „ _capacity * 2 ํ•œ ๊ฐ’๋ณด๋‹ค n์ด ํฌ๋ฉด ๊ทธ n์œผ๋กœ ํ•˜๊ณ  ์•„๋‹ˆ๋ฉด _capacity * 2๋กœ ํ• ๋‹นํ•ด์ฃผ๋Š” ๋“ฏ.
  • ์ด์ „ ํ•˜๊ณ  ๋‚˜๋ฉด ๊ธฐ์กด์˜ iterator๋“ค๊ณผ reference๋“ค์€ invalid ํ•ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ์ฃผ์˜ํ•ด์•ผํ•จ
  • ์š”์ฒญ๋œ ํฌ๊ธฐ๊ฐ€ ์ตœ๋Œ€ ํฌ๊ธฐ(vector::max_size)๋ณด๋‹ค ํฌ๋ฉด length_error ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒ. & ์žฌํ• ๋‹น์˜ ๊ฒฝ์šฐ ์ปจํ…Œ์ด๋„ˆ์˜ ํ• ๋‹น์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ† ๋ฆฌ์ง€๊ฐ€ ํ• ๋‹น๋˜๋ฉฐ, ์‹คํŒจ ์‹œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Œ(๊ธฐ๋ณธ ํ• ๋‹น์ž์˜ ๊ฒฝ์šฐ ํ• ๋‹น ์š”์ฒญ์ด ์„ฑ๊ณตํ•˜์ง€ ์•Š์œผ๋ฉด bad_alloc์ด throw๋จ).
    => std::allocator์—์„œ ์•Œ์•„์„œ throw ๋จ

Element access

oprator[]

at

  • https://cplusplus.com/reference/vector/vector/at/
  • n์ด _size๋ณด๋‹ค ํฌ๋ฉด out_of_range ์—๋Ÿฌ throw.
  • ๋ฒ”์œ„๋ฅผ ํ™•์ธํ•˜์ง€ ์•Š๋Š” []์™€ ๋Œ€์กฐ๋œ๋‹ค.

front

  • https://cplusplus.com/reference/vector/vector/front/
  • ๋ฒกํ„ฐ์˜ ์ฒซ ๋ฒˆ์งธ ์›์†Œ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋ฐ˜ํ™˜.
  • iterator๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” begin๊ณผ ๋Œ€์กฐ๋œ๋‹ค.
  • ๋นˆ ์ปจํ…Œ์ด๋„ˆ์—์„œ ์ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์ •์˜๋˜์ง€ ์•Š์€ ๋™์ž‘์ด ๋ฐœ์ƒํ•œ๋‹ค.
  • ํ• ๋‹นํ•˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ ๋ ˆํผ๋Ÿฐ์Šค ๋ฐ˜ํ™˜ ํ•ด์„œ ๊ทธ๋Ÿฐ๋“ฏ? ํ•จ์ˆ˜ ๋‚ด์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ•ด์ฃผ์ง€ ์•Š๊ณ  ๋ฌด์กฐ๊ฑด ์ฒซ ๋ฒˆ์งธ ์›์†Œ ๋ ˆํผ๋Ÿฐ์Šค ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ํ•˜๋ฉด ๋จ.

back

  • https://cplusplus.com/reference/vector/vector/back/
  • ๋ฒกํ„ฐ์˜ ๋งˆ์ง€๋ง‰ ์›์†Œ ๋ ˆํผ๋Ÿฐ์Šค ๋ฐ˜ํ™˜.
  • iterator๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” end์™€ ๋Œ€์กฐ๋œ๋‹ค.
  • ์ด๊ฒƒ๋„ ๋นˆ ์ปจํ…Œ์ด๋„ˆ์ผ ๋•Œ ์ •์˜๋˜์ง€ ์•Š์€ ๋™์ž‘ ๋ฐœ์ƒ

Modifiers

assign

  • https://cplusplus.com/reference/vector/vector/assign/
  • ๋ฒกํ„ฐ์— ์ƒˆ ๋‚ด์šฉ์„ ํ• ๋‹นํ•˜๊ณ  ํ˜„์žฌ ๋‚ด์šฉ์„ ๋ฐ”๊พธ๊ณ  ๊ทธ์— ๋”ฐ๋ผ ํฌ๊ธฐ๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.

push_back

  • https://cplusplus.com/reference/vector/vector/push_back/
  • ํ˜„์žฌ ๋งˆ์ง€๋ง‰ ์š”์†Œ ๋‹ค์Œ์— ๋ฒกํ„ฐ์˜ ๋์— ์ƒˆ ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. val์˜ ๋‚ด์šฉ์ด ์ƒˆ ์š”์†Œ๋กœ ๋ณต์‚ฌ(๋˜๋Š” ์ด๋™)๋ฉ๋‹ˆ๋‹ค.
  • ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ ํฌ๊ธฐ๊ฐ€ 1์”ฉ ์ฆ๊ฐ€ํ•˜์—ฌ ์ƒˆ ๋ฒกํ„ฐ ํฌ๊ธฐ๊ฐ€ ํ˜„์žฌ ๋ฒกํ„ฐ ์šฉ๋Ÿ‰์„ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ ํ• ๋‹น๋œ ์ €์žฅ ๊ณต๊ฐ„์ด ์ž๋™์œผ๋กœ ์žฌํ• ๋‹น๋ฉ๋‹ˆ๋‹ค.

pop_back

  • https://cplusplus.com/reference/vector/vector/pop_back/
  • ๋ฒกํ„ฐ์˜ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ ํฌ๊ธฐ๋ฅผ 1๋กœ ํšจ๊ณผ์ ์œผ๋กœ ์ค„์ž…๋‹ˆ๋‹ค.
  • ๋ฐ˜ํ™˜ํ•˜๋Š” ์›์†Œ ์—†์Œ. ๊ฑ ์ง€์šฐ๋Š” ๊ฑฐ. ๋งˆ์ง€๋ง‰ ์›์†Œ destoryํ•œ ๋‹ค์Œ size ์ค„์ด๋ฉด ๋  ๋“ฏ.
  • ์›์†Œ 0์ผ ๋•Œ ๋”ฐ๋กœ ์ฒ˜๋ฆฌ ์•ˆ ํ•ด์คŒ. ์›๋ž˜ std vector๋„ ๊ทธ๋Ÿผ.

insert

  • https://cplusplus.com/reference/vector/vector/insert/
  • ์ด๊ฑด ์ธ์ž๋กœ ๋ฐ›์€ positoin ์•ž์— ์‚ฝ์ž…ํ•˜๋Š” ๊ฑฐ
  • ๋ฒกํ„ฐ๋Š” ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— insertํ•˜๋ฉด position ๋’ค์˜ ์ธ๋ฑ์Šค๋ฅผ ๋‹ค ํ•œ ์นธ์”ฉ ๋’ค๋กœ ๋ฏธ๋ค„์ค˜์•ผ ํ•จ.
  • ๋‹ค๋ฅธ list ๊ธฐ๋ฐ˜์— ๋น„ํ•ด ๋น„ํšจ์œจ์ .

erase

  • https://cplusplus.com/reference/vector/vector/erase/
  • ๋ฒ”์œ„ ํ˜น์€ position์— ์žˆ๋Š” ์›์†Œ destroy.
  • eraseํ•œ ๋ฒ”์œ„ ๋‹ค์Œ์— ์žˆ๋˜ ์›์†Œ๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” iterator๋ฐ˜ํ™˜.
  • first๋ถ€ํ„ฐ last๊นŒ์ง€ ์ง€์šฐ๊ณ  ๋’ค์— ์žˆ๋Š” ๊ฑฐ first์ชฝ์œผ๋กœ ๋•ก๊ฒจ์˜ค๋‹ˆ๊นŒ ๊ฒฐ๊ตญ first ๋ฐ˜ํ™˜ํ•ด์ฃผ๋ฉด ๋จ.

swap

  • https://cplusplus.com/reference/vector/vector/swap/
  • ๋‘ ๋ฒกํ„ฐ ๊ตํ™˜. a <-> b
  • ์ด์ „์— = assignmanet๋ฅผ ๊ตฌํ˜„ํ•ด๋†จ๊ธฐ ๋•Œ๋ฌธ์— ๊ฑ ์›๋ž˜ ์Šค์™‘ ํ•  ๋•Œ ์“ฐ๋Š” tmp = x; x = *this; *this = tmp; ์“ฐ๋ฉด ๋จ -->!!! ใ„ดใ„ด ์ด๋Ÿฌ๋ฉด ๋ถˆํ•„์š”ํ•œ ํ•ด์ œ ์ผ์–ด๋‚˜๊ฒŒ ๋จ. ๊ฑ ๊ฐ ๋ณ€์ˆ˜๋งˆ๋‹ค ft::swap ์จ์„œ ๋ณ€์ˆ˜๋ผ๋ฆฌ ์„œ๋กœ ๊ตํ™˜ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค˜์•ผ ํ•จ

clear

ํ• ๋‹น ํ•จ์ˆ˜ ๋น„๊ต

ํ•จ์ˆ˜๋ช…content changesize changecapacity change
reserve๊ธฐ์กด ์ปจํ…์ธ  ์•ˆ ๊ฑด๋“ค์ž„size ์•ˆ ๋ฐ”๊ฟˆcapacity๋งŒ ๋ฐ”๊ฟˆ
resize๊ธฐ์กด ์ปจํ…์ธ  ์•ˆ ๊ฑด๋“ค์ž„.
but ๋ฐ”๊พธ๋ ค๋Š” ์‚ฌ์ด์ฆˆ๊ฐ€ ํ˜„์žฌ ์ปจํ…์ธ  ์‚ฌ์ด์ฆˆ๋ณด๋‹ค ๋” ํฌ๋ฉด
๋‚˜๋จธ์ง€ ๋ถ€๋ถ„์€ ์ƒˆ๋กœ์šด ๊ฐ’์œผ๋กœ ์ฑ„์šธ ์ˆ˜ ์žˆ์Œ
size ๋ฐ”๊ฟˆcapacity ๋ฐ”๊ฟˆ
assign๊ธฐ์กด ์ปจํ…์ธ  ๊ฑด๋“ค์ž„. ์•„์˜ˆ ์‹น ๋ฐ”๊พธ๋Š” ๊ฑฐsize ๋ฐ”๊ฟˆcapacity ๋ฐ”๊ฟˆ

Allocator

get_allocator

Non-member function overloads

relational operators

operator==

  • ๊ฐ™์Œ ๋น„๊ต(operator==)๋Š” ๋จผ์ € ํฌ๊ธฐ๋ฅผ ๋น„๊ตํ•˜์—ฌ ์ˆ˜ํ–‰ํ•˜๊ณ , ์ผ์น˜ํ•˜๋ฉด operator==๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์š”์†Œ๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ๋น„๊ตํ•˜๊ณ  ์ฒซ ๋ฒˆ์งธ ๋ถˆ์ผ์น˜์—์„œ ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค(๊ฐ™์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ).
  • algorithm header์— ์žˆ๋Š” equal์„ namespace ft๋กœ ํ•˜๋‚˜ ๋” ๋งŒ๋“ค์–ด์ค˜์„œ ์‚ฌ์šฉ
  • https://cplusplus.com/reference/algorithm/equal/?kw=equal

operator!=

  • ๋งŒ๋“ค์–ด๋‘” == ์‚ฌ์šฉํ•ด์„œ !(lhs == rhs) ํ•ด์ฃผ๋ฉด ๋จ

operator<

  • ๋ณด๋‹ค ์ž‘์Œ ๋น„๊ต(operator<)๋Š” lexicographical_compare ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ operator<๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์š”์†Œ๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค(์ฆ‰, a<b ๋ฐ b<a ๋ชจ๋‘ ํ™•์ธ).
  • algorithm ํ—ค๋”์— ์žˆ๋Š” lexicographical_compare namespace ft๋กœ ํ•˜๋‚˜ ๋” ๋งŒ๋“ค์–ด์ค˜์„œ ์‚ฌ์šฉ
  • https://cplusplus.com/reference/algorithm/lexicographical_compare/

operator<=

  • ๊ตฌํ˜„ํ•ด๋’€๋˜ operator< ์‚ฌ์šฉ
  • !(rhs < lhs) lhs <= rhs๋ž‘ ๋˜‘๊ฐ™์Œ

operator>

  • ๊ตฌํ˜„ํ•ด๋’€๋˜ operator< ์‚ฌ์šฉ
  • (rhs < lhs)

operator>=

  • ๊ตฌํ˜„ํ•ด๋’€๋˜ operator< ์‚ฌ์šฉ
  • !(lhs < rhs) rhs <= lhs ๋ž‘ ๋˜‘๊ฐ™์Œ

swap

๋~~

0๊ฐœ์˜ ๋Œ“๊ธ€