2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* vector.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef VECTOR_H
|
|
|
|
#define VECTOR_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Vector
|
2020-02-17 22:06:54 +01:00
|
|
|
* Vector container. Regular Vector Container. Use with care and for smaller arrays when possible. Use Vector for large arrays.
|
2021-10-28 15:43:36 +02:00
|
|
|
*/
|
2018-09-11 18:13:45 +02:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/error/error_macros.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/memory.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/templates/cowdata.h"
|
2021-09-19 20:13:09 +02:00
|
|
|
#include "core/templates/search_array.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/templates/sort_array.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-01-10 13:56:55 +01:00
|
|
|
#include <climits>
|
2021-07-15 18:28:05 +02:00
|
|
|
#include <initializer_list>
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
template <class T>
|
2018-07-25 03:11:03 +02:00
|
|
|
class VectorWriteProxy {
|
|
|
|
public:
|
2024-01-03 01:14:50 +01:00
|
|
|
_FORCE_INLINE_ T &operator[](typename CowData<T>::Size p_index) {
|
2018-12-14 21:03:02 +01:00
|
|
|
CRASH_BAD_INDEX(p_index, ((Vector<T> *)(this))->_cowdata.size());
|
2016-02-19 07:13:16 +01:00
|
|
|
|
2018-12-14 21:03:02 +01:00
|
|
|
return ((Vector<T> *)(this))->_cowdata.ptrw()[p_index];
|
2016-02-19 07:13:16 +01:00
|
|
|
}
|
2018-07-25 03:11:03 +02:00
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
template <class T>
|
|
|
|
class Vector {
|
|
|
|
friend class VectorWriteProxy<T>;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2018-07-25 03:11:03 +02:00
|
|
|
VectorWriteProxy<T> write;
|
2024-01-03 01:14:50 +01:00
|
|
|
typedef typename CowData<T>::Size Size;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-12-14 21:03:02 +01:00
|
|
|
private:
|
|
|
|
CowData<T> _cowdata;
|
|
|
|
|
|
|
|
public:
|
2019-12-26 17:38:08 +01:00
|
|
|
bool push_back(T p_elem);
|
2020-02-17 22:06:54 +01:00
|
|
|
_FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias
|
2021-02-25 15:10:39 +01:00
|
|
|
void fill(T p_elem);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
void remove_at(Size p_index) { _cowdata.remove_at(p_index); }
|
2023-04-10 18:45:53 +02:00
|
|
|
_FORCE_INLINE_ bool erase(const T &p_val) {
|
2024-01-03 01:14:50 +01:00
|
|
|
Size idx = find(p_val);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (idx >= 0) {
|
2021-07-04 00:17:03 +02:00
|
|
|
remove_at(idx);
|
2023-04-10 18:45:53 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2023-04-10 18:45:53 +02:00
|
|
|
return false;
|
2020-02-17 22:06:54 +01:00
|
|
|
}
|
2023-04-10 18:45:53 +02:00
|
|
|
|
2021-03-14 08:21:32 +01:00
|
|
|
void reverse();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-12-14 21:03:02 +01:00
|
|
|
_FORCE_INLINE_ T *ptrw() { return _cowdata.ptrw(); }
|
|
|
|
_FORCE_INLINE_ const T *ptr() const { return _cowdata.ptr(); }
|
2018-07-25 03:11:03 +02:00
|
|
|
_FORCE_INLINE_ void clear() { resize(0); }
|
2020-12-15 13:04:21 +01:00
|
|
|
_FORCE_INLINE_ bool is_empty() const { return _cowdata.is_empty(); }
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
_FORCE_INLINE_ T get(Size p_index) { return _cowdata.get(p_index); }
|
|
|
|
_FORCE_INLINE_ const T &get(Size p_index) const { return _cowdata.get(p_index); }
|
|
|
|
_FORCE_INLINE_ void set(Size p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); }
|
|
|
|
_FORCE_INLINE_ Size size() const { return _cowdata.size(); }
|
|
|
|
Error resize(Size p_size) { return _cowdata.resize(p_size); }
|
|
|
|
Error resize_zeroed(Size p_size) { return _cowdata.template resize<true>(p_size); }
|
|
|
|
_FORCE_INLINE_ const T &operator[](Size p_index) const { return _cowdata.get(p_index); }
|
|
|
|
Error insert(Size p_pos, T p_val) { return _cowdata.insert(p_pos, p_val); }
|
|
|
|
Size find(const T &p_val, Size p_from = 0) const { return _cowdata.find(p_val, p_from); }
|
|
|
|
Size rfind(const T &p_val, Size p_from = -1) const { return _cowdata.rfind(p_val, p_from); }
|
|
|
|
Size count(const T &p_val) const { return _cowdata.count(p_val); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2024-01-09 02:36:19 +01:00
|
|
|
void append_array(const Vector<T> &p_other);
|
2017-11-21 01:11:39 +01:00
|
|
|
|
2022-02-01 19:19:13 +01:00
|
|
|
_FORCE_INLINE_ bool has(const T &p_val) const { return find(p_val) != -1; }
|
2020-02-21 05:19:00 +01:00
|
|
|
|
2022-03-28 03:57:20 +02:00
|
|
|
void sort() {
|
|
|
|
sort_custom<_DefaultComparator<T>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Comparator, bool Validate = SORT_ARRAY_VALIDATE_ENABLED, class... Args>
|
|
|
|
void sort_custom(Args &&...args) {
|
2024-01-03 01:14:50 +01:00
|
|
|
Size len = _cowdata.size();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (len == 0) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 03:11:03 +02:00
|
|
|
|
|
|
|
T *data = ptrw();
|
2022-03-28 03:57:20 +02:00
|
|
|
SortArray<T, Comparator, Validate> sorter{ args... };
|
2014-02-10 02:10:30 +01:00
|
|
|
sorter.sort(data, len);
|
|
|
|
}
|
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
Size bsearch(const T &p_value, bool p_before) {
|
2022-03-28 03:57:20 +02:00
|
|
|
return bsearch_custom<_DefaultComparator<T>>(p_value, p_before);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-03-28 03:57:20 +02:00
|
|
|
template <class Comparator, class Value, class... Args>
|
2024-01-03 01:14:50 +01:00
|
|
|
Size bsearch_custom(const Value &p_value, bool p_before, Args &&...args) {
|
2022-03-28 03:57:20 +02:00
|
|
|
SearchArray<T, Comparator> search{ args... };
|
2021-09-19 20:13:09 +02:00
|
|
|
return search.bisect(ptrw(), size(), p_value, p_before);
|
|
|
|
}
|
|
|
|
|
2020-12-17 21:26:05 +01:00
|
|
|
Vector<T> duplicate() {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-03-20 00:53:54 +01:00
|
|
|
void ordered_insert(const T &p_val) {
|
2024-01-03 01:14:50 +01:00
|
|
|
Size i;
|
2018-12-14 21:03:02 +01:00
|
|
|
for (i = 0; i < _cowdata.size(); i++) {
|
2015-03-20 00:53:54 +01:00
|
|
|
if (p_val < operator[](i)) {
|
|
|
|
break;
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-20 00:53:54 +01:00
|
|
|
insert(i, p_val);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-11-30 15:19:26 +01:00
|
|
|
inline void operator=(const Vector &p_from) {
|
2018-12-14 21:03:02 +01:00
|
|
|
_cowdata._ref(p_from._cowdata);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2018-07-29 16:57:05 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Vector<uint8_t> to_byte_array() const {
|
|
|
|
Vector<uint8_t> ret;
|
2022-06-28 04:02:42 +02:00
|
|
|
if (is_empty()) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-05-01 14:34:23 +02:00
|
|
|
ret.resize(size() * sizeof(T));
|
2021-04-27 16:19:21 +02:00
|
|
|
memcpy(ret.ptrw(), ptr(), sizeof(T) * size());
|
2020-05-01 14:34:23 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
Vector<T> slice(Size p_begin, Size p_end = CowData<T>::MAX_INT) const {
|
2021-11-27 02:18:26 +01:00
|
|
|
Vector<T> result;
|
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
const Size s = size();
|
2020-02-17 22:06:54 +01:00
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
Size begin = CLAMP(p_begin, -s, s);
|
2022-01-10 13:56:55 +01:00
|
|
|
if (begin < 0) {
|
|
|
|
begin += s;
|
|
|
|
}
|
2024-01-03 01:14:50 +01:00
|
|
|
Size end = CLAMP(p_end, -s, s);
|
2022-01-10 13:56:55 +01:00
|
|
|
if (end < 0) {
|
|
|
|
end += s;
|
|
|
|
}
|
2021-11-27 02:18:26 +01:00
|
|
|
|
2022-01-10 13:56:55 +01:00
|
|
|
ERR_FAIL_COND_V(begin > end, result);
|
2021-11-27 02:18:26 +01:00
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
Size result_size = end - begin;
|
2021-11-27 02:18:26 +01:00
|
|
|
result.resize(result_size);
|
2020-02-17 22:06:54 +01:00
|
|
|
|
2021-11-27 02:18:26 +01:00
|
|
|
const T *const r = ptr();
|
|
|
|
T *const w = result.ptrw();
|
2024-01-03 01:14:50 +01:00
|
|
|
for (Size i = 0; i < result_size; ++i) {
|
2022-01-10 13:56:55 +01:00
|
|
|
w[i] = r[begin + i];
|
2020-02-17 22:06:54 +01:00
|
|
|
}
|
|
|
|
|
2021-11-27 02:18:26 +01:00
|
|
|
return result;
|
2020-02-17 22:06:54 +01:00
|
|
|
}
|
|
|
|
|
2020-11-05 03:01:55 +01:00
|
|
|
bool operator==(const Vector<T> &p_arr) const {
|
2024-01-03 01:14:50 +01:00
|
|
|
Size s = size();
|
2020-11-05 03:01:55 +01:00
|
|
|
if (s != p_arr.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-01-03 01:14:50 +01:00
|
|
|
for (Size i = 0; i < s; i++) {
|
2020-11-05 03:01:55 +01:00
|
|
|
if (operator[](i) != p_arr[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Vector<T> &p_arr) const {
|
2024-01-03 01:14:50 +01:00
|
|
|
Size s = size();
|
2020-11-05 03:01:55 +01:00
|
|
|
if (s != p_arr.size()) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-01-03 01:14:50 +01:00
|
|
|
for (Size i = 0; i < s; i++) {
|
2020-11-05 03:01:55 +01:00
|
|
|
if (operator[](i) != p_arr[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Implement Range Iterators
This PR implements range iterators in the base containers (Vector, Map, List, Pair Set).
Given several of these data structures will be replaced by more efficient versions, having a common iterator API will make this simpler.
Iterating can be done as follows (examples):
```C++
//Vector<String>
for(const String& I: vector) {
}
//List<String>
for(const String& I: list) {
}
//Map<String,int>
for(const KeyValue<String,int>&I : map) {
print_line("key: "+I.key+" value: "+itos(I.value));
}
//if intending to write the elements, reference can be used
//Map<String,int>
for(KeyValue<String,int>& I: map) {
I.value = 25;
//this will fail because key is always const
//I.key = "hello"
}
```
The containers are (for now) not STL compatible, since this would mean changing how they work internally (STL uses a special head/tail allocation for end(), while Godot Map/Set/List do not).
The idea is to change the Godot versions to be more compatible with STL, but this will happen after conversion to new iterators have taken place.
2021-07-08 17:31:19 +02:00
|
|
|
struct Iterator {
|
|
|
|
_FORCE_INLINE_ T &operator*() const {
|
|
|
|
return *elem_ptr;
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ T *operator->() const { return elem_ptr; }
|
|
|
|
_FORCE_INLINE_ Iterator &operator++() {
|
|
|
|
elem_ptr++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ Iterator &operator--() {
|
|
|
|
elem_ptr--;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ bool operator==(const Iterator &b) const { return elem_ptr == b.elem_ptr; }
|
|
|
|
_FORCE_INLINE_ bool operator!=(const Iterator &b) const { return elem_ptr != b.elem_ptr; }
|
|
|
|
|
|
|
|
Iterator(T *p_ptr) { elem_ptr = p_ptr; }
|
|
|
|
Iterator() {}
|
|
|
|
Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
T *elem_ptr = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstIterator {
|
|
|
|
_FORCE_INLINE_ const T &operator*() const {
|
|
|
|
return *elem_ptr;
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ const T *operator->() const { return elem_ptr; }
|
|
|
|
_FORCE_INLINE_ ConstIterator &operator++() {
|
|
|
|
elem_ptr++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ ConstIterator &operator--() {
|
|
|
|
elem_ptr--;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return elem_ptr == b.elem_ptr; }
|
|
|
|
_FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return elem_ptr != b.elem_ptr; }
|
|
|
|
|
2021-08-23 19:00:33 +02:00
|
|
|
ConstIterator(const T *p_ptr) { elem_ptr = p_ptr; }
|
Implement Range Iterators
This PR implements range iterators in the base containers (Vector, Map, List, Pair Set).
Given several of these data structures will be replaced by more efficient versions, having a common iterator API will make this simpler.
Iterating can be done as follows (examples):
```C++
//Vector<String>
for(const String& I: vector) {
}
//List<String>
for(const String& I: list) {
}
//Map<String,int>
for(const KeyValue<String,int>&I : map) {
print_line("key: "+I.key+" value: "+itos(I.value));
}
//if intending to write the elements, reference can be used
//Map<String,int>
for(KeyValue<String,int>& I: map) {
I.value = 25;
//this will fail because key is always const
//I.key = "hello"
}
```
The containers are (for now) not STL compatible, since this would mean changing how they work internally (STL uses a special head/tail allocation for end(), while Godot Map/Set/List do not).
The idea is to change the Godot versions to be more compatible with STL, but this will happen after conversion to new iterators have taken place.
2021-07-08 17:31:19 +02:00
|
|
|
ConstIterator() {}
|
|
|
|
ConstIterator(const ConstIterator &p_it) { elem_ptr = p_it.elem_ptr; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const T *elem_ptr = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Iterator begin() {
|
|
|
|
return Iterator(ptrw());
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ Iterator end() {
|
|
|
|
return Iterator(ptrw() + size());
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ ConstIterator begin() const {
|
|
|
|
return ConstIterator(ptr());
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ ConstIterator end() const {
|
|
|
|
return ConstIterator(ptr() + size());
|
|
|
|
}
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
_FORCE_INLINE_ Vector() {}
|
2021-07-15 18:28:05 +02:00
|
|
|
_FORCE_INLINE_ Vector(std::initializer_list<T> p_init) {
|
|
|
|
Error err = _cowdata.resize(p_init.size());
|
|
|
|
ERR_FAIL_COND(err);
|
|
|
|
|
2024-01-03 01:14:50 +01:00
|
|
|
Size i = 0;
|
2021-07-15 18:28:05 +02:00
|
|
|
for (const T &element : p_init) {
|
|
|
|
_cowdata.set(i++, element);
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 17:01:17 +02:00
|
|
|
_FORCE_INLINE_ Vector(const Vector &p_from) { _cowdata._ref(p_from._cowdata); }
|
|
|
|
|
2018-12-14 21:03:02 +01:00
|
|
|
_FORCE_INLINE_ ~Vector() {}
|
2018-07-25 03:11:03 +02:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
template <class T>
|
2021-03-14 08:21:32 +01:00
|
|
|
void Vector<T>::reverse() {
|
2024-01-03 01:14:50 +01:00
|
|
|
for (Size i = 0; i < size() / 2; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
T *p = ptrw();
|
|
|
|
SWAP(p[i], p[size() - i - 1]);
|
2017-01-06 14:15:44 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-11-21 01:11:39 +01:00
|
|
|
template <class T>
|
2024-01-09 02:36:19 +01:00
|
|
|
void Vector<T>::append_array(const Vector<T> &p_other) {
|
2024-01-03 01:14:50 +01:00
|
|
|
const Size ds = p_other.size();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (ds == 0) {
|
2017-11-21 01:11:39 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2024-01-03 01:14:50 +01:00
|
|
|
const Size bs = size();
|
2017-11-21 01:11:39 +01:00
|
|
|
resize(bs + ds);
|
2024-01-03 01:14:50 +01:00
|
|
|
for (Size i = 0; i < ds; ++i) {
|
2018-07-25 03:11:03 +02:00
|
|
|
ptrw()[bs + i] = p_other[i];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2019-12-26 17:38:08 +01:00
|
|
|
bool Vector<T>::push_back(T p_elem) {
|
2018-07-25 03:11:03 +02:00
|
|
|
Error err = resize(size() + 1);
|
2019-06-11 14:49:34 +02:00
|
|
|
ERR_FAIL_COND_V(err, true);
|
2018-07-25 03:11:03 +02:00
|
|
|
set(size() - 1, p_elem);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2021-02-25 15:10:39 +01:00
|
|
|
template <class T>
|
|
|
|
void Vector<T>::fill(T p_elem) {
|
|
|
|
T *p = ptrw();
|
2024-01-03 01:14:50 +01:00
|
|
|
for (Size i = 0; i < size(); i++) {
|
2021-02-25 15:10:39 +01:00
|
|
|
p[i] = p_elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-25 11:10:34 +01:00
|
|
|
#endif // VECTOR_H
|