comparison d1/qtd/Array.d @ 311:8674fd5f34f4 lifetime

Added d1/d2 top directories
author maxter <spambox@d-coding.com>
date Wed, 23 Dec 2009 16:17:22 +0200
parents
children 80b52f5e97b6
comparison
equal deleted inserted replaced
310:5bcfe9e7db7f 311:8674fd5f34f4
1 /**
2 *
3 * Copyright: Copyright QtD Team, 2008-2009
4 * Authors: Max Samukha
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>
6 *
7 * Copyright QtD Team, 2008-2009
8 * Distributed under the Boost Software License, Version 1.0.
9 * (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 *
11 */
12 module qt.qtd.Array;
13
14 version (Tango)
15 import tango.stdc.string;
16 else
17 import core.stdc.string;
18
19 void remove(T)(ref T[] haystack, T needle)
20 {
21 foreach (i, e; haystack)
22 {
23 if (e == needle)
24 {
25 if (haystack.length > 1)
26 {
27 i++;
28 memmove(haystack.ptr + i - 1, haystack.ptr + i, (haystack.length - i) * T.sizeof);
29 haystack.length = haystack.length - 1;
30 }
31 else
32 haystack.length = 0;
33
34 break;
35 }
36 }
37 }