diff d2/qtd/Array.d @ 344:96a75b1e5b26

project structure changes
author Max Samukha <maxter@spambox.com>
date Fri, 14 May 2010 12:14:37 +0300
parents qt/qtd/Array.d@e78566595089
children 31520b2c0b3c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/d2/qtd/Array.d	Fri May 14 12:14:37 2010 +0300
@@ -0,0 +1,37 @@
+/**
+ *
+ *  Copyright: Copyright QtD Team, 2008-2009
+ *  Authors: Max Samukha
+ *  License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>
+ *
+ *  Copyright QtD Team, 2008-2009
+ *  Distributed under the Boost Software License, Version 1.0.
+ *  (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+module qtd.Array;
+
+version (Tango)
+    import tango.stdc.string;
+else
+    import core.stdc.string;
+
+void remove(T)(ref T[] haystack, T needle)
+{
+    foreach (i, e; haystack)
+    {
+        if (e == needle)
+        {
+            if (haystack.length > 1)
+            {
+                i++;
+                memmove(haystack.ptr + i - 1, haystack.ptr + i, (haystack.length - i) * T.sizeof);
+                haystack.length = haystack.length - 1;
+            }
+            else
+                haystack.length = 0;
+
+            break;
+        }
+    }
+}