Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct MyRange {
- private int current_row = 0;
- private int rows_count = 5;
- @disable this(this); // <===
- bool empty () { return current_row == rows_count; }
- int front() { return current_row*current_row; }
- void popFront() { ++current_row; }
- }
- struct Container {
- @disable this(this); // <===
- int opApply(int delegate(int) dg) {
- foreach (int row; 0..5) dg(row*row);
- return 1;
- }
- }
- void foreach_iterable(Type)(ref Type iterable) {
- import std.stdio: writeln;
- foreach (int row_value; iterable) { // test_range.d(20): Error: struct test_range.MyRange is not copyable because it is annotated with @disable
- row_value.writeln;
- }
- }
- void call_iterable(Type)() {
- Type iterable;
- foreach_iterable(iterable);
- }
- void main() {
- call_iterable!Container(); // work
- call_iterable!MyRange(); // does`t work
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement