1#ifndef NE_STL_INCLUDENE_STL_CONTINUOUS_CONTAINER_
2#define NE_STL_INCLUDENE_STL_CONTINUOUS_CONTAINER_
12template <
class TElement,
13 element_malloc_fun_t<TElement> _malloc = memory::safe_malloc_container_element<TElement>,
14 element_delete_fun_t<TElement> _delete = memory::safe_delete_container_element<TElement>>
29 static_assert(std::is_standard_layout<TElement>::value,
"TElement should standard layout");
40 static_assert(std::is_standard_layout<TElement>::value,
"TElement should standard layout");
50 other.data_ =
nullptr;
51 other.malloc_fun_ =
nullptr;
52 other.delete_fun_ =
nullptr;
54 other.cap_length_ = 0;
64 static_assert(std::is_standard_layout<TElement>::value,
"TElement should standard layout");
74 static_assert(std::is_standard_layout<TElement>::value,
"TElement should standard layout");
85 static_assert(std::is_standard_layout<TElement>::value,
"TElement should standard layout");
96 for (
auto it : other) {
107 for (
auto it : other) {
118 for (
auto it : init) {
158 if (
this != &other) {
165 if (
this != &other) {
170 other.data_ =
nullptr;
172 other.cap_length_ = 0;
177 template <
typename T>
180 for (
auto it : other) {
183 *
this = templateContainer;
186 operator std::vector<TElement>() {
187 std::vector<TElement> ret;
188 for (
auto it : *
this) {
189 ret.emplace_back(it);
193 operator std::vector<TElement>()
const {
194 std::vector<TElement> ret;
195 for (
auto it : *
this) {
196 ret.emplace_back(it);
200 template <
class TSTDVectorItem>
201 operator std::vector<TSTDVectorItem>() {
202 std::vector<TSTDVectorItem> ret;
203 for (
auto it : *
this) {
204 ret.emplace_back(it);
208 template <
class TSTDVectorItem>
209 operator std::vector<TSTDVectorItem>()
const {
210 std::vector<TSTDVectorItem> ret;
211 for (
auto it : *
this) {
212 ret.emplace_back(it);
221 for (
auto iter : *
this) {
232 for (std::size_t index = 0; index <
length_; ++index) {
233 if (
find(other[index]) ==
end()) {
251 const TElement&
at(std::size_t i)
const {
256 TElement&
at(std::size_t i) {
281 TElement* buffer =
nullptr;
292 TElement* buffer =
nullptr;
299 const std::size_t n =
_getLength(first, second);
301 TElement* buffer =
nullptr;
326 *
this = std::move(other);
327 other = std::move(temp);
337 template <
class InputIt>
340 throw std::runtime_error(
"Only inserting to end is supported");
353 throw std::runtime_error(
"Only inserting to end is supported");
367 return std::all_of(other.
begin(), other.
end(), [
this](
const TElement& element) {
368 return find(element) != end();
374 void _append(
const TElement* other, std::size_t n) {
375 if (!other || n == 0)
378 for (std::size_t i = 0; i < n; ++i)
379 operator[](
length_ + i) = other[i];
383 if (other ==
nullptr) {
387 for (std::size_t i = 0; i < len; ++i)
388 buffer[i] = other[pos + i];
465 TElement* buffer =
data_;
469 for (std::size_t i = 0; i <
length_; ++i)
470 operator[](i) = buffer[i];
497 void _alloc_buffer(TElement*& buffer,
const std::size_t n,
const TElement& element)
const {
499 std::size_t
begin = 0;
501 buffer[
begin++] = element;
510 for (std::size_t i = 0; i < n; ++i)
511 buffer[i] = *
begin++;
513 void _clear_str(
const std::size_t pos,
bool destruct =
true) {
514 std::size_t
begin = pos;
515 TElement* begin_data =
data_ + pos;
517 auto _temp = begin_data++;
532 return memory::safe_malloc_container_element<TElement>(count);
540 memory::safe_delete_container_element<TElement>(
data);
552template <
class TElement,
553 element_malloc_fun_t<TElement> _malloc = memory::safe_malloc_container_element<TElement>,
554 element_delete_fun_t<TElement> _delete = memory::safe_delete_container_element<TElement>>
557template <
class TElement,
Definition: ne_stl_iterator.h:22
nstd::iterator_type< TElement > & current()
Definition: ne_stl_iterator.h:32
Definition: ne_stl_iterator.h:159
Definition: ne_stl_continuous_container.h:15
void _append(const TElement other)
Definition: ne_stl_continuous_container.h:373
_continuous_container & append(const _continuous_container &other, std::size_t subpos, std::size_t sublen=container_npos::value)
Definition: ne_stl_continuous_container.h:279
void set_element_delete_function(element_delete_fun_t< TElement > function)
Definition: ne_stl_continuous_container.h:409
nstd::const_iterator< TElement > cend() const
Definition: ne_stl_continuous_container.h:129
nstd::reverse_iterator< TElement > rend()
Definition: ne_stl_continuous_container.h:133
std::size_t cap_length_
Definition: ne_stl_continuous_container.h:549
_continuous_container(const _continuous_container &other)
Definition: ne_stl_continuous_container.h:33
std::string to_string() const
Definition: ne_stl_continuous_container.h:217
nstd::iterator_type< TElement > _rbegin() const
Definition: ne_stl_continuous_container.h:144
void _alloc_buffer(TElement *&buffer, const std::size_t n, const nstd::const_iterator< TElement > i1, const nstd::const_iterator< TElement > i2) const
Definition: ne_stl_continuous_container.h:504
void _decrease_capacity(const std::size_t cap)
Definition: ne_stl_continuous_container.h:483
const TElement & at(std::size_t i) const
Definition: ne_stl_continuous_container.h:251
TElement & operator[](std::size_t i)
Definition: ne_stl_continuous_container.h:250
const TElement * data() const
Definition: ne_stl_continuous_container.h:405
void swap(_continuous_container &other)
Definition: ne_stl_continuous_container.h:324
_continuous_container(std::size_t n, const TElement &s)
Definition: ne_stl_continuous_container.h:77
TElement * data_
Definition: ne_stl_continuous_container.h:545
~_continuous_container()
Definition: ne_stl_continuous_container.h:241
nstd::const_reverse_iterator< TElement > rend() const
Definition: ne_stl_continuous_container.h:134
const TElement & operator[](std::size_t i) const
Definition: ne_stl_continuous_container.h:249
_continuous_container(std::initializer_list< TElement > init)
Definition: ne_stl_continuous_container.h:111
bool element_equal(const _continuous_container &other) const
Definition: ne_stl_continuous_container.h:229
_continuous_container()
Definition: ne_stl_continuous_container.h:22
nstd::iterator< TElement > begin()
Definition: ne_stl_continuous_container.h:124
bool contains(const _continuous_container &other) const
Definition: ne_stl_continuous_container.h:363
std::size_t size() const
Definition: ne_stl_continuous_container.h:410
TElement * pointer
Definition: ne_stl_continuous_container.h:19
void shrink_to_fit()
Definition: ne_stl_continuous_container.h:449
std::size_t _getLength(const _continuous_container &str, std::size_t pos, std::size_t len=container_npos::value) const
Definition: ne_stl_continuous_container.h:396
nstd::const_reverse_iterator< TElement > rbegin() const
Definition: ne_stl_continuous_container.h:132
std::size_t capacity() const
Definition: ne_stl_continuous_container.h:432
void _erase(std::size_t pos, std::size_t size)
Definition: ne_stl_continuous_container.h:390
const TElement & back() const
Definition: ne_stl_continuous_container.h:263
void resize(std::size_t n, TElement c)
Definition: ne_stl_continuous_container.h:421
void _set_length(const std::size_t len)
Definition: ne_stl_continuous_container.h:452
void _append(const TElement *other, std::size_t n)
Definition: ne_stl_continuous_container.h:374
element_malloc_fun_t< TElement > malloc_fun_
Definition: ne_stl_continuous_container.h:546
nstd::iterator< TElement > erase(nstd::const_iterator< TElement > p)
Definition: ne_stl_continuous_container.h:316
void _clear_str(const std::size_t pos, bool destruct=true)
Definition: ne_stl_continuous_container.h:513
nstd::const_iterator< TElement > end() const
Definition: ne_stl_continuous_container.h:127
_continuous_container & operator=(const std::vector< T > &other)
Definition: ne_stl_continuous_container.h:178
_continuous_container & erase(std::size_t pos=0, std::size_t len=container_npos::value)
Definition: ne_stl_continuous_container.h:312
_continuous_container & append(const nstd::const_iterator< TElement > first, const nstd::const_iterator< TElement > second)
Definition: ne_stl_continuous_container.h:298
bool empty() const
Definition: ne_stl_continuous_container.h:448
bool operator==(const _continuous_container &other) const
Definition: ne_stl_continuous_container.h:358
void insert(iterator pos, InputIt first, InputIt last)
The function type imitates the STL std::vector: https://en.cppreference.com/w/cpp/container/vector/in...
Definition: ne_stl_continuous_container.h:338
void _alloc_buffer(TElement *&buffer, const std::size_t n, const TElement &element) const
Definition: ne_stl_continuous_container.h:497
nstd::const_iterator< TElement > cbegin() const
Definition: ne_stl_continuous_container.h:128
void insert(const_iterator pos, const TElement &value)
The function type differs the STL std::vector in the return type: https://en.cppreference....
Definition: ne_stl_continuous_container.h:351
_continuous_container(const std::vector< TElement > &other)
Definition: ne_stl_continuous_container.h:100
_continuous_container & operator+=(const _continuous_container &other)
Definition: ne_stl_continuous_container.h:267
void _increase_capacity(const std::size_t cap)
Definition: ne_stl_continuous_container.h:474
nstd::iterator_type< TElement > _ibegin() const
Definition: ne_stl_continuous_container.h:143
_continuous_container(_continuous_container &&other)
Definition: ne_stl_continuous_container.h:43
nstd::iterator< TElement > find(const TElement &element)
Definition: ne_stl_continuous_container.h:361
_continuous_container(const _continuous_container &other, std::size_t pos, std::size_t len=container_npos::value)
Definition: ne_stl_continuous_container.h:57
_continuous_container(const nstd::const_iterator< TElement > first, const nstd::const_iterator< TElement > second)
Definition: ne_stl_continuous_container.h:78
_continuous_container & append(std::size_t n, TElement element)
Definition: ne_stl_continuous_container.h:291
nstd::const_reverse_iterator< TElement > crbegin() const
Definition: ne_stl_continuous_container.h:135
void _alloc_buffer(TElement *&buffer, const std::size_t n) const
Definition: ne_stl_continuous_container.h:490
nstd::const_reverse_iterator< TElement > crend() const
Definition: ne_stl_continuous_container.h:136
TElement & front()
Definition: ne_stl_continuous_container.h:262
const TElement & front() const
Definition: ne_stl_continuous_container.h:261
void _set_capacity(const std::size_t cap)
Definition: ne_stl_continuous_container.h:459
_continuous_container & push_back(TElement element)
Definition: ne_stl_continuous_container.h:308
_continuous_container & operator+=(TElement element)
Definition: ne_stl_continuous_container.h:271
_continuous_container & append(const _continuous_container &other)
Definition: ne_stl_continuous_container.h:275
_continuous_container & append(const TElement elements)
Definition: ne_stl_continuous_container.h:287
void _substr(TElement *&buffer, const TElement *other, std::size_t pos=0, std::size_t len=container_npos::value) const
Definition: ne_stl_continuous_container.h:382
std::size_t increase_step_length_
Definition: ne_stl_continuous_container.h:550
std::size_t max_size() const
Definition: ne_stl_continuous_container.h:411
nstd::const_iterator< TElement > find(const TElement &element) const
Definition: ne_stl_continuous_container.h:362
void set_element_malloc_function(element_malloc_fun_t< TElement > function)
Definition: ne_stl_continuous_container.h:408
nstd::iterator_type< TElement > _end() const
Definition: ne_stl_continuous_container.h:145
nstd::iterator< TElement > end()
Definition: ne_stl_continuous_container.h:126
TElement * _new_data(std::size_t count) const
Definition: ne_stl_continuous_container.h:526
nstd::reverse_iterator< TElement > rbegin()
Definition: ne_stl_continuous_container.h:131
nstd::const_iterator< TElement > begin() const
Definition: ne_stl_continuous_container.h:125
element_delete_fun_t< TElement > delete_fun_
Definition: ne_stl_continuous_container.h:547
std::size_t length_
Definition: ne_stl_continuous_container.h:548
_continuous_container(const std::vector< T > &other)
Definition: ne_stl_continuous_container.h:89
TElement & back()
Definition: ne_stl_continuous_container.h:264
bool operator!=(const _continuous_container &other) const
Definition: ne_stl_continuous_container.h:359
void _delete_data(TElement *&data)
Definition: ne_stl_continuous_container.h:534
void reserve(std::size_t n=0)
Definition: ne_stl_continuous_container.h:433
_continuous_container & operator=(_continuous_container &&other)
Definition: ne_stl_continuous_container.h:164
std::size_t _getLength(const nstd::const_iterator< TElement > first, const nstd::const_iterator< TElement > second)
Definition: ne_stl_continuous_container.h:146
TElement & at(std::size_t i)
Definition: ne_stl_continuous_container.h:256
_continuous_container(const TElement *s, std::size_t n)
Definition: ne_stl_continuous_container.h:67
TElement value_type
Definition: ne_stl_continuous_container.h:18
nstd::iterator< TElement > erase(nstd::const_iterator< TElement > first, nstd::const_iterator< TElement > last)
Definition: ne_stl_continuous_container.h:320
_continuous_container & operator=(const _continuous_container &other)
Definition: ne_stl_continuous_container.h:157
void clear()
Definition: ne_stl_continuous_container.h:444
std::size_t size_type
Definition: ne_stl_continuous_container.h:17
void resize(std::size_t n)
Definition: ne_stl_continuous_container.h:412
Definition: ne_stl_iterator.h:108
Definition: ne_stl_iterator.h:242
Definition: ne_stl_any.h:7
void(*)(TElement *&) element_delete_fun_t
Definition: ne_stl_memory.h:13
TElement *(*)(std::size_t) element_malloc_fun_t
Definition: ne_stl_memory.h:10
#define false
Definition: stdbool.h:33
Definition: ne_stl_value_def.h:12
static const T value
Definition: ne_stl_type_traits.h:10
Definition: ne_stl_iterator.h:9
Definition: ne_stl_bind.h:132