Merged latest tintystl.

This commit is contained in:
Branimir Karadžić
2015-10-16 09:02:39 -07:00
parent d84f2b2307
commit 137a52ccf7
2 changed files with 27 additions and 7 deletions

View File

@@ -179,9 +179,11 @@ namespace tinystl {
Alloc::static_deallocate(b->first, sizeof(T)*capacity);
b->capacity = b->first;
} else if (b->capacity != b->last) {
const size_t capacity = (size_t)(b->capacity - b->first);
const size_t size = (size_t)(b->last - b->first);
T* newfirst = (T*)Alloc::static_allocate(sizeof(T) * size);
buffer_move_urange(newfirst, b->first, b->last);
Alloc::static_deallocate(b->first, sizeof(T) * capacity);
b->first = newfirst;
b->last = newfirst + size;
b->capacity = b->last;
@@ -225,6 +227,26 @@ namespace tinystl {
new(placeholder(), where) T();
}
template<typename T, typename Alloc, typename Param>
static inline void buffer_append(buffer<T, Alloc>* b, const Param* param) {
if (b->capacity != b->last) {
new(placeholder(), b->last) T(*param);
++b->last;
} else {
buffer_insert(b, b->last, param, param + 1);
}
}
template<typename T, typename Alloc>
static inline void buffer_append(buffer<T, Alloc>* b) {
if (b->capacity != b->last) {
new(placeholder(), b->last) T();
++b->last;
} else {
buffer_insert(b, b->last, 1);
}
}
template<typename T, typename Alloc>
static inline T* buffer_erase(buffer<T, Alloc>* b, T* first, T* last) {
typedef T* pointer;

View File

@@ -228,20 +228,18 @@ namespace tinystl {
template<typename T, typename Alloc>
inline void vector<T, Alloc>::push_back(const T& t) {
buffer_insert(&m_buffer, m_buffer.last, &t, &t + 1);
buffer_append(&m_buffer, &t);
}
template<typename T, typename Alloc>
inline void vector<T, Alloc>::emplace_back()
{
buffer_insert(&m_buffer, m_buffer.last, 1);
inline void vector<T, Alloc>::emplace_back() {
buffer_append(&m_buffer);
}
template<typename T, typename Alloc>
template<typename Param>
inline void vector<T, Alloc>::emplace_back(const Param& param)
{
buffer_insert(&m_buffer, m_buffer.last, &param, &param + 1);
inline void vector<T, Alloc>::emplace_back(const Param& param) {
buffer_append(&m_buffer, &param);
}
template<typename T, typename Alloc>