]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /** |
2 | * Contains a modified version of std.algorithm.remove that doesn't take an | |
3 | * alias parameter to avoid DMD @@BUG6395@@. | |
4 | */ | |
5 | module thrift.internal.algorithm; | |
6 | ||
7 | import std.algorithm : move; | |
8 | import std.exception; | |
9 | import std.functional; | |
10 | import std.range; | |
11 | import std.traits; | |
12 | ||
13 | enum SwapStrategy | |
14 | { | |
15 | unstable, | |
16 | semistable, | |
17 | stable, | |
18 | } | |
19 | ||
20 | Range removeEqual(SwapStrategy s = SwapStrategy.stable, Range, E)(Range range, E e) | |
21 | if (isBidirectionalRange!Range) | |
22 | { | |
23 | auto result = range; | |
24 | static if (s != SwapStrategy.stable) | |
25 | { | |
26 | for (;!range.empty;) | |
27 | { | |
28 | if (range.front !is e) | |
29 | { | |
30 | range.popFront; | |
31 | continue; | |
32 | } | |
33 | move(range.back, range.front); | |
34 | range.popBack; | |
35 | result.popBack; | |
36 | } | |
37 | } | |
38 | else | |
39 | { | |
40 | auto tgt = range; | |
41 | for (; !range.empty; range.popFront) | |
42 | { | |
43 | if (range.front is e) | |
44 | { | |
45 | // yank this guy | |
46 | result.popBack; | |
47 | continue; | |
48 | } | |
49 | // keep this guy | |
50 | move(range.front, tgt.front); | |
51 | tgt.popFront; | |
52 | } | |
53 | } | |
54 | return result; | |
55 | } |