working typedef
This commit is contained in:
@@ -4,12 +4,17 @@
|
|||||||
# include "colors.h"
|
# include "colors.h"
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
# include <string>
|
# include <string>
|
||||||
|
|
||||||
# include <memory> // std::allocator
|
# include <memory> // std::allocator
|
||||||
|
|
||||||
class ftvector {
|
class ftvector {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef int value_type;
|
||||||
|
typedef std::allocator<int> allocator_type;
|
||||||
|
typedef std::size_t size_type;
|
||||||
|
|
||||||
ftvector();
|
ftvector();
|
||||||
ftvector( ftvector const & src );
|
ftvector( ftvector const & src );
|
||||||
~ftvector();
|
~ftvector();
|
||||||
@@ -36,20 +41,17 @@ public:
|
|||||||
* capacity :
|
* capacity :
|
||||||
************/
|
************/
|
||||||
// size
|
// size
|
||||||
// TMP
|
size_type size() const;
|
||||||
unsigned int size() const;
|
|
||||||
// TMP END
|
|
||||||
// size_type size() const;
|
|
||||||
// max_size
|
// max_size
|
||||||
// size_type max_size() const;
|
// size_type max_size() const;
|
||||||
// resize
|
// resize
|
||||||
// void resize(size_type n, value_type val = value_type());
|
// void resize(size_type n, value_type val = value_type());
|
||||||
// capacity
|
// capacity
|
||||||
size_type capacity() const;
|
// size_type capacity() const;
|
||||||
// empty
|
// empty
|
||||||
// bool empty() const;
|
// bool empty() const;
|
||||||
//reserve
|
//reserve
|
||||||
// void reserve(size_type n);
|
void reserve(size_type n);
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
* element access :
|
* element access :
|
||||||
@@ -75,10 +77,7 @@ public:
|
|||||||
// void assign(InputIterator first, InputIterator last);
|
// void assign(InputIterator first, InputIterator last);
|
||||||
// void assign(size_type n, const value_type& val);
|
// void assign(size_type n, const value_type& val);
|
||||||
// push_back
|
// push_back
|
||||||
// TMP
|
void push_back(const value_type & val);
|
||||||
void push_back(const int & element);
|
|
||||||
// TMP END
|
|
||||||
// void push_back(const value_type& val);
|
|
||||||
// pop_back
|
// pop_back
|
||||||
// void pop_back();
|
// void pop_back();
|
||||||
// insert
|
// insert
|
||||||
@@ -97,9 +96,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::size_t _size;
|
size_type _size;
|
||||||
int * _mem_ptr;
|
value_type * _mem_ptr;
|
||||||
std::allocator<int> _allocator;
|
allocator_type _allocator;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,10 @@
|
|||||||
|
|
||||||
ftvector::ftvector()
|
ftvector::ftvector()
|
||||||
: _size(0)
|
: _size(0)
|
||||||
, _space(0) {
|
//, _space(0)
|
||||||
|
{
|
||||||
// std::cout << COPLIEN_COLOR "ftvector constructor" RESET "\n";
|
// std::cout << COPLIEN_COLOR "ftvector constructor" RESET "\n";
|
||||||
_allocator = std::allocator<int>();
|
_allocator = allocator_type();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,42 +54,41 @@ ftvector & ftvector::operator=( ftvector const & rhs ) {
|
|||||||
* ACCESSORS
|
* ACCESSORS
|
||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
||||||
unsigned int ftvector::size() const {return _size;}
|
ftvector::size_type ftvector::size() const {return _size;}
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
* PUBLIC MEMBER FUNCTIONS
|
* PUBLIC MEMBER FUNCTIONS
|
||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
||||||
void ftvector::push_back(const int & element) {
|
void ftvector::push_back(const value_type & element) {
|
||||||
if (_size == _space)
|
// if (_size == _space)
|
||||||
hold_space(1);
|
reserve(1);
|
||||||
_allocator.construct(&_mem_ptr[_size], element);
|
_allocator.construct(&_mem_ptr[_size], element);
|
||||||
_size++;
|
_size++;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < _size; i++)
|
for (size_type i = 0; i < _size; i++)
|
||||||
std::cout << _mem_ptr[i] << "\n";
|
std::cout << _mem_ptr[i] << "\n";
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
* PRIVATE MEMBER FUNCTIONS
|
* PRIVATE MEMBER FUNCTIONS
|
||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
||||||
void hold_space(std::size_t add_space) {
|
void ftvector::reserve(size_type add_space) {
|
||||||
|
|
||||||
if (add_space == 0)
|
if (add_space == 0)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
int * tmp_ptr;
|
// int * tmp_ptr;
|
||||||
|
//
|
||||||
if (_space > 0 && add_space == 1)
|
// if (_space > 0 && add_space == 1)
|
||||||
{
|
// {
|
||||||
add_space = _space * 2;
|
// add_space = _space * 2;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
tmp_ptr = _allocator.allocate(add_space);
|
// tmp_ptr = _allocator.allocate(add_space);
|
||||||
// _mem_ptr = _allocator.allocate(add_space);
|
_mem_ptr = _allocator.allocate(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user