Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
module test; import std.stdio; import std.range; struct MyLockStep(alias sentinel) { int[] arr1; int[] arr2; int opApply(int delegate(int, int) dg) { int res; while (!arr1.empty || !arr2.empty) { int e1; if (arr1.empty) { e1 = sentinel; } else { e1 = arr1.front; arr1.popFront; } int e2; if (arr2.empty) { e2 = sentinel; } else { e2 = arr2.front; arr2.popFront; } res = dg(e1, e2); if (res) break; } return res; } } void main() { int[] arr1 = [1, 2]; int[] arr2 = [2, 4, 3]; bool state; foreach (aa, bb; MyLockStep!(-1)(arr1, arr2)) { writeln(aa, " ", bb); } }
Result:
Success
/
Return code: 0
/
Compilation time:
0.261
seconds
/
Run time:
0.001
seconds
Application output:
1 2
2 4
-1 3
Username
Message
Add comment
Paste info
Author:
Guest
Views:
98
Private:
no
Expires:
Never
Uploaded:
18.09.12 1:01
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.060
Pointer size:
m32
Actions
Download
Fork
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason