Last active
November 9, 2019 12:09
-
-
Save Ben1980/e7ee2f3bfd2470977d2d7b5c0a1b0f44 to your computer and use it in GitHub Desktop.
Parts of std::vector implementation from https://gcc.gnu.org/onlinedocs/gcc-9.2.0/libstdc++/api/a07959.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pointer | |
_M_allocate(size_t __n) | |
{ | |
typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; | |
return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer(); //(3) | |
} | |
void | |
_M_create_storage(size_t __n) | |
{ | |
this->_M_impl._M_start = this->_M_allocate(__n); //(2) | |
this->_M_impl._M_finish = this->_M_impl._M_start; | |
this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; | |
} | |
/** | |
* @brief Creates a %vector with default constructed elements. | |
* @param __n The number of elements to initially create. | |
* @param __a An allocator. | |
* | |
* This constructor fills the %vector with @a __n default | |
* constructed elements. | |
*/ | |
explicit | |
vector(size_type __n, const allocator_type& __a = allocator_type()) | |
: _Base(_S_check_init_len(__n, __a), __a) //(1) | |
{ _M_default_initialize(__n); } | |
/** | |
* @brief Subscript access to the data contained in the %vector. | |
* @param __n The index of the element for which data should be | |
* accessed. | |
* @return Read/write reference to data. | |
* | |
* This operator allows for easy, array-style, data access. | |
* Note that data access with this operator is unchecked and | |
* out_of_range lookups are not defined. (For checked lookups | |
* see at().) | |
*/ | |
reference | |
operator[](size_type __n) _GLIBCXX_NOEXCEPT | |
{ | |
__glibcxx_requires_subscript(__n); | |
return *(this->_M_impl._M_start + __n); //(4) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment