Explorar o código

AK/Vector: Add `Vector::reverse()` method

This reverses the contents of the vector in-place.
Mustafa Quraish %!s(int64=3) %!d(string=hai) anos
pai
achega
27f28998b1
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  1. 6 0
      AK/Vector.h

+ 6 - 0
AK/Vector.h

@@ -746,6 +746,12 @@ public:
         return {};
     }
 
+    void reverse()
+    {
+        for (size_t i = 0; i < size() / 2; ++i)
+            AK::swap(at(i), at(size() - i - 1));
+    }
+
 private:
     void reset_capacity()
     {