@@ -51,16 +51,15 @@ class FixedVector {
5151
5252public:
5353 _FORCE_INLINE_ constexpr FixedVector () = default;
54+
5455 constexpr FixedVector (std::initializer_list<T> p_init) {
5556 ERR_FAIL_COND (p_init.size () > CAPACITY);
5657 for (const T &element : p_init) {
5758 memnew_placement (ptr () + _size++, T (element));
5859 }
5960 }
6061
61- template <uint32_t p_capacity>
62- constexpr FixedVector (const FixedVector<T, p_capacity> &p_from) {
63- ERR_FAIL_COND (p_from.size () > CAPACITY);
62+ constexpr FixedVector (const FixedVector &p_from) {
6463 if constexpr (std::is_trivially_copyable_v<T>) {
6564 // Copy size and all provided elements at once.
6665 memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
@@ -71,15 +70,48 @@ class FixedVector {
7170 }
7271 }
7372
74- template <uint32_t p_capacity>
75- constexpr FixedVector (FixedVector<T, p_capacity> &&p_from) {
76- ERR_FAIL_COND (p_from.size () > CAPACITY);
73+ constexpr FixedVector (FixedVector &&p_from) {
7774 // Copy size and all provided elements at once.
7875 // Note: Assumes trivial relocatability.
7976 memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
8077 p_from._size = 0 ;
8178 }
8279
80+ constexpr FixedVector &operator =(const FixedVector &p_from) {
81+ if constexpr (std::is_trivially_copyable_v<T>) {
82+ // Copy size and all provided elements at once.
83+ memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
84+ } else {
85+ // Destruct extraneous elements.
86+ if constexpr (!std::is_trivially_destructible_v<T>) {
87+ for (uint32_t i = p_from.size (); i < _size; i++) {
88+ ptr ()[i].~T ();
89+ }
90+ }
91+
92+ _size = 0 ; // Loop-assign the rest.
93+ for (const T &element : p_from) {
94+ ptr ()[_size++] = element;
95+ }
96+ }
97+ return *this ;
98+ }
99+
100+ constexpr FixedVector &operator =(FixedVector &&p_from) {
101+ // Destruct extraneous elements.
102+ if constexpr (!std::is_trivially_destructible_v<T>) {
103+ for (uint32_t i = p_from.size (); i < _size; i++) {
104+ ptr ()[i].~T ();
105+ }
106+ }
107+
108+ // Relocate elements (and size) into our buffer.
109+ memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
110+ p_from._size = 0 ;
111+
112+ return *this ;
113+ }
114+
83115 ~FixedVector () {
84116 if constexpr (!std::is_trivially_destructible_v<T>) {
85117 for (uint32_t i = 0 ; i < _size; i++) {
@@ -136,6 +168,12 @@ class FixedVector {
136168 _size++;
137169 }
138170
171+ constexpr void push_back (T &&p_val) {
172+ ERR_FAIL_COND (_size >= CAPACITY);
173+ memnew_placement (ptr () + _size, T (std::move (p_val)));
174+ _size++;
175+ }
176+
139177 constexpr void pop_back () {
140178 ERR_FAIL_COND (_size == 0 );
141179 _size--;
0 commit comments