Mercurial > projects > qtd
comparison 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 |
comparison
equal
deleted
inserted
replaced
343:552647ec0f82 | 344:96a75b1e5b26 |
---|---|
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 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 } |