Mercurial > projects > qtd
annotate d1/qtd/Array.d @ 314:80b52f5e97b6 lifetime
Structure without common root dir
author | maxter <spambox@d-coding.com> |
---|---|
date | Wed, 23 Dec 2009 23:17:36 +0200 |
parents | 8674fd5f34f4 |
children |
rev | line source |
---|---|
311 | 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 */ | |
314
80b52f5e97b6
Structure without common root dir
maxter <spambox@d-coding.com>
parents:
311
diff
changeset
|
12 module qtd.Array; |
311 | 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 } |