Advertisement
Guest User

Untitled

a guest
Jun 21st, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.88 KB | None | 0 0
  1. struct MyRange {
  2.     private int current_row = 0;
  3.     private int rows_count = 5;
  4.     @disable this(this); // <===
  5.     bool empty () { return current_row == rows_count; }
  6.     int front() { return current_row*current_row; }
  7.     void popFront() { ++current_row; }
  8. }
  9.  
  10. struct Container {
  11.     @disable this(this); // <===
  12.     int opApply(int delegate(int) dg) {
  13.         foreach (int row; 0..5) dg(row*row);
  14.         return 1;
  15.     }
  16. }
  17.  
  18. void foreach_iterable(Type)(ref Type iterable) {
  19.     import std.stdio: writeln;
  20.     foreach (int row_value; iterable) { // test_range.d(20): Error: struct test_range.MyRange is not copyable because it is annotated with @disable
  21.         row_value.writeln;
  22.     }
  23. }
  24.  
  25. void call_iterable(Type)() {
  26.     Type iterable;
  27.     foreach_iterable(iterable);
  28. }
  29.  
  30. void main() {
  31.     call_iterable!Container(); // work
  32.     call_iterable!MyRange(); // does`t work
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement