@@ -53,16 +53,15 @@ class FixedVector {
5353
5454public:
5555 _FORCE_INLINE_ constexpr FixedVector () = default;
56+
5657 constexpr FixedVector (std::initializer_list<T> p_init) {
5758 ERR_FAIL_COND (p_init.size () > CAPACITY);
5859 for (const T &element : p_init) {
5960 memnew_placement (ptr () + _size++, T (element));
6061 }
6162 }
6263
63- template <uint32_t p_capacity>
64- constexpr FixedVector (const FixedVector<T, p_capacity> &p_from) {
65- ERR_FAIL_COND (p_from.size () > CAPACITY);
64+ constexpr FixedVector (const FixedVector &p_from) {
6665 if constexpr (std::is_trivially_copyable_v<T>) {
6766 // Copy size and all provided elements at once.
6867 memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
@@ -73,15 +72,48 @@ class FixedVector {
7372 }
7473 }
7574
76- template <uint32_t p_capacity>
77- constexpr FixedVector (FixedVector<T, p_capacity> &&p_from) {
78- ERR_FAIL_COND (p_from.size () > CAPACITY);
75+ constexpr FixedVector (FixedVector &&p_from) {
7976 // Copy size and all provided elements at once.
8077 // Note: Assumes trivial relocatability.
8178 memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
8279 p_from._size = 0 ;
8380 }
8481
82+ constexpr FixedVector &operator =(const FixedVector &p_from) {
83+ if constexpr (std::is_trivially_copyable_v<T>) {
84+ // Copy size and all provided elements at once.
85+ memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
86+ } else {
87+ // Destruct extraneous elements.
88+ if constexpr (!std::is_trivially_destructible_v<T>) {
89+ for (uint32_t i = p_from.size (); i < _size; i++) {
90+ ptr ()[i].~T ();
91+ }
92+ }
93+
94+ _size = 0 ; // Loop-assign the rest.
95+ for (const T &element : p_from) {
96+ ptr ()[_size++] = element;
97+ }
98+ }
99+ return *this ;
100+ }
101+
102+ constexpr FixedVector &operator =(FixedVector &&p_from) {
103+ // Destruct extraneous elements.
104+ if constexpr (!std::is_trivially_destructible_v<T>) {
105+ for (uint32_t i = p_from.size (); i < _size; i++) {
106+ ptr ()[i].~T ();
107+ }
108+ }
109+
110+ // Relocate elements (and size) into our buffer.
111+ memcpy ((void *)&_size, (void *)&p_from._size , sizeof (_size) + DATA_PADDING + p_from.size () * sizeof (T));
112+ p_from._size = 0 ;
113+
114+ return *this ;
115+ }
116+
85117 ~FixedVector () {
86118 if constexpr (!std::is_trivially_destructible_v<T>) {
87119 for (uint32_t i = 0 ; i < _size; i++) {
@@ -138,6 +170,12 @@ class FixedVector {
138170 _size++;
139171 }
140172
173+ constexpr void push_back (T &&p_val) {
174+ ERR_FAIL_COND (_size >= CAPACITY);
175+ memnew_placement (ptr () + _size, T (std::move (p_val)));
176+ _size++;
177+ }
178+
141179 constexpr void pop_back () {
142180 ERR_FAIL_COND (_size == 0 );
143181 _size--;
0 commit comments