D, the Best Programming Language, for Former Python Developers by Victor Porton 2020

D, the Best Programming Language, for Former Python Developers by Victor Porton 2020

Author:Victor Porton, 2020
Language: eng
Format: epub
Published: 2020-12-31T09:37:35+00:00


Kind of templates. Eponymous templates

Almost any kind of an identifier can be a template:

enum e(int x) = x + 1; // enum template alias e(T) = T[]; // alias template void f(T)() { } // function template this(T)() { } // constructor template struct S(T) { } // struct template class S(T) { } // class template

There are no module templates and no variable templates.

There is also the keyword template specially to group several identifiers together in one template:

template GroupOfIdentifiers(T, T zero) { alias Matrix = T[3][3]; enum zeroMatrix = [ [zero, zero, zero], [zero, zero, zero], [zero, zero, zero] ]; Matrix invert(Matrix a) { return …; } } enum GroupOfIdentifiers!(double, 0.0).Matrix m = [ … ]; // … immutable inv = GroupOfIdentifiers!(double, 0.0).invert(m); // or for brevity: alias matrices = GroupOfIdentifiers!(double, 0.0); enum matrices.Matrix m2 = [ … ]; // … immutable inv2 = matrices.invert(m2);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.