little formating improvement
This commit is contained in:
@@ -51,31 +51,35 @@ ftvector & ftvector::operator=( ftvector const & rhs ) {
|
||||
// return (o);
|
||||
//}
|
||||
|
||||
/*********************************************
|
||||
* ACCESSORS
|
||||
*********************************************/
|
||||
|
||||
ftvector::size_type ftvector::size() const {return _size;}
|
||||
|
||||
/*********************************************
|
||||
* PUBLIC MEMBER FUNCTIONS
|
||||
*********************************************/
|
||||
|
||||
void ftvector::push_back(const value_type & element) {
|
||||
if (_size >= _capacity)
|
||||
{
|
||||
reserve(std::min(_size + 1, _allocator.max_size() / 2) * 2);
|
||||
}
|
||||
_allocator.construct(&_mem_ptr[_size], element);
|
||||
_size++;
|
||||
|
||||
for (size_type i = 0; i < _size; i++)
|
||||
std::cout << _mem_ptr[i] << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
/*************
|
||||
* iterators :
|
||||
*************/
|
||||
// begin -------------------------------------
|
||||
ftvector::iterator ftvector::begin() {return _mem_ptr;}
|
||||
// end ---------------------------------------
|
||||
ftvector::iterator ftvector::end() {return &_mem_ptr[_size];}
|
||||
// rbegin ------------------------------------
|
||||
// rend --------------------------------------
|
||||
|
||||
/************
|
||||
* capacity :
|
||||
************/
|
||||
// size --------------------------------------
|
||||
ftvector::size_type ftvector::size() const {return _size;}
|
||||
// max_size ----------------------------------
|
||||
// resize ------------------------------------
|
||||
// capacity ----------------------------------
|
||||
// empty -------------------------------------
|
||||
// reserve -----------------------------------
|
||||
void ftvector::reserve(size_type new_cap) {
|
||||
value_type * tmp_ptr;
|
||||
iterator first = begin();
|
||||
iterator last = end();
|
||||
|
||||
if (new_cap > _allocator.max_size())
|
||||
throw std::length_error("new_cap > max_size");
|
||||
@@ -89,19 +93,62 @@ void ftvector::reserve(size_type new_cap) {
|
||||
|
||||
if (_mem_ptr)
|
||||
{
|
||||
// TMP
|
||||
// TMP replacing assign()
|
||||
for (size_type i = 0; i < _size; i++)
|
||||
tmp_ptr[i] = _mem_ptr[i];
|
||||
// TMP END
|
||||
_destroy(first, last);
|
||||
_allocator.deallocate(_mem_ptr, _capacity);
|
||||
}
|
||||
_mem_ptr = tmp_ptr;
|
||||
}
|
||||
|
||||
/******************
|
||||
* element access :
|
||||
******************/
|
||||
// operator[] --------------------------------
|
||||
// at ----------------------------------------
|
||||
// front -------------------------------------
|
||||
// back --------------------------------------
|
||||
|
||||
/*************
|
||||
* modifiers :
|
||||
*************/
|
||||
// assign ------------------------------------
|
||||
// push_back ---------------------------------
|
||||
void ftvector::push_back(const value_type & element) {
|
||||
if (_size >= _capacity)
|
||||
reserve(std::min(_size + 1, _allocator.max_size() / 2) * 2);
|
||||
_allocator.construct(&_mem_ptr[_size], element);
|
||||
_size++;
|
||||
|
||||
// TMP
|
||||
for (size_type i = 0; i < _size; i++)
|
||||
std::cout << _mem_ptr[i] << "\n";
|
||||
std::cout << "\n";
|
||||
// TMP END
|
||||
}
|
||||
// pop_back ----------------------------------
|
||||
// insert ------------------------------------
|
||||
// erase -------------------------------------
|
||||
// swap --------------------------------------
|
||||
// clear -------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
* PRIVATE MEMBER FUNCTIONS
|
||||
*********************************************/
|
||||
|
||||
void ftvector::_destroy(iterator first, iterator last) {
|
||||
while (first != last)
|
||||
{
|
||||
_allocator.destroy(first);
|
||||
first++;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************
|
||||
* NESTED CLASS
|
||||
*********************************************/
|
||||
|
||||
Reference in New Issue
Block a user