| 1 |
module imports.test35a; |
| 2 |
|
| 3 |
template ElemTypeOf( T ) |
| 4 |
{ |
| 5 |
alias typeof(T.init[0]) ElemTypeOf; |
| 6 |
} |
| 7 |
|
| 8 |
template removeIf_( Elem, Pred ) |
| 9 |
{ |
| 10 |
size_t fn( Elem[] buf, Pred pred ) |
| 11 |
{ |
| 12 |
void exch( size_t p1, size_t p2 ) |
| 13 |
{ |
| 14 |
Elem t = buf[p1]; |
| 15 |
buf[p1] = buf[p2]; |
| 16 |
buf[p2] = t; |
| 17 |
} |
| 18 |
|
| 19 |
size_t cnt = 0; |
| 20 |
|
| 21 |
for( size_t pos = 0, len = buf.length; pos < len; ++pos ) |
| 22 |
{ |
| 23 |
if( pred( buf[pos] ) ) |
| 24 |
++cnt; |
| 25 |
else |
| 26 |
exch( pos, pos - cnt ); |
| 27 |
} |
| 28 |
return buf.length - cnt; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
template removeIf( Buf, Pred ) |
| 33 |
{ |
| 34 |
size_t removeIf( Buf buf, Pred pred ) |
| 35 |
{ |
| 36 |
return removeIf_!(ElemTypeOf!(Buf), Pred).fn( buf, pred ); |
| 37 |
} |
| 38 |
} |