2 import core.stdc.stdio;
7 /************************************************/
13 int opApply(int delegate(ref uint) dg)
16 for (int i = 0; i < array.length; i++)
18 result = dg(array[i]);
27 /**************************************************/
43 assert(a.array[0] == 73);
44 assert(a.array[1] == 82);
47 /**************************************************/
57 foreach (ref uint u; a)
63 assert(a.array[0] == 74);
64 assert(a.array[1] == 83);
67 /**************************************************/
77 foreach (ref uint u; a)
85 assert(a.array[0] == 73);
86 assert(a.array[1] == 82);
89 /**************************************************/
99 foreach (ref uint u; a)
107 assert(a.array[0] == 73 && a.array[1] == 83);
110 /**************************************************/
123 foreach (ref uint u; a)
132 assert(a.array[0] == 73);
133 assert(a.array[1] == 82);
136 /**************************************************/
149 foreach (ref uint u; a)
159 assert(a.array[0] == 74);
160 assert(a.array[1] == 83);
163 /**************************************************/
173 foreach (ref uint u; a)
183 assert(a.array[0] == 73);
184 assert(a.array[1] == 82);
187 /**************************************************/
192 foreach (ref uint u; a)
211 assert(a.array[0] == 73);
212 assert(a.array[1] == 82);
215 /**************************************************/
220 foreach (ref uint u; a)
240 assert(a.array[0] == 73);
241 assert(a.array[1] == 82);
244 /**************************************************/
249 foreach (ref uint u; a)
269 assert(a.array[0] == 73);
270 assert(a.array[1] == 82);
273 /**************************************************/
277 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0
279 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0
280 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0
281 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0
289 for (int i = 0; i < 25; i += 5) {
290 data[i+0] = data[i+1] = true;
293 for (int i = 0; i < 25; i++) {
294 printf("%d ", data[i]);
296 assert(data[i] == true);
298 assert(data[i] == false);
301 printf("\n%d\n", data[22] = true);
305 for (int i = 0; i < 25; i += 5) {
306 data[i+1] = data[i+3] = true;
308 if (j == 0 || j == 1 || j == 3)
309 assert(data[i] == true);
311 assert(data[i] == false);
314 for (int i = 0; i < 25; i++) {
315 printf("%d ", data[i]);
321 foreach (bit b; data) {
324 if (j == 0 || j == 1 || j == 3 || k == 22)
325 assert(data[k] == true);
327 assert(data[k] == false);
332 foreach (int l, bit b; data) {
335 if (j == 0 || j == 1 || j == 3 || l == 22)
336 assert(data[l] == true);
338 assert(data[l] == false);
344 /**************************************************/
351 foreach (dchar d; "hello")
353 printf("d = x%x\n", d);
354 if (j == 0) assert(d == 'h');
355 if (j == 1) assert(d == 'e');
356 if (j == 2) assert(d == 'l');
357 if (j == 3) assert(d == 'l');
358 if (j == 4) assert(d == 'o');
364 foreach (size_t i, dchar d; "hello")
366 printf("i = %d, d = x%x\n", i, d);
367 if (j == 0) assert(d == 'h');
368 if (j == 1) assert(d == 'e');
369 if (j == 2) assert(d == 'l');
370 if (j == 3) assert(d == 'l');
371 if (j == 4) assert(d == 'o');
378 /**************************************************/
385 foreach (wchar d; "hello")
387 printf("d = x%x\n", d);
388 if (j == 0) assert(d == 'h');
389 if (j == 1) assert(d == 'e');
390 if (j == 2) assert(d == 'l');
391 if (j == 3) assert(d == 'l');
392 if (j == 4) assert(d == 'o');
398 foreach (size_t i, wchar d; "hello")
400 printf("i = %d, d = x%x\n", i, d);
401 if (j == 0) assert(d == 'h');
402 if (j == 1) assert(d == 'e');
403 if (j == 2) assert(d == 'l');
404 if (j == 3) assert(d == 'l');
405 if (j == 4) assert(d == 'o');
412 /**************************************************/
419 foreach (char d; cast(wstring)"hello")
421 printf("d = x%x\n", d);
422 if (j == 0) assert(d == 'h');
423 if (j == 1) assert(d == 'e');
424 if (j == 2) assert(d == 'l');
425 if (j == 3) assert(d == 'l');
426 if (j == 4) assert(d == 'o');
432 foreach (size_t i, char d; cast(wstring)"hello")
434 printf("i = %d, d = x%x\n", i, d);
435 if (j == 0) assert(d == 'h');
436 if (j == 1) assert(d == 'e');
437 if (j == 2) assert(d == 'l');
438 if (j == 3) assert(d == 'l');
439 if (j == 4) assert(d == 'o');
446 /**************************************************/
453 foreach (dchar d; cast(wstring)"hello")
455 printf("d = x%x\n", d);
456 if (j == 0) assert(d == 'h');
457 if (j == 1) assert(d == 'e');
458 if (j == 2) assert(d == 'l');
459 if (j == 3) assert(d == 'l');
460 if (j == 4) assert(d == 'o');
466 foreach (size_t i, dchar d; cast(wstring)"hello")
468 printf("i = %d, d = x%x\n", i, d);
469 if (j == 0) assert(d == 'h');
470 if (j == 1) assert(d == 'e');
471 if (j == 2) assert(d == 'l');
472 if (j == 3) assert(d == 'l');
473 if (j == 4) assert(d == 'o');
480 /**************************************************/
487 foreach (char d; cast(dstring)"hello")
489 printf("d = x%x\n", d);
490 if (j == 0) assert(d == 'h');
491 if (j == 1) assert(d == 'e');
492 if (j == 2) assert(d == 'l');
493 if (j == 3) assert(d == 'l');
494 if (j == 4) assert(d == 'o');
500 foreach (size_t i, char d; cast(dstring)"hello")
502 printf("i = %d, d = x%x\n", i, d);
503 if (j == 0) assert(d == 'h');
504 if (j == 1) assert(d == 'e');
505 if (j == 2) assert(d == 'l');
506 if (j == 3) assert(d == 'l');
507 if (j == 4) assert(d == 'o');
514 /**************************************************/
521 foreach (wchar d; cast(dstring)"hello")
523 printf("d = x%x\n", d);
524 if (j == 0) assert(d == 'h');
525 if (j == 1) assert(d == 'e');
526 if (j == 2) assert(d == 'l');
527 if (j == 3) assert(d == 'l');
528 if (j == 4) assert(d == 'o');
534 foreach (size_t i, wchar d; cast(dstring)"hello")
536 printf("i = %d, d = x%x\n", i, d);
537 if (j == 0) assert(d == 'h');
538 if (j == 1) assert(d == 'e');
539 if (j == 2) assert(d == 'l');
540 if (j == 3) assert(d == 'l');
541 if (j == 4) assert(d == 'o');
548 /**************************************************/
552 string a = "\xE2\x89\xA0"; // \u2260 encoded as 3 UTF-8 bytes
556 printf("a[] = %x\n", c); // prints 'a[] = 2260'
560 dstring b = "\u2260";
565 printf("%x, ", c); // prints e2, 89, a0
566 if (i == 0) assert(c == 0xE2);
567 else if (i == 1) assert(c == 0x89);
568 else if (i == 2) assert(c == 0xA0);
576 /**************************************************/
580 string string = x"F0 9D 83 93";
584 foreach(dchar value ; string){
589 assert(tmp==0x01D0D3);
592 /**************************************************/
596 int opApply(int delegate(ref int i) dg)
607 foreach(int i; foo20)
614 /**************************************************/
616 void foo21(string[] args)
618 printf("args.length = %d\n", args.length);
619 assert(args.length == 3);
620 foreach (i, arg; args)
622 assert(typeid(typeof(i)) == typeid(size_t));
623 assert(typeid(typeof(arg)) == typeid(string));
624 writefln("args[%d] = '%s'", i, arg);
628 assert(typeid(typeof(arg)) == typeid(string));
629 writefln("args[] = '%s'", arg);
644 /**************************************************/
653 foreach (key, value; map)
655 assert(typeid(typeof(key)) == typeid(string));
656 assert(typeid(typeof(value)) == typeid(int));
657 writefln("map[%s] = %s", key, value);
659 foreach (key, int value; map)
661 assert(typeid(typeof(key)) == typeid(string));
662 assert(typeid(typeof(value)) == typeid(int));
663 writefln("map[%s] = %s", key, value);
665 foreach (string key, value; map)
667 assert(typeid(typeof(key)) == typeid(string));
668 assert(typeid(typeof(value)) == typeid(int));
669 writefln("map[%s] = %s", key, value);
673 assert(typeid(typeof(value)) == typeid(int));
674 writefln("map[] = %s", value);
678 /**************************************************/
684 int opApply(int delegate(ref int) dg)
687 for (int i = 0; i < array.length; i++)
689 result = dg(array[i]);
696 int opApply(int delegate(ref size_t, ref int) dg)
699 for (size_t i = 0; i < array.length; i++)
701 result = dg(i, array[i]);
711 Foo23 a = new Foo23();
719 assert(typeid(typeof(u)) == typeid(int));
722 //writefln("u = %d", u);
723 assert((i == 1) ? u == 74 : u == 83);
726 assert(a.array[0] == 73);
727 assert(a.array[1] == 82);
731 assert(typeid(typeof(j)) == typeid(size_t));
732 assert(typeid(typeof(u)) == typeid(int));
735 writefln("u = %d", u);
736 assert((i == 3) ? u == 74 : u == 83);
740 assert(a.array[0] == 73);
741 assert(a.array[1] == 82);
744 /**************************************************/
748 int opApply(int delegate(ref int) dg){
768 assert(foo24() == true);
771 /**************************************************/
775 alias void function(string[string]) FN;
776 FN fn = function (string[string] aarray)
778 foreach (string s; aarray)
784 string[string] aarray;
789 /**************************************************/
795 int forward(int delegate(ref uint) dg)
798 for (int i = 0; i < array.length; i++)
800 result = dg(array[i]);
807 int forward(int delegate(ref uint) dg, int x) { return 1; }
809 int reverse(int delegate(ref uint) dg, int x) { return 1; }
811 int reverse(int delegate(ref uint) dg)
814 foreach_reverse (v; array)
834 foreach (u; &a.forward)
841 assert(a.array[0] == 73);
842 assert(a.array[1] == 82);
844 foreach (uint u; &a.reverse)
850 /**************************************************/
856 bool empty() { return a.length == 0; }
858 void popFront() { a = a[1 .. $]; }
859 int front() { return a[0]; }
861 void popBack() { a = a[0 .. $ - 1]; }
862 ref int back() { return a[$ - 1]; }
874 r ~= cast(char)(e + '0');
879 foreach_reverse (ref e; s)
883 r ~= cast(char)(e + '0');
891 r ~= cast(char)(e + '0');
896 /**************************************************/