Enable assert always in Dali::Vector
[platform/core/uifw/dali-core.git] / dali / public-api / common / dali-vector.h
1 #ifndef DALI_VECTOR_H
2 #define DALI_VECTOR_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23 #include <cstddef>
24 #include <cstdint> // uint32_t
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/common/type-traits.h>
29 #include <dali/public-api/math/math-utils.h>
30
31 #define DALI_ASSERT_VECTOR(cond) DALI_ASSERT_ALWAYS(cond)
32
33 namespace Dali
34 {
35 /**
36  * @addtogroup dali_core_common
37  * @{
38  */
39
40 /**
41  * @brief Base class to handle the memory of simple vector.
42  *
43  * Memory layout is such that it has two std::size_t to hold the count
44  * and capacity of the vector. VectorBase::mData is adjusted so that it points to the
45  * beginning of the first real item so that iterating the items is quick.
46  * @SINCE_1_0.0
47  */
48 class DALI_CORE_API VectorBase
49 {
50 public: // Typedefs
51   using SizeType = std::size_t;
52
53 protected: // Construction
54   /**
55    * @brief Default constructor. Does not allocate space.
56    * @SINCE_1_0.0
57    */
58   VectorBase();
59
60   /**
61    * @brief Destructor.
62    *
63    * Does not release the space. Derived class needs to call Release.
64    * Not virtual as this should not be called directly and we do not want
65    * a vtable for this class as it would unnecessarily increase size.
66    * @SINCE_1_0.0
67    */
68   ~VectorBase();
69
70 public: // API
71   /**
72    * @brief This method is inlined as it's needed frequently for Vector::End() iterator.
73    *
74    * @SINCE_1_0.0
75    * @return The count of elements in this vector
76    */
77   SizeType Count() const
78   {
79     SizeType items = 0u;
80     if(mData)
81     {
82       SizeType* metadata = reinterpret_cast<SizeType*>(mData);
83       items              = *(metadata - 1u);
84     }
85     return items;
86   }
87
88   /**
89    * @brief Gets the count of elements in this vector.
90    * @SINCE_1_0.0
91    * @return The count of elements in this vector
92    */
93   SizeType Size() const
94   {
95     return Count();
96   }
97
98   /**
99    * @brief @ return if the vector is empty.
100    * @SINCE_1_0.0
101    * @return True if the count of elements is empty
102    */
103   bool Empty() const
104   {
105     return Count() == 0u;
106   }
107
108   /**
109    * @brief Gets the capacity of this vector.
110    * @SINCE_1_0.0
111    * @return The capacity of this vector
112    */
113   SizeType Capacity() const;
114
115   /**
116    * @brief Releases the data.
117    *
118    * Does not call destructors on objects held.
119    * @SINCE_1_0.0
120    */
121   void Release();
122
123 protected: // for Derived classes
124   /**
125    * @brief Helper to set the count.
126    *
127    * @SINCE_1_0.0
128    * @param[in] count Number of elements in the vector
129    */
130   void SetCount(SizeType count);
131
132   /**
133    * @brief Reserves space in the vector.
134    *
135    * @SINCE_1_0.0
136    * @param[in] count Count of elements to reserve
137    * @param[in] elementSize Size of a single element
138    */
139   void Reserve(SizeType count, SizeType elementSize);
140
141   /**
142    * @brief Copy a vector.
143    *
144    * @SINCE_1_0.0
145    * @param[in] vector Vector to copy from
146    * @param[in] elementSize Size of a single element
147    */
148   void Copy(const VectorBase& vector, SizeType elementSize);
149
150   /**
151    * @brief Swaps the contents of two vectors.
152    *
153    * @SINCE_1_0.0
154    * @param[in] vector Vector to swap with
155    */
156   void Swap(VectorBase& vector);
157
158   /**
159    * @brief Erases an element.
160    *
161    * Does not change capacity.
162    * @SINCE_1_0.0
163    * @param[in] address Address to erase from
164    * @param[in] elementSize Size to erase
165    * @pre Last element cannot be erased as there is nothing to move.
166    */
167   void Erase(char* address, SizeType elementSize);
168
169   /**
170    * @brief Erases a range of elements.
171    *
172    * Does not change capacity.
173    * @SINCE_1_0.0
174    * @param[in] first Address to the first element to be erased
175    * @param[in] last Address to the last element to be erased
176    * @param[in] elementSize Size of one of the elements to be erased
177    * @return Address pointing to the next element of the last one
178    */
179   char* Erase(char* first, char* last, SizeType elementSize);
180
181   /**
182    * @brief Copies a number of bytes from \e source to \e destination.
183    *
184    * \e source and \e destination must not overlap.
185    *
186    * @SINCE_1_0.0
187    * @param[in] destination Pointer to the destination address
188    * @param[in] source Pointer to the source address
189    * @param[in] numberOfBytes The number of bytes to be copied
190    */
191   void CopyMemory(char* destination, const char* source, size_t numberOfBytes);
192
193 private:
194   // not copyable as it does not know the size of elements
195   VectorBase(const VectorBase&) = delete;            ///< Deleted copy constructor. @SINCE_1_0.0
196   VectorBase& operator=(const VectorBase&) = delete; ///< Deleted copy assignment operator. @SINCE_1_0.0
197
198   // not movable as this is handled by deriving classes
199   VectorBase(VectorBase&&) = delete;            ///< Deleted move constructor. @SINCE_1_9.25
200   VectorBase& operator=(VectorBase&&) = delete; ///< Deleted copy assignment operator. @SINCE_1_9.25
201
202 protected:     // Data
203   void* mData; ///< Pointer to the data.
204 };
205
206 /// @cond internal
207 /**
208  * @brief Vector algorithm variant for trivial types.
209  *
210  * Trivial types do not need destructor or copy constructor called.
211  * @SINCE_1_0.0
212  */
213 template<bool IsTrivial>
214 class VectorAlgorithms : public VectorBase
215 {
216 protected: // API for deriving classes
217   using SizeType = VectorBase::SizeType;
218
219   /**
220    * @brief Empty constructor.
221    * @SINCE_1_0.0
222    */
223   VectorAlgorithms() = default;
224
225   /**
226    * @brief Empty destructor.
227    * @SINCE_1_0.0
228    */
229   ~VectorAlgorithms() = default;
230
231   /**
232    * @brief Copy vector contents.
233    *
234    * @SINCE_1_0.0
235    * @param[in] rhs VectorBase object to copy from
236    * @param[in] elementSize Size of the content
237    */
238   void Copy(const VectorBase& rhs, SizeType elementSize)
239   {
240     if(rhs.Capacity() > 0u)
241     {
242       VectorBase::Copy(rhs, elementSize);
243     }
244     else
245     {
246       VectorBase::Release();
247     }
248   }
249
250   /**
251    * @brief Reserves space in the vector.
252    *
253    * @SINCE_1_0.0
254    * @param[in] count Count of elements to reserve
255    * @param[in] elementSize Size of a single element
256    */
257   void Reserve(SizeType count, SizeType elementSize)
258   {
259     VectorBase::Reserve(count, elementSize);
260   }
261
262   /**
263    * @brief Resizes the vector. Does not change capacity.
264    *
265    * @SINCE_1_0.0
266    * @param[in] count Count to resize to
267    * @param[in] elementSize Size of a single element
268    */
269   void Resize(SizeType count, SizeType elementSize)
270   {
271     // reserve will copy old elements as well
272     Reserve(count, elementSize);
273   }
274
275   /**
276    * @brief Clears the contents.
277    *
278    * For simple types, nothing to do.
279    * @SINCE_1_0.0
280    */
281   void Clear()
282   {
283     if(mData)
284     {
285       VectorBase::SetCount(0u);
286     }
287   }
288
289   /**
290    * @brief Releases the vector.
291    * @SINCE_1_0.0
292    */
293   void Release()
294   {
295     VectorBase::Release();
296   }
297
298   /**
299    * @brief Erases an element. Does not change capacity.
300    *
301    * @SINCE_1_0.0
302    * @param[in] address Address to erase from
303    * @param[in] elementSize Size to erase
304    */
305   void Erase(uint8_t* address, SizeType elementSize)
306   {
307     VectorBase::Erase(reinterpret_cast<char*>(address), elementSize);
308   }
309
310   /**
311    * @brief Erases a range of elements. Does not change capacity.
312    *
313    * @SINCE_1_0.0
314    * @param[in] first Address to the first element to be erased
315    * @param[in] last Address to the last element to be erased
316    * @param[in] elementSize Size of one of the elements to be erased
317    * @return Address pointing to the next element of the last one
318    */
319   uint8_t* Erase(uint8_t* first, uint8_t* last, SizeType elementSize)
320   {
321     return reinterpret_cast<uint8_t*>(VectorBase::Erase(reinterpret_cast<char*>(first), reinterpret_cast<char*>(last), elementSize));
322   }
323
324   /**
325    * @brief Inserts the given elements into the vector.
326    *
327    * @SINCE_1_0.0
328    * @param[in] at Address where to insert the elements into the vector
329    * @param[in] from Address to the first element to be inserted
330    * @param[in] to Address to the last element to be inserted
331    * @param[in] elementSize Size of one of the elements to be inserted
332    */
333   void Insert(uint8_t* at, uint8_t* from, uint8_t* to, SizeType elementSize)
334   {
335     const SizeType size     = to - from;
336     const SizeType count    = Count();
337     const SizeType newCount = count + size / elementSize;
338
339     if(newCount > Capacity())
340     {
341       // Calculate the at offset as the pointer is invalid after the Reserve() call.
342       std::size_t offset = at - reinterpret_cast<uint8_t*>(mData);
343
344       // need more space
345       Reserve(NextPowerOfTwo(static_cast<uint32_t>(newCount)), elementSize); // reserve enough space to store at least the next power of two elements of the new required size.
346
347       // Set the new at pointer.
348       at = reinterpret_cast<uint8_t*>(mData) + offset;
349     }
350     // set new count first as otherwise the debug assert will hit us
351     SetCount(newCount);
352
353     // Move current items to a new position inside the vector.
354     CopyMemory(reinterpret_cast<char*>(at + size),
355                reinterpret_cast<const char*>(at),
356                (reinterpret_cast<uint8_t*>(mData) + count * elementSize) - at);
357
358     // Copy the given items.
359     CopyMemory(reinterpret_cast<char*>(at), reinterpret_cast<const char*>(from), size);
360   }
361 };
362 /// @endcond
363
364 /// @cond internal
365 /**
366  * @brief Vector algorithm variant for complex types.
367  *
368  * Not yet supported so will lead to compile error
369  * as constructor and destructor are private.
370  * TODO add support for this variant.
371  * @SINCE_1_0.0
372  */
373 template<>
374 class VectorAlgorithms<false> : public VectorBase
375 {
376 private:
377   VectorAlgorithms()  = default;
378   ~VectorAlgorithms() = default;
379 };
380 /// @endcond
381
382 /**
383  * @brief Vector class with minimum space allocation when it's empty.
384  *
385  * @SINCE_1_0.0
386  * @param type The type of the data that the vector holds
387  */
388 template<class T, bool IsTrivialType = TypeTraits<T>::IS_TRIVIAL_TYPE == true>
389 class Vector : public VectorAlgorithms<IsTrivialType>
390 {
391 public: // API
392   /**
393    * @brief Type definitions.
394    * @SINCE_1_0.0
395    */
396   using SizeType      = VectorBase::SizeType; ///< Size type @SINCE_1_0.0
397   using Iterator      = T*;                   ///< Most simple Iterator is a pointer @SINCE_1_0.0
398   using ConstIterator = const T*;             ///< Const iterator @SINCE_1_0.0
399   using ItemType      = T;                    ///< Item type @SINCE_1_0.0
400
401   /**
402    * @brief Enumeration for BaseType.
403    * @SINCE_1_0.0
404    */
405   enum
406   {
407     BaseType = IsTrivialType ///< @SINCE_1_0.0
408   };
409
410   /**
411    * @brief Default constructor. Does not allocate any space.
412    * @SINCE_1_0.0
413    */
414   Vector() = default;
415
416   /**
417    * @brief Destructor. Releases the allocated space.
418    * @SINCE_1_0.0
419    */
420   ~Vector()
421   {
422     Release();
423   }
424
425   /**
426    * @brief Copy constructor.
427    *
428    * @SINCE_1_0.0
429    * @param[in] vector Vector to copy from
430    */
431   Vector(const Vector& vector)
432   {
433     // reuse copy assignment
434     operator=(vector);
435   }
436
437   /**
438    * @brief Default move constructor.
439    *
440    * @SINCE_1_9.25
441    * @param[in] vector Vector to move
442    */
443   Vector(Vector&& vector)
444   {
445     // reuse move assignment
446     operator=(std::move(vector));
447   }
448
449   /**
450    * @brief Assignment operator.
451    *
452    * @SINCE_1_0.0
453    * @param[in] vector Vector to assign from
454    * @return Reference to self for chaining
455    */
456   Vector& operator=(const Vector& vector)
457   {
458     if(this != &vector)
459     {
460       VectorAlgorithms<BaseType>::Copy(vector, sizeof(ItemType));
461     }
462     return *this;
463   }
464
465   /**
466    * @brief Default move assignment operator.
467    *
468    * @SINCE_1_9.25
469    * @param[in] vector Vector to move
470    */
471   Vector& operator=(Vector&& vector)
472   {
473     if(this != &vector)
474     {
475       if(VectorBase::mData)
476       {
477         Release();
478       }
479       VectorBase::mData = vector.mData;
480       vector.mData      = nullptr;
481     }
482     return *this;
483   }
484
485   /**
486    * @brief Iterator to the beginning of the data.
487    * @SINCE_1_0.0
488    * @return Iterator to the beginning of the data
489    */
490   Iterator Begin() const
491   {
492     ItemType* address = reinterpret_cast<ItemType*>(VectorBase::mData);
493     return address;
494   }
495
496   /**
497    * @brief Iterator to the end of the data (one past last element).
498    * @SINCE_1_0.0
499    * @return Iterator to the end of the data (one past last element)
500    */
501   Iterator End() const
502   {
503     ItemType* address = reinterpret_cast<ItemType*>(VectorBase::mData);
504     address += VectorBase::Count();
505     return address;
506   }
507
508   /**
509    * Support for C++11 Range-based for loop: for( item : container ).
510    * @SINCE_1_2.60
511    * @return The start iterator
512    */
513   Iterator begin() const
514   {
515     return Begin();
516   }
517
518   /**
519    * Support for C++11 Range-based for loop: for( item : container ).
520    * @SINCE_1_2.60
521    * @return The end iterator
522    */
523   Iterator end() const
524   {
525     return End();
526   }
527
528   /**
529    * @brief Subscript operator.
530    * @SINCE_1_0.0
531    * @param[in] index Index of the element
532    * @return Reference to the element for given index
533    * @pre Index must be in the vector's range.
534    */
535   ItemType& operator[](SizeType index)
536   {
537     // reuse the const version
538     return const_cast<ItemType&>(const_cast<const Vector<ItemType>&>(*this)[index]);
539   }
540
541   /**
542    * @brief Subscript operator.
543    * @SINCE_1_0.0
544    * @param[in] index Index of the element
545    * @return Reference to the element for given index
546    * @pre Index must be in the vector's range.
547    */
548   const ItemType& operator[](SizeType index) const
549   {
550     DALI_ASSERT_VECTOR(VectorBase::mData && "Vector is empty");
551     DALI_ASSERT_VECTOR(index < VectorBase::Count() && "Index out of bounds");
552     ItemType* address = reinterpret_cast<ItemType*>(VectorBase::mData);
553     address += index;
554     return *address;
555   }
556
557   /**
558    * @brief Pushes back an element to the vector.
559    *
560    * The underlying storage may be reallocated to provide space.
561    * If this occurs, all pre-existing pointers into the vector will
562    * become invalid.
563    *
564    * @SINCE_1_0.0
565    * @param[in] element Element to be added
566    */
567   void PushBack(const ItemType& element)
568   {
569     const SizeType count    = VectorBase::Count();
570     const SizeType newCount = count + 1u;
571     const SizeType capacity = VectorBase::Capacity();
572     if(newCount > capacity)
573     {
574       // need more space
575       Reserve(newCount << 1u); // reserve double the current count
576     }
577     // set new count first as otherwise the debug assert will hit us
578     VectorBase::SetCount(newCount);
579     operator[](count) = element;
580   }
581
582   /**
583    * @brief Inserts an element to the vector.
584    *
585    * Elements after \e at are moved one position to the right.
586    *
587    * The underlying storage may be reallocated to provide space.
588    * If this occurs, all pre-existing pointers into the vector will
589    * become invalid.
590    *
591    * @SINCE_1_0.0
592    * @param[in] at Iterator where to insert the elements into the vector
593    * @param[in] element An element to be added
594    * @pre Iterator at must be in the vector's range ( Vector::Begin(), Vector::End() ).
595    */
596   void Insert(Iterator at, const ItemType& element)
597   {
598     DALI_ASSERT_VECTOR((at <= End()) && (at >= Begin()) && "Iterator not inside vector");
599     const SizeType size    = sizeof(ItemType);
600     uint8_t*       address = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&element));
601     VectorAlgorithms<BaseType>::Insert(reinterpret_cast<uint8_t*>(at),
602                                        address,
603                                        address + size,
604                                        size);
605   }
606
607   /**
608    * @brief Inserts the given elements into the vector.
609    *
610    * Elements after \e at are moved the number of given elements positions to the right.
611    *
612    * The underlying storage may be reallocated to provide space.
613    * If this occurs, all pre-existing pointers into the vector will
614    * become invalid.
615    *
616    * @SINCE_1_0.0
617    * @param[in] at Iterator where to insert the elements into the vector
618    * @param[in] from Iterator to the first element to be inserted
619    * @param[in] to Iterator to the last element to be inserted
620    * @pre Iterator \e at must be in the vector's range ( Vector::Begin(), Vector::End() ).
621    * @pre Iterators \e from and \e to must be valid iterators.
622    * @pre Iterator \e from must not be grater than Iterator \e to.
623    *
624    */
625   void Insert(Iterator at, Iterator from, Iterator to)
626   {
627     DALI_ASSERT_VECTOR((at <= End()) && (at >= Begin()) && "Iterator not inside vector");
628     DALI_ASSERT_VECTOR((from <= to) && "from address can't be greater than to");
629
630     if(from == to)
631     {
632       // nothing to copy.
633       return;
634     }
635
636     VectorAlgorithms<BaseType>::Insert(reinterpret_cast<uint8_t*>(at),
637                                        reinterpret_cast<uint8_t*>(from),
638                                        reinterpret_cast<uint8_t*>(to),
639                                        sizeof(ItemType));
640   }
641
642   /**
643    * @brief Reserves space in the vector.
644    *
645    * Reserving less than current Capacity is a no-op.
646    * @SINCE_1_0.0
647    * @param[in] count Count of elements to reserve
648    */
649   void Reserve(SizeType count)
650   {
651     VectorAlgorithms<BaseType>::Reserve(count, sizeof(ItemType));
652   }
653
654   /**
655    * @brief Resizes the vector. Does not change capacity.
656    *
657    * @SINCE_1_0.0
658    * @param[in] count Count to resize to
659    */
660   void Resize(SizeType count)
661   {
662     ItemType item = ItemType();
663     Resize(count, item);
664   }
665
666   /**
667    * @brief Resizes the vector without initializing the data.
668    *
669    * Can be used as a data container for reading whole file content.
670    * @SINCE_1_9.27
671    * @param[in] count Count to resize to
672    */
673   void ResizeUninitialized(SizeType count)
674   {
675     Reserve(count);
676     VectorBase::SetCount(count);
677   }
678
679   /**
680    * @brief Resizes the vector. Does not change capacity.
681    *
682    * @SINCE_1_0.0
683    * @param[in] count Count to resize to
684    * @param[in] item An item to insert to the new indices
685    */
686   void Resize(SizeType count, const ItemType& item)
687   {
688     const SizeType oldCount = VectorBase::Count();
689     if(count <= oldCount)
690     {
691       // getting smaller so just set count
692       VectorBase::SetCount(count);
693     }
694     else
695     {
696       // remember how many new items get added
697       SizeType newItems = count - oldCount;
698       Reserve(count);
699       for(; newItems > 0u; --newItems)
700       {
701         PushBack(item);
702       }
703     }
704   }
705
706   /**
707    * @brief Erases an element.
708    *
709    * Does not change capacity. Other elements get moved.
710    *
711    * @SINCE_1_0.0
712    * @param[in] iterator Iterator pointing to the item to remove
713    * @return Iterator pointing to next element
714    * @pre Iterator \e iterator must be within the vector's range ( Vector::Begin(), Vector::End() - 1 ).
715    *
716    */
717   Iterator Erase(Iterator iterator)
718   {
719     DALI_ASSERT_VECTOR((iterator < End()) && (iterator >= Begin()) && "Iterator not inside vector");
720     if(iterator < (End() - 1u))
721     {
722       VectorAlgorithms<BaseType>::Erase(reinterpret_cast<uint8_t*>(iterator), sizeof(ItemType));
723     }
724     else
725     {
726       // just remove the element
727       Remove(iterator);
728     }
729     return iterator;
730   }
731
732   /**
733    * @brief Erases a range of elements.
734    *
735    * Does not change capacity. Other elements get moved.
736    *
737    * @SINCE_1_0.0
738    * @param[in] first Iterator to the first element to be erased
739    * @param[in] last Iterator to the last element to be erased
740    *
741    * @return Iterator pointing to the next element of the last one
742    * @pre Iterator \e first must be in the vector's range ( Vector::Begin(), Vector::End() ).
743    * @pre Iterator \e last must be in the vector's range ( Vector::Begin(), Vector::End() ).
744    * @pre Iterator \e first must not be grater than Iterator \e last.
745    *
746    */
747   Iterator Erase(Iterator first, Iterator last)
748   {
749     DALI_ASSERT_VECTOR((first <= End()) && (first >= Begin()) && "Iterator not inside vector");
750     DALI_ASSERT_VECTOR((last <= End()) && (last >= Begin()) && "Iterator not inside vector");
751     DALI_ASSERT_VECTOR((first <= last) && "first iterator greater than last");
752
753     Iterator nextElement;
754
755     if(last == End())
756     {
757       // Erase up to the end.
758       VectorBase::SetCount(VectorBase::Count() - (last - first));
759       nextElement = End();
760     }
761     else
762     {
763       nextElement = reinterpret_cast<Iterator>(VectorAlgorithms<BaseType>::Erase(reinterpret_cast<uint8_t*>(first),
764                                                                                  reinterpret_cast<uint8_t*>(last),
765                                                                                  sizeof(ItemType)));
766     }
767
768     return nextElement;
769   }
770
771   /**
772    * @brief Removes an element.
773    *
774    * Does not maintain order. Swaps the element with end and
775    * decreases size by one.  This is much faster than Erase so use
776    * this in case order does not matter. Does not change capacity.
777    *
778    * @SINCE_1_0.0
779    * @param[in] iterator Iterator pointing to the item to remove
780    * @pre Iterator \e iterator must be in the vector's range ( Vector::Begin(), Vector::End() - 1 ).
781    *
782    */
783   void Remove(Iterator iterator)
784   {
785     DALI_ASSERT_VECTOR((iterator < End()) && (iterator >= Begin()) && "Iterator not inside vector");
786
787     Iterator last = End() - 1u;
788     if(last > iterator)
789     {
790       std::swap(*iterator, *last);
791     }
792     VectorBase::SetCount(VectorBase::Count() - 1u);
793   }
794
795   /**
796    * @brief Swaps the contents of two vectors.
797    *
798    * @SINCE_1_0.0
799    * @param[in] vector Vector to swap with
800    */
801   void Swap(Vector& vector)
802   {
803     VectorBase::Swap(vector);
804   }
805
806   /**
807    * @brief Clears the contents of the vector. Keeps its capacity.
808    * @SINCE_1_0.0
809    */
810   void Clear()
811   {
812     VectorAlgorithms<BaseType>::Clear();
813   }
814
815   /**
816    * @brief Releases the memory that the vector holds.
817    * @SINCE_1_0.0
818    */
819   void Release()
820   {
821     VectorAlgorithms<BaseType>::Release();
822   }
823 };
824
825 /**
826  * @brief Erases all elements that compare equal to value from the vector.
827  *
828  * @SINCE_1_9.33
829  * @param[in] vector The vector
830  * @param[in] value The value to be removed.
831  */
832 template<class T, class U>
833 inline void Erase(Dali::Vector<T>& vector, const U& value)
834 {
835   auto begin = vector.Begin();
836   auto end   = vector.End();
837
838   vector.Erase(std::remove(begin, end, value), end);
839 }
840
841 /**
842  * @brief Erases all elements that satisfy the predicate from the vector.
843  *
844  * @SINCE_1_9.33
845  * @param[in] vector The vector
846  * @param[in] predicate The predicate
847  */
848 template<class T, class Predicate>
849 inline void EraseIf(Dali::Vector<T>& vector, Predicate predicate)
850 {
851   auto begin = vector.Begin();
852   auto end   = vector.End();
853
854   vector.Erase(std::remove_if(begin, end, predicate), end);
855 }
856
857 /**
858  * @}
859  */
860 } // namespace Dali
861
862 #endif // DALI_VECTOR_H