7 #ifndef CMAGIC_VECTOR_HPP 8 #define CMAGIC_VECTOR_HPP 11 #include <type_traits> 40 static_assert(std::is_copy_assignable<T>(),
"value type must be copy-assignable");
41 static_assert(std::is_copy_constructible<T>(),
"value type must be copy-constructible");
42 CMAGIC_VECTOR(T) vector_handle;
47 bool allocate_back() {
52 template <
typename URef>
53 bool push_back_template(URef &&val) {
55 if (!allocate_back()) {
90 vector_handle =
nullptr;
107 vector_handle = x.vector_handle;
148 assert(pos <=
size());
156 assert (pos <=
size());
170 return push_back_template(val);
177 return push_back_template(std::move(val));
190 template<
typename... Args>
193 if (!allocate_back()) {
254 return &(*this)[
size()];
262 return &(*this)[
size()];
279 operator bool()
const {
280 return static_cast<bool>(vector_handle);
const value_type & operator[](size_type pos) const
Returns a reference to the element at position pos in the vector container.
Definition: vector.hpp:155
static vector custom_allocation_vector()
Constructs an empty vector using custom CMagic memory allocation from memory.h.
Definition: vector.hpp:75
#define CMAGIC_VECTOR_DATA(cmagic_vector)
Gets an address to the beginning of the vector data.
Definition: vector.h:53
Set of allocation functions. Used in some CMagic structures to specify a desired memory pool...
Definition: memory.h:187
#define CMAGIC_VECTOR_FREE(cmagic_vector)
Frees the resources allocated by the vector before.
Definition: vector.h:79
value_type * begin()
Return iterator to beginning.
Definition: vector.hpp:231
size_type size() const
Returns the number of elements in the vector.
Definition: vector.hpp:124
const value_type * end() const
Return iterator to end.
Definition: vector.hpp:260
#define CMAGIC_VECTOR_POP_BACK(cmagic_vector)
Deallocates the last element in the vector.
Definition: vector.h:108
bool push_back(value_type &&val)
Add element at the end.
Definition: vector.hpp:176
const value_type * begin() const
Return iterator to beginning.
Definition: vector.hpp:239
#define CMAGIC_VECTOR_BACK(cmagic_vector)
Gets an address of the last element in the vector.
Definition: vector.h:61
value_type & operator[](size_type pos)
Returns a reference to the element at position pos in the vector container.
Definition: vector.hpp:147
vector()
Constructs an empty vector with standard memory allocation.
Definition: vector.hpp:68
bool empty() const
Returns whether the vector is empty (i.e. whether its size is 0).
Definition: vector.hpp:135
#define CMAGIC_VECTOR_GET_ALLOC_PACKET(cmagic_vector)
Extracts cmagic_memory_alloc_packet_t which was used as an argument of CMAGIC_VECTOR_NEW.
Definition: vector.h:123
T value_type
Type of vector elements.
Definition: vector.hpp:32
value_type * end()
Return iterator to end.
Definition: vector.hpp:252
bool emplace_back(Args &&... args)
Construct and insert element at the end.
Definition: vector.hpp:191
Implementation of a vector container.
A sequence container representing array that can change in size.
Definition: vector.hpp:26
#define CMAGIC_VECTOR_ALLOCATE_BACK(cmagic_vector)
Allocates space for a new element but does not initialize it.
Definition: vector.h:88
bool push_back(const value_type &val)
Add element at the end.
Definition: vector.hpp:169
static const cmagic_memory_alloc_packet_t CMAGIC_MEMORY_ALLOC_PACKET_STD
Allocation from the standard library.
Definition: memory.h:196
size_t size_type
Type used to measure element size and position in a vector.
Definition: vector.hpp:37
void pop_back()
Delete last element.
Definition: vector.hpp:207
static const cmagic_memory_alloc_packet_t CMAGIC_MEMORY_ALLOC_PACKET_CUSTOM_CMAGIC
Custom allocation from the CMagic library.
Definition: memory.h:203
#define CMAGIC_VECTOR_NEW(type, alloc_packet)
Allocates and returns an address of a newly created empty vector.
Definition: vector.h:71
void clear()
Removes all elements from the vector (which are destroyed), leaving the container with a size of 0...
Definition: vector.hpp:219
#define CMAGIC_VECTOR_SIZE(cmagic_vector)
Deallocates the last element in the vector.
Definition: vector.h:115