]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/d/src/thrift/internal/algorithm.d
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / d / src / thrift / internal / algorithm.d
CommitLineData
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 */
5module thrift.internal.algorithm;
6
7import std.algorithm : move;
8import std.exception;
9import std.functional;
10import std.range;
11import std.traits;
12
13enum SwapStrategy
14{
15 unstable,
16 semistable,
17 stable,
18}
19
20Range removeEqual(SwapStrategy s = SwapStrategy.stable, Range, E)(Range range, E e)
21if (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}