@@ -468,20 +468,23 @@ $(P Properties for associative arrays are:)
468
468
else evaluates the $(D create) delegate and adds it to the associative array))
469
469
)
470
470
471
- $(HR)
471
+ $(H2 $(LNAME2 examples, Examples))
472
+
472
473
$(H3 $(LNAME2 aa_example, Associative Array Example: word count))
473
474
474
475
$(P Let's consider the file is ASCII encoded with LF EOL.
475
476
In general case we should use $(I dchar c) for iteration
476
477
over code points and functions from $(LINK2 $(ROOT_DIR)phobos/std_uni.html,std.uni).
477
478
)
478
479
480
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
479
481
---------
482
+ import std.algorithm : sort;
480
483
import std.file; // D file I/O
481
484
import std.stdio;
482
485
import std.ascii;
483
486
484
- void main (string[] args)
487
+ void main(string[] args)
485
488
{
486
489
ulong totalWords, totalLines, totalChars;
487
490
ulong[string] dictionary;
@@ -491,7 +494,7 @@ $(H3 $(LNAME2 aa_example, Associative Array Example: word count))
491
494
{
492
495
ulong wordCount, lineCount, charCount;
493
496
494
- foreach(line; File(arg).byLine())
497
+ foreach (line; File(arg).byLine())
495
498
{
496
499
bool inWord;
497
500
size_t wordStart;
@@ -549,6 +552,7 @@ $(H3 $(LNAME2 aa_example, Associative Array Example: word count))
549
552
}
550
553
}
551
554
---------
555
+ )
552
556
553
557
$(H3 $(LNAME2 aa_example_iteration, Associative Array Example: counting Tuples))
554
558
0 commit comments