1
|
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 } |