-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.html
4279 lines (4013 loc) · 209 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<meta name="description" content="Effective D Programming Language.">
<style type="text/css" media="all" >/* Eric Meyer's Reset CSS v2.0 - http://cssreset.com */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}table{border-collapse:collapse;border-spacing:0}
html
{
height: 100%;
font-size: 10px;
}
body
{
font-family: "HelveticaNeue", "Helvetica Neue", "HelveticaNeueRoman", "HelveticaNeue-Roman", "Helvetica Neue Roman", 'TeXGyreHerosRegular', "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif;
font-weight: 400;
font-stretch: normal;
display: block;
color: #bbbbbb;
background-color: #424040;
}
.sub
{
font-size: 0.8em;
vertical-align: super;
}
.container
{
display: block;
width: 90%;
max-width: 1100px;
padding: 0.5rem;
margin: 0 auto;
background-color: #bbbbbc;
box-shadow: 0.2rem 0.4rem 1rem 0rem rgba(32,32,32,0.15);
}
.permalink
{
float: right;
display: inline-block;
font-size: 0.7em;
}
header
{
display: block;
width: 90%;
max-width: 1100px;
padding: 0 0.5rem;
margin: 0 auto;
background-color: #744;
font-weight: 700;
vertical-align: middle;
box-shadow: 0.2em 0.8em 1em 0em rgba(32,32,32,0.15);
z-index: 5;
color: #e8e8ef;
}
nav
{
display: block;
width: 90%;
max-width: 1100px;
font-size: 1.6rem;
padding: 0.5rem;
margin: 0 auto;
background-color: #ededef;
list-style-type: square;
box-shadow: 0.2em 0.4em 2.0em 0em rgba(32,32,32,0.1);
z-index: 10;
}
footer
{
display: block;
width: 90%;
max-width: 1100px;
font-size: 1.6rem;
padding: 0.5rem;
margin: 0 auto;
background-color: #744;
list-style-type: square;
box-shadow: 0.2em 0.4em 2.0em 0em rgba(32,32,32,0.1);
z-index: 10;
color: black;
line-height: 1.3em;
}
footer h2
{
color: #f8deb7;
padding: 4rem 4.25rem 0rem 4.25rem;
margin: 2rem;
}
footer p, footer ul
{
padding: 0rem 4.25rem 0rem 4.25rem;
margin: 2rem;
color: #ccb3b3;
}
footer a
{
color: #84c6ea;
}
a
{
text-decoration: none;
color: #5050c0;
font-weight: 700;
}
a:hover
{
color: #5000c0;
text-decoration: underline;
}
.item-nav
{
padding: 0.32em;
margin: 1rem 8rem 1rem 8rem;
display: list-item;
}
h1
{
font-size: 2.38rem;
padding: 1.2rem;
margin: 0em 0em 2.4rem 1.2rem;
color: #444;
}
h2
{
font-size: 1.9rem;
padding: 0.34rem;
margin: 4rem 0rem 1rem -0.5rem;
color: #444;
}
p
{
padding: 1rem 2rem;
padding: 1rem 2rem;
max-width: 80rem;
}
ol
{
margin: 0.85rem;
}
li
{
display: list-item;
list-style: square;
margin: 0rem 0rem 0rem 6rem;
padding: 0.34rem;
}
strong
{
font-weight: 700;
}
em
{
font-style:italic;
}
.prettyprint
{
font-family: "Inconsolata", "Courier New", "Courier", monospace, sans-serif;
color: #883000;
}
pre
{
font-family: "Inconsolata", "Courier New", "Courier", monospace, sans-serif;
padding: 0rem;
margin: 1.7rem;
font-size: 1.53rem;
line-height: 1.7rem;
box-shadow: inset 0.15rem 0.3rem 1.5rem 0rem rgba(0,0,0,0.2);
}
.idiom
{
font-size: 1.7rem;
color: #222;
background-color: #ededef;
display: block;
padding: 8rem 6rem;
margin: 2.4rem;
line-height: 2.5rem;
box-shadow: 0.17rem 0.34rem 1.7rem 0rem rgba(32,32,32,0.15);
}
#logo
{
position: relative;
display: inline-block;
left: -0.5rem;
vertical-align: bottom;
}
#title-container
{
display: inline-block;
vertical-align: bottom;
margin: 4.3rem 1rem 4.3rem 1rem;
}
#title
{
font-size: 2.3rem;
line-height: 1em;
}
#sub-title
{
font-size: 0.5em;
font-style: italic;
font-weight: normal;
color: #b37777;
}
img
{
max-width: 100%;
}/*
vim-hybrid theme by w0ng (https://github.com/w0ng/vim-hybrid)
*/
/*background color*/
.hljs {
display: block;
overflow-x: auto;
padding: 1.0em;
background: #1d1f21;
-webkit-text-size-adjust: none;
}
/*selection color*/
.hljs::selection,
.hljs span::selection {
background: #bababa;
}
.hljs::-moz-selection,
.hljs span::-moz-selection {
background: #bababa;
}
/*foreground color*/
.hljs,
.hljs-setting .hljs-value,
.hljs-expression .hljs-variable,
.hljs-expression .hljs-begin-block,
.hljs-expression .hljs-end-block,
.hljs-class .hljs-params,
.hljs-function .hljs-params,
.hljs-at_rule .hljs-preprocessor {
color: #c5c8c6;
}
/*color: fg_yellow*/
.hljs-title,
.hljs-function .hljs-title,
.hljs-keyword .hljs-common,
.hljs-class .hljs-title,
.hljs-decorator,
.hljs-tag .hljs-title,
.hljs-header,
.hljs-sub,
.hljs-function {
color: #f0c674;
}
/*color: fg_comment*/
.hljs-comment,
.hljs-javadoc,
.hljs-output .hljs-value,
.hljs-pi,
.hljs-shebang,
.hljs-doctype {
color: #707880;
}
/*color: fg_red*/
.hljs-number,
.hljs-symbol,
.hljs-literal,
.hljs-deletion,
.hljs-link_url,
.hljs-symbol .hljs-string,
.hljs-argument,
.hljs-hexcolor,
.hljs-input .hljs-prompt,
.hljs-char {
color: #cc6666
}
/*color: fg_green*/
.hljs-string,
.hljs-special,
.hljs-javadoctag,
.hljs-addition,
.hljs-important,
.hljs-tag .hljs-value,
.hljs-at.rule .hljs-keyword,
.hljs-regexp,
.hljs-attr_selector {
color: #b5bd68;
}
/*color: fg_purple*/
.hljs-variable,
.hljs-property,
.hljs-envar,
.hljs-code,
.hljs-expression,
.hljs-localvars,
.hljs-id,
.hljs-variable .hljs-filter,
.hljs-variable .hljs-filter .hljs-keyword,
.hljs-template_tag .hljs-filter .hljs-keyword {
color: #b294bb;
}
/*color: fg_blue*/
.hljs-statement,
.hljs-label,
.hljs-keyword,
.hljs-xmlDocTag,
.hljs-function .hljs-keyword,
.hljs-chunk,
.hljs-cdata,
.hljs-link_label,
.hljs-bullet,
.hljs-class .hljs-keyword,
.hljs-smartquote,
.hljs-method,
.hljs-list .hljs-title,
.hljs-tag {
color: #81a2be;
}
/*color: fg_aqua*/
.hljs-pseudo,
.hljs-exception,
.hljs-annotation,
.hljs-subst,
.hljs-change,
.hljs-cbracket,
.hljs-operator,
.hljs-horizontal_rule,
.hljs-preprocessor .hljs-keyword,
.hljs-typedef,
.hljs-template_tag,
.hljs-variable,
.hljs-variable .hljs-filter .hljs-argument,
.hljs-at_rule,
.hljs-at_rule .hljs-string,
.hljs-at_rule .hljs-keyword {
color: #8abeb7;
}
/*color: fg_orange*/
.hljs-type,
.hljs-typename,
.hljs-inheritance .hljs-parent,
.hljs-constant,
.hljs-built_in,
.hljs-setting,
.hljs-structure,
.hljs-link_reference,
.hljs-attribute,
.hljs-blockquote,
.hljs-quoted,
.hljs-class,
.hljs-header {
color: #de935f;
}
.hljs-emphasis
{
font-style: italic;
}
.hljs-strong
{
font-weight: bold;
}
</style><link href='//fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
<title>d-idioms - Idioms for the D programming language</title></head><body><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-71912218-1', 'auto');ga('send', 'pageview');</script><script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<header><img id="logo" src="d-logo.svg"></img><div id="title-container"><div id="title">Idioms for the D Programming Language
<br><div id="sub-title"><b>ἰδῐόω</b> (idióō): peculiarity, specific property, unique feature.</div></div></div></header><nav><div class="item-nav"><a href="#The-merged-allocation-optimization">The merged allocation optimization
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Aug 6<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#DIID-#12---Simple-HTTP-server">DIID #12 - Simple HTTP server
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created May 15<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#DIID-#11---Write-current-date-on-a-PNG">DIID #11 - Write current date on a PNG
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created May 15<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#Installing-Dlang-on-Windows">Installing Dlang on Windows
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Apr 15<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#DIID-#10---Colorize-console-output">DIID #10 - Colorize console output
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Mar 20<span class="sub">th</span> 2022, created Mar 14<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#DIID-#9---Parse-command-line-arguments">DIID #9 - Parse command-line arguments
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Mar 14<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#/+-+/-nestable-comments-and-version(none)">/+ +/ nestable comments and version(none)
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 22<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#@nogc-Array-Literals:-Breaking-the-Limits">@nogc Array Literals: Breaking the Limits
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Oct 23<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Adding-or-removing-an-element-from-arrays">Adding or removing an element from arrays
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 22<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#assert(false)-is-special">assert(false) is special
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 14<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Automatic-attribute-inference-for-function-templates">Automatic attribute inference for function templates
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Feb 14<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Bypassing-@nogc">Bypassing @nogc
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jun 7<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Capturing-with-regular-expressions">Capturing with regular expressions
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 29<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Compile-time-RNG">Compile-time RNG
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Feb 5<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Contributing-back-with-money">Contributing back with money
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 1<span class="sub">st</span> 2018
</span></div><div class="item-nav"><a href="#Converting-from-and-to-C-strings">Converting from and to C strings
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Feb 14<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Custom-format()-for-builtin-types">Custom format() for builtin types
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jun 8<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#D-online-resources">D online resources
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 8<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Design-by-Introspection">Design by Introspection
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 23<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Differences-in-integer-handling-vs-C">Differences in integer handling vs C
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Feb 14<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Don't-use-@property">Don't use @property
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created May 11<span class="sub">th</span> 2019
</span></div><div class="item-nav"><a href="#Emulating-Perl's-__DATA__">Emulating Perl's __DATA__
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 14<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#Ensure-array-access-without-bounds-checking">Ensure array access without bounds checking
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 7<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Enumerate-fields-with-__traits(allMembers)-and-static-foreach">Enumerate fields with __traits(allMembers) and static foreach
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 20<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Eponymous-templates">Eponymous templates
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Oct 4<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Everything-you-wanted-to-ask-about-struct-construction">Everything you wanted to ask about struct construction
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 24<span class="sub">th</span> 2017
</span></div><div class="item-nav"><a href="#Extend-a-struct-with-alias-this">Extend a struct with alias this
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Nov 28<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Falsey-values">Falsey values
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 15<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Four-ways-to-use-the-static-keyword-you-may-not-know-about">Four ways to use the static keyword you may not know about
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 26<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Friends-don't-let-friends-use-the-default-struct-postblit">Friends don't let friends use the default struct postblit
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 6<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Games-made-with-D">Games made with D
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 14<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#GC-proof-resource-class">GC-proof resource class
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Aug 30<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Get-parent-class-of-a-class-at-compile-time">Get parent class of a class at compile-time
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 7<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#Getting-a-method-callbacked-from-C">Getting a method callbacked from C
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 23<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Grouping-modules-with-package.d">Grouping modules with package.d
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 22<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#How-does-D-improve-on-C++17?">How does D improve on C++17?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Apr 26<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#How-the-D-Garbage-Collector-works">How the D Garbage Collector works
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Feb 14<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#if-(__ctfe)">if (__ctfe)
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Feb 22<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#if-embedded-declaration">if embedded declaration
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 15<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Implicit-conversion-for-user-defined-types">Implicit conversion for user-defined types
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 23<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Inheriting-from-Exception">Inheriting from Exception
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 4<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Is-a-specific-program-available-in-PATH?">Is a specific program available in PATH?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Oct 15<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Is-this-available-at-compile-time-or-runtime?">Is this available at compile-time or runtime?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Apr 19<span class="sub">th</span> 2017
</span></div><div class="item-nav"><a href="#Knowing-inout-inside-out">Knowing inout inside out
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 5<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Leveraging-TLS-for-a-fast-thread-safe-singleton">Leveraging TLS for a fast thread-safe singleton
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 20<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Linking-with-C-gotchas">Linking with C gotchas
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 14<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Minimum-or-maximum-of-numbers">Minimum or maximum of numbers
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 4<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Never-use->=-for-dependencies">Never use >= for dependencies
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 28<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#One-does-not-simply-call-new-for-static-arrays">One does not simply call new for static arrays
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created May 6<span class="sub">th</span> 2018
</span></div><div class="item-nav"><a href="#Optimal-AA-lookup">Optimal AA lookup
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 10<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Parallel-foreach">Parallel foreach
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 3<span class="sub">rd</span> 2019
</span></div><div class="item-nav"><a href="#Patching-a-library-available-on-the-DUB-registry">Patching a library available on the DUB registry
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 7<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#People-blogging-about-D">People blogging about D
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 20<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Phobos-gems">Phobos gems
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 17<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Placement-new-with-emplace">Placement new with emplace
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 14<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Porting-from-C-gotchas">Porting from C gotchas
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 11<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Precise-timestamps-in-milliseconds">Precise timestamps in milliseconds
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Oct 6<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Precomputed-tables-at-compile-time-through-CTFE">Precomputed tables at compile-time through CTFE
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 26<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Qualified-switch-using-with">Qualified switch using with
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 4<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Recursive-Sum-Type-with-matching">Recursive Sum Type with matching
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 24<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Renaming-a-module-with-backwards-compatibility">Renaming a module with backwards compatibility
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 14<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#Rvalue-references:-Understanding-auto-ref-and-then-not-using-it">Rvalue references: Understanding auto ref and then not using it
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Oct 23<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Searching-for-a-substring-position">Searching for a substring position
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 4<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Should-I-use-++pre-increment-or-post-increment++?">Should I use ++pre-increment or post-increment++?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 22<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Skip-initialization-with-=-void">Skip initialization with = void
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created May 16<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Slices-.capacity,-the-mysterious-property">Slices .capacity, the mysterious property
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Mar 22<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Smallest-dub.json-for-an-executable">Smallest dub.json for an executable
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 8<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#So-D-is-just-C++-with-a-Garbage-Collector?">So D is just C++ with a Garbage Collector?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 4<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#So-what-do-module-declarations-do,-exactly?">So what do module declarations do, exactly?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Sep 4<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#So-what-does--debug-do,-exactly?">So what does -debug do, exactly?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Apr 18<span class="sub">th</span> 2018
</span></div><div class="item-nav"><a href="#So-what-does--release-do,-exactly?">So what does -release do, exactly?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created May 16<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Static-arrays-are-value-types">Static arrays are value types
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 10<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#String-interpolation-as-a-library">String interpolation as a library
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 20<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#The-importance-of-being-pure">The importance of being pure
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 27<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#The-impossible-real-time-thread">The impossible real-time thread
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 24<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#The-trouble-with-class-destructors">The trouble with class destructors
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 31<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#The-truth-about-shared">The truth about shared
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 10<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Trailing-commas">Trailing commas
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 27<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Type-qualifiers-and-slices-creation">Type qualifiers and slices creation
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created May 6<span class="sub">th</span> 2018
</span></div><div class="item-nav"><a href="#Unittests-with-optimizations-:-the-Final-Frontier">Unittests with optimizations : the Final Frontier
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Feb 22<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#Unrecoverable-vs-recoverable-errors">Unrecoverable vs recoverable errors
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Feb 12<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#Using-std.typecons.Flag-like-a-pro">Using std.typecons.Flag like a pro
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 21<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Voldemort-types">Voldemort types
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 5<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#What-is-the-difference-between-out-and-ref-parameters?">What is the difference between out and ref parameters?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Feb 22<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#Which-book-should-I-read?">Which book should I read?
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Jan 5<span class="sub">th</span> 2016
</span></div><div class="item-nav"><a href="#Working-with-files">Working with files
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Feb 22<span class="sub">th</span> 2022, created Oct 4<span class="sub">th</span> 2015
</span></div><div class="item-nav"><a href="#DIID-#8---Your-own-tree-walk-interpreter">DIID #8 - Your own tree-walk interpreter
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Jan 29<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#DIID-#1---Parse-XML-file">DIID #1 - Parse XML file
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Jan 29<span class="sub">th</span> 2022, created Dec 9<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#DIID-#7---GET-a-file-from-the-Internet">DIID #7 - GET a file from the Internet
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Jan 29<span class="sub">th</span> 2022
</span></div><div class="item-nav"><a href="#DIID-#6---Parse-JSON-file">DIID #6 - Parse JSON file
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Dec 18<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#DIID-#2---Play-music">DIID #2 - Play music
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Dec 18<span class="sub">th</span> 2021, created Dec 9<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#DIID-#3---Convert-Markdown-to-HTML">DIID #3 - Convert Markdown to HTML
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Dec 18<span class="sub">th</span> 2021, created Dec 9<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#DIID-#4---Draw-an-accelerated-triangle">DIID #4 - Draw an accelerated triangle
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Modified Dec 18<span class="sub">th</span> 2021, created Dec 9<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#DIID-#5---Draw-a-triangle-in-a-PDF">DIID #5 - Draw a triangle in a PDF
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Dec 18<span class="sub">th</span> 2021
</span></div><div class="item-nav"><a href="#Smallest-valid-D-program">Smallest valid D program
</a><span style=" color:rgb(158,158,158); font-size: 0.7em; float: right;"> Created Oct 19<span class="sub">th</span> 2016
</span></div></nav><div class="container"><a name="The-merged-allocation-optimization"></a><div class="idiom"><a class="permalink" href="#The-merged-allocation-optimization">Link
</a><h1 id="the-merged-allocation-optimization">The merged allocation optimization</h1>
<p>One of the most suprisingly effective optimization is to merge your array allocations together, if they have a chance to be accessed together.
</p>
<p>You can do that with eg. <code class="prettyprint">MergedAlloc</code>, a handy way to do that in an aggregate, that supports alignment, does the memory reclaim, and supports both pointers and slices.
</p>
<h2 id="usage"> Usage</h2>
<p>Consider the following <code class="prettyprint">struct</code>. It process things with intermediate buffers, who themselved have alignment requirements.
</p>
<pre class="prettyprint"><code>struct A
{
float[] buf0;
int[] buf1;
double* buf2;
void init(int n)
{
// allocate arrays
buf0 = allocateAligned!float(n, 16);
buf1 = allocateAligned!int(n, 16);
buf2 = allocateAligned!double(n, 16).ptr;
}
~this()
{
// reclaim memory
deallocate(buf0);
deallocate(buf1);
deallocate(buf2);
}
void process(float[] input)
{
// Do things with buf0, buf1, buf2, and input
}
}
</code></pre><p>Let's introduce <code class="prettyprint">MergedAlloc</code> instead to have all the arrays in a single <code class="prettyprint">malloc</code> call.
</p>
<pre class="prettyprint"><code>struct A
{
float[] buf0;
int[] buf1;
double* buf2;
MergedAllocation mergedAlloc;
void init(int n)
{
mergedAlloc.start(); // initialize merged alloc counter
layout(n); // first layout call count the bytes
mergedAlloc.allocate(); // make single allocation
layout(n); // second layout call sets the final pointers
}
void layout(int n)
{
mergedAlloc.allocArray(buf0, n, 16);
mergedAlloc.allocArray(buf1, n, 16);
mergedAlloc.alloc(buf2, n, 16);
}
void process(float[] input)
{
// Do things with buf0, buf1, buf2, and input
}
}
</code></pre><p>The <code class="prettyprint">layout</code> functions is called twice:
</p>
<ul>
<li>first call is as if the allocation was at address <code class="prettyprint">0</code>, and simply count the bytes
</li>
<li>second call sets the right pointers into fields, into the merge allocation
</li>
</ul>
<h2 id="mergedalloc-implementation"> <code class="prettyprint">MergedAlloc</code> implementation</h2>
<p>See its <a href="https://github.com/AuburnSounds/Dplug/blob/master/core/dplug/core/vec.d#L593">source code</a>.
</p>
</div><a name="DIID-#12---Simple-HTTP-server"></a><div class="idiom"><a class="permalink" href="#DIID-#12---Simple-HTTP-server">Link
</a><h1 id="diid-12-simple-http-server"> DIID #12 - Simple HTTP server</h1>
<p><strong>Solution:</strong> Use the <code class="prettyprint">arsd-official:cgi</code> <a href="https://code.dlang.org/packages/arsd-official%3Acgi">package</a>.
</p>
<h2 id="dub-json"> <code class="prettyprint">dub.json</code></h2>
<pre class="prettyprint"><code>{
"name": "simple-HTTP-server",
"dependencies":
{
"arsd-official:cgi": "~>10.0"
}
}
</code></pre><h2 id="index-html"> <code class="prettyprint">index.html</code></h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Hello</h1>
<p>This page brought to you by D.</p>
</body>
</html>
</code></pre><h2 id="source-main-d"> <code class="prettyprint">source/main.d</code></h2>
<pre class="prettyprint"><code>static import std.file;
import arsd.cgi;
import std.format;
import std.stdio;
void myHTTPServer(Cgi cgi)
{
string url = cgi.pathInfo;
writefln("GET %s", url);
switch(cgi.pathInfo)
{
case "/style.css":
cgi.setResponseContentType("text/css");
cgi.write("body { color: red; }");
break;
case "/":
cgi.setResponseContentType("text/html");
cgi.write(std.file.read("index.html"));
break;
default:
cgi.setResponseStatus(404);
}
cgi.close();
}
mixin GenericMain!myHTTPServer;
</code></pre><h2 id="how-to-run"> How to run</h2>
<p><code class="prettyprint">dub -- --port 8080</code> then open <code class="prettyprint">http://localhost:8080/</code>.
</p>
<p>Get <code class="prettyprint">cgi.d</code> documentation <a href="https://arsd-official.dpldocs.info/arsd.cgi.html">here</a>.<br/>Get the source code for all DIID examples <a href="https://github.com/p0nce/DIID">here</a>.
</p>
<h2 id="alternatives"> Alternatives:</h2>
<ul>
<li><a href="https://vibed.org/">vibe.d</a>
</li>
<li><a href="https://code.dlang.org/packages/serverino">serverino</a>
</li>
<li><a href="https://code.dlang.org/packages/archttp">archttp</a>
</li>
</ul>
</div><a name="DIID-#11---Write-current-date-on-a-PNG"></a><div class="idiom"><a class="permalink" href="#DIID-#11---Write-current-date-on-a-PNG">Link
</a><h1 id="diid-11-write-current-date-on-a-png"> DIID #11 - Write current date on a PNG</h1>
<p><strong>Solution:</strong> Use the <code class="prettyprint">dplug:graphics</code> <a href="https://code.dlang.org/packages/dplug%3Agraphics">package</a>.
</p>
<h2 id="dub-json"> <code class="prettyprint">dub.json</code></h2>
<pre class="prettyprint"><code>{
"name": "write-current-date-on-png",
"dependencies":
{
"dplug:graphics": "~>12.0"
}
}
</code></pre><h2 id="input-image-and-font-file"> Input image and font file</h2>
<p>This program assumes <code class="prettyprint">input.png</code> and <code class="prettyprint">VeraBd.ttf</code> in the project directory.
</p>
<h2 id="source-main-d"> <code class="prettyprint">source/main.d</code></h2>
<pre class="prettyprint"><code>static import std.file;
import std.datetime;
import dplug.graphics;
void main(string[] args)
{
// Load image.
auto image = loadOwnedImage( std.file.read("input.png") );
// Load font.
auto font = new Font( cast(ubyte[]) std.file.read("VeraBd.ttf") );
// Write text.
RGBA red = RGBA(255, 0, 0, 255);
float textX = 20;
float textY = 20;
float fontSize = 16;
string timeStr = Clock.currTime().toISOExtString();
image.toRef.fillText(font, timeStr, fontSize, 0.0, red, textX, textY, HorizontalAlignment.left);
// Save image.
std.file.write("output.png", image.toRef.convertImageRefToPNG);
}
</code></pre><p>Get <code class="prettyprint">dplug:graphics</code> documentation <a href="http://dplug.dpldocs.info/dplug.graphics.html">here</a>.<br/>Get the source code for all DIID examples <a href="https://github.com/p0nce/DIID">here</a>.<br/><strong>Alternative:</strong> <a href="https://forum.dlang.org/post/[email protected]">arsd solution</a>.
</p>
</div><a name="Installing-Dlang-on-Windows"></a><div class="idiom"><a class="permalink" href="#Installing-Dlang-on-Windows">Link
</a><h1 id="installing-dlang-on-windows"> Installing Dlang on Windows</h1>
<p><em>This idiom by Stephane Ribas.</em>
</p>
<p><em>Installing the D programming language on Windows can be sometimes difficult. This guide is intended to provide a beginner-friendly tutorial for foolproof D installation, using Visual Studio + VisualD.</em>
</p>
<h2 id="general-plan-to-install-d-language-ldc-etc"> <strong>General plan to install D language, LDC, etc.</strong></h2>
<p>Install & compile D code by following those steps:
</p>
<ol>
<li>1. Install Microsoft Visual Studio.
</li>
<li>2. Add C++ & Windows SDK libs.
</li>
<li>3. Install Visual D.
</li>
<li>4. Check the LDC path in the <code class="prettyprint">PATH</code> environment variable.
</li>
<li>5. Open a terminal window, check that DUB and compilers are working.
</li>
</ol>
<p><em>The order is important!</em>
</p>
<h2 id="1-install-microsoft-visual-studio-ide-libraries"> <strong>1. Install Microsoft Visual Studio IDE + Libraries</strong></h2>
<p>Before starting the D language installation, we recommend you to install FIRST the Microsoft Visual Studio Community IDE:
</p>
<ol>
<li><p>To do so you will have to install <strong>Microsoft Visual Installer</strong> that can be downloaded from Microsoft Visual Studio <a href="https://visualstudio.microsoft.com">official website</a>.
</p>
</li>
<li><p>Once you have downloaded this executable and installed it on your PC, launch it and install the free <strong>Microsoft Visual Studio Community Edition</strong> (2019 version or above).
</p>
</li>
</ol>
<p><img src="assets/vs-community.png" alt="">
</p>
<ol>
<li><p><strong>IMPORTANT:</strong> Once installed, you need to install Windows SDK and C/C++ libs.
</p>
</li>
</ol>
<h2 id="2-install-librairies"> <strong>2. Install librairies</strong></h2>
<h3 id="windows-sdk-version-10-or-11"> <strong>Windows SDK (version 10 or 11)</strong></h3>
<ol>
<li><p>Open again the Microsoft Visual Installer & in Microsoft Visual Studio Community area, click on the "MODIFY" option
</p>
</li>
</ol>
<p><img src="assets/vs-modify.png" alt="">
</p>
<ol>
<li><p>Choose the thumbnail called "Individual component':
</p>
</li>
</ol>
<p><img src="assets/all-kits.png" alt="">
</p>
<ol>
<li><p>In the SEARCH toolbar, write "Windows SDK" and press ENTER:
</p>
</li>
</ol>
<p><img src="assets/windows-sdk.png" alt="">
</p>
<ol>
<li><p>The program will show you all the Windows SDK libraries that you can install on your system.
</p>
</li>
<li><p>Install ALL OF THEM.
</p>
</li>
</ol>
<h3 id="windows-c-c-libs"> <strong>Windows C++/C libs</strong></h3>
<ol>
<li>Once you have install the Windows SDK librairies, go back the SEARCH toolbar.
</li>
<li>Write "C++ development tools".
</li>
<li>The program will show you all the libraries that you can install on your system.
</li>
<li>Install ALL OF THEM...
</li>
</ol>
<p><img src="assets/vs-search.png" alt="">
</p>
<ol>
<li><p>Now you have an IDE & libs installed. Perfect!
</p>
</li>
</ol>
<p><em>Explanation: D programs links with both the D runtime, and a C runtime. Here the C runtime is MSVCRT (Visual C language runtime), so we need to install it.</em>
</p>
<h2 id="3-visual-d-installer"> <strong>3. Visual D installer</strong></h2>
<ol>
<li>Go on the official webpage <a href="https://rainers.github.io/visuald/visuald/StartPage.html">VisualD installer</a> that bundles everything needed for D on Windows. That installer will install VisualD, LDC and DMD on your computer.
</li>
<li>During the installation process, the VisualD installer will ask you if you want to integrate in Microsoft Visual Studio IDE the D language extension. <strong>Yes you want to.</strong> <br/> This will add a specific D menu into the Microsoft IDE (to access D specific function directly from the Visual Studio graphic user interface).
</li>
</ol>
<h2 id="4-set-up-the-dub-ldc-path-in-the-path-environment-variable"> <strong>4. Set up the DUB/LDC path in the</strong> <code class="prettyprint">PATH</code> <strong>environment variable</strong></h2>
<p>Normally, the Visual D installer should have already set up the <code class="prettyprint">PATH</code> environment variable, adding the path to <code class="prettyprint">ldc2.exe</code>:
</p>
<ol>
<li><p>You can check this by opening the environment variable setup in your system:
</p>
</li>
</ol>
<p><img src="assets/envvars.png" alt="">
</p>
<p><strong>If you have the LDC path in your PATH variable: nothing else to do!</strong>
</p>
<p>Otherwise, follow the instructions below:
</p>
<ol>
<li>If you are lazy, we advise you to go to the <a href="https://github.com/ldc-developers/ldc/releases">LDC official github repository</a> & download the latest LDC stable release (multilib version is highly recommended).
</li>
<li>Launch this executable (for instance LDC.1.29-multilib.exe)
</li>
<li>Follow the instructions.
</li>
<li>At the end of the process, the installer will ask you if you want to add the right LDC PATH automatically. Do so :-)
</li>
<li>You can do that everytime you want to update LDC.
</li>
</ol>
<p>If you don't want to do this (you are not lazy) :
</p>
<ol>
<li><p>Go the the Windows Configuration Panel, search for "environment variables" & add into the PATH the path to the LDC root folder:
</p>
</li>
</ol>
<p><img src="assets/ldc-path.png" alt="">
</p>
<p><strong>Here is a detailed guide to set your environment variables:</strong> <a href="https://www.computerhope.com/issues/ch000549.htm">https://www.computerhope.com/issues/ch000549.htm</a>
</p>
<p><em>Note: environment variables are inherited from parent process to child process. After modifying them, you will have to restart your IDE, or terminal window, in order for them to udpate.</em>
</p>
<h2 id="5-this-is-the-end"> <strong>5. This is the END...</strong></h2>
<p>Open a <code class="prettyprint">CMD.exe</code> and try <code class="prettyprint">dub --version</code>. You should get an answer from the system with a version number. You can now start writing D code & compile it!
</p>
<p>Some useful commands:
</p>
<ul>
<li><code class="prettyprint">dub -a x86</code> builds a 32-bit program using LDC
</li>
<li><code class="prettyprint">dub -a x86_64</code> builds a 64-bit program using LDC
</li>
<li><code class="prettyprint">dub -a x86 --compiler dmd</code> builds a 32-bit program using DMD
</li>
<li><code class="prettyprint">dub -a x86_64 --compiler dmd</code> builds a 64-bit program using DMD
</li>
<li><code class="prettyprint">dub generate visuald</code> generates a 64-bit LDC VisualD solution.
</li>
<li><code class="prettyprint">dmd --version</code> tells your DMD version.
</li>
<li><code class="prettyprint">ldc2 --version</code> tells your LDC version.
</li>
<li><code class="prettyprint">rdmd file.d</code> builds and run a single-file D program in <code class="prettyprint">file.d</code>.
</li>
</ul>
<p><em>Warning: both DMD and LDC comes with their own dub. The one that is used depends on who is first in the PATH envvar.</em>
</p>
<h2 id="an-issue-while-installing-d-language"> <strong>An issue while installing D language ?</strong></h2>
<p>In case you encounter an issue while installing the D programming language, do not hesitate to post your questions on the D.learn forum: https://forum.dlang.org/group/learn
</p>
</div><a name="DIID-#10---Colorize-console-output"></a><div class="idiom"><a class="permalink" href="#DIID-#10---Colorize-console-output">Link
</a><h1 id="diid-10-colorize-console-output"> DIID #10 - Colorize console output</h1>
<p><strong>Solution:</strong> Use the <code class="prettyprint">console-colors</code> <a href="https://code.dlang.org/packages/console-colors">package</a>.
</p>
<h2 id="dub-json"> <code class="prettyprint">dub.json</code></h2>
<pre class="prettyprint"><code>{
"name": "colorize-text-output",
"dependencies":
{
"console-colors": "~>1.0"
}
}
</code></pre><h2 id="source-main-d"> <code class="prettyprint">source/main.d</code></h2>
<pre class="prettyprint"><code>import consolecolors;
void main()
{
cwriteln("This is light blue on orange".lblue.on_orange);
cwritefln("This is a <red>%s</red>.", "nested <yellow>color</yellow> string");
}
</code></pre><p>Get <code class="prettyprint">console-colors</code> documentation <a href="https://github.com/p0nce/console-colors">here</a>.<br/>Get the source code for all DIID examples <a href="https://github.com/p0nce/DIID">here</a>.
</p>
</div><a name="DIID-#9---Parse-command-line-arguments"></a><div class="idiom"><a class="permalink" href="#DIID-#9---Parse-command-line-arguments">Link
</a><h1 id="diid-9-parse-command-line-arguments"> DIID #9 - Parse command-line arguments</h1>
<p><strong>Solution:</strong> Use <code class="prettyprint">std.getopt</code> from Phobos.
</p>
<h2 id="dub-json"> <code class="prettyprint">dub.json</code></h2>
<pre class="prettyprint"><code>{
"name": "cmdline-args",
"dependencies": {
}
}
</code></pre><h2 id="source-main-d"> <code class="prettyprint">source/main.d</code></h2>
<pre class="prettyprint"><code>import std.getopt;
int main(string[] args)
{
string data = null;
int length = 24;
bool verbose;
enum Color { no, yes }
Color color;
auto helpInformation = getopt(
args,
"length", &length, // numeric
"file", &data, // string
"verbose", &verbose, // flag
"color", "Information about this color", &color); // enum
// std.getopt always add an option for --help|-h
if (helpInformation.helpWanted || data is null)
{