d

How to make a system call and read the stdout, in D?

左心房为你撑大大i 提交于 2020-01-03 08:36:09
问题 I thought to try using D for some system administration scripts which require high performance (for comparing performance with python/perl etc). I can't find an example in the tutorials I looked through so far (dsource.org etc.) on how to make a system call (i.e. calling another software) and receiving it's output from stdout, though? If I missed it, could someone point me to the right docs/tutorial, or provide with the answer right away? 回答1: Well, then I of course found it: http://www

Why use static if in D?

淺唱寂寞╮ 提交于 2020-01-03 08:22:11
问题 I have been reading about the template system in the D language and came upon a unusual construct, static if . From what I managed to grasp it is evaluated at compile time, but from what I have searched, the example shown here did not quite enlighten me. template Factorial(ulong n) { static if(n < 2) const Factorial = 1; else const Factorial = n * Factorial!(n - 1); } What does static if do, and when should I use it? 回答1: the D static if is the base for "conditional compilation", and plays an

Obtaining a plain char* from a string in D?

老子叫甜甜 提交于 2020-01-03 08:00:35
问题 I'm having an absolute hell of a time trying to figure out how to get a plain, mutable C string (a char*) from a D string (a immutable(char)[]) to that I can pass the character data to legacy C code. toStringz doesn't work, as I get an error saying that I "cannot implicitly convert expression (toStringz(this.fileName())) of type immutable(char)* to char*". Do I need to recreate a new, mutable array of char and copy the characters over? 回答1: If you can change the header of the D interface of

Parallel Iterators in the D language

删除回忆录丶 提交于 2020-01-02 11:44:54
问题 I am trying to implement a graph data structure in the D language which supports parallel iteration over the node and edge sets. alias ulong index; alias index node; alias ulong count; class Graph { index z; // max node index count n; // number of nodes count m; // number of edges node[][] adja; // adjacency list count[] deg; // node degree this(count n = 0) { this.z = n; this.n = n; this.m = 0; this.adja = new node[][](this.z, 0); this.deg = new count[](this.z); } Here's a sequential node

Parallel Iterators in the D language

只谈情不闲聊 提交于 2020-01-02 11:43:28
问题 I am trying to implement a graph data structure in the D language which supports parallel iteration over the node and edge sets. alias ulong index; alias index node; alias ulong count; class Graph { index z; // max node index count n; // number of nodes count m; // number of edges node[][] adja; // adjacency list count[] deg; // node degree this(count n = 0) { this.z = n; this.n = n; this.m = 0; this.adja = new node[][](this.z, 0); this.deg = new count[](this.z); } Here's a sequential node

Right way to do “const pointer to non-const” in D?

半世苍凉 提交于 2020-01-02 06:33:47
问题 Ok, according to http://dlang.org/const-faq.html#head-const there is no way to have a const pointer to non-const in D. But there is a good practice: declare a field in a class const and compiler let you know if you forget to initialize it. Is there any way to protect myself from forgetting to init pointer field of a class in D? 回答1: Yes: void main() { // ConstPointerToNonConst!(int) a; // ./b.d(4): Error: variable b.main.a default construction is disabled for type ConstPointerToNonConst!int

Right way to do “const pointer to non-const” in D?

泪湿孤枕 提交于 2020-01-02 06:33:33
问题 Ok, according to http://dlang.org/const-faq.html#head-const there is no way to have a const pointer to non-const in D. But there is a good practice: declare a field in a class const and compiler let you know if you forget to initialize it. Is there any way to protect myself from forgetting to init pointer field of a class in D? 回答1: Yes: void main() { // ConstPointerToNonConst!(int) a; // ./b.d(4): Error: variable b.main.a default construction is disabled for type ConstPointerToNonConst!int

Statically linking SQLite with DMD (Windows x86)

笑着哭i 提交于 2020-01-01 10:28:09
问题 I've tried to statically link with sqlite3 without success. I'm using the 'etc.c.sqlite3' header, and the sqlite3 amalgamation. To create the .lib file I've tried both VC++ and MinGW-gcc, both of these compile the source file successfully - but they both generate COFF object format (optlink, which DMD uses, works with OMF). After reading tons of posts on 'digitalmars.D', I've tried several different solutions. objconv: tried to convert lib file created with GCC, resulted in undefined symbols

What is a “yield return” equivalent in the D programming language?

佐手、 提交于 2019-12-31 09:11:09
问题 Here is a simple generator in C#. IEnumerable<int> Foo() { int a = 1, b = 1; while(true) { yield return b; int temp = a + b; a = b; b = temp; } } How do I write a similar generator in Digital Mars D? (The question is about the yield return statement) Thanks! Update. That's interesting. Since I'm just generating a mathematical sequence, using recurrence may be a good option. auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1); foreach (e; take(fib, 10)) // <- prints first ten numbers from the

DMD vs. GDC vs. LDC

纵饮孤独 提交于 2019-12-31 08:33:09
问题 What are the Pros/Cons of the different D Compilers? How is the performance and the standard compliance/D2 support? How well are debuggers supported? How good are the Error messages and is the IDE integration? How good is the 64 bit support? My thought so far: DMD Mature and well maintained Only one platform, 64 bit support is not good Not FOSS GDC Supports various platforms Has very mature optimizations, so it's fast? Out of date runtime? GCC so a good debugger support? LDC Supports various