commit 92d0a0e386d1f5b06f9182b28922513d1e61e00d
parent 02b8bed7bfe94c0f048fe1d0157c36318ecf8fda
Author: Dominik Schmidt <das1993@hotmail.com>
Date: Sun, 9 Aug 2015 16:18:42 +0200
Preserve the positition in opApply.
Diffstat:
1 file changed, 8 insertions(+), 0 deletions(-)
diff --git a/dfortune.d b/dfortune.d
@@ -163,6 +163,7 @@ class Fortune : RandomAccessFinite!(Cookie){
}
int opApply(int delegate(Cookie)f){
int ret;
+ immutable uint pos=this.pos;
while(!empty()){
ret=f(front());
popFront();
@@ -170,6 +171,7 @@ class Fortune : RandomAccessFinite!(Cookie){
break;
}
}
+ this.pos=pos;
return ret;
}
Cookie moveFront(){
@@ -187,6 +189,7 @@ class Fortune : RandomAccessFinite!(Cookie){
int opApply(int delegate(size_t,Cookie)f){
int ret;
size_t cnt=0;
+ immutable uint pos=this.pos;
while(!empty()){
ret=f(cnt++, front());
popFront();
@@ -194,6 +197,7 @@ class Fortune : RandomAccessFinite!(Cookie){
break;
}
}
+ this.pos=pos;
return ret;
}
Cookie moveAt(size_t i){
@@ -289,6 +293,7 @@ struct Fortunes{
}
int opApply(int delegate(CookieResult)f){
int ret;
+ immutable size_t pos=this.pos;
while(!empty()){
ret=f(moveFront());
popFront();
@@ -296,11 +301,13 @@ struct Fortunes{
break;
}
}
+ this.pos=pos;
return ret;
}
int opApply(int delegate(size_t,CookieResult)f){
int ret;
size_t i;
+ immutable size_t pos=this.pos;
while(!empty()){
ret=f(i++,moveFront());
popFront();
@@ -308,6 +315,7 @@ struct Fortunes{
break;
}
}
+ this.pos=pos;
return ret;
}
@property bool empty() const{