d

Pimpl-idiom in the D programming language

眉间皱痕 提交于 2019-12-22 09:19:39
问题 D has a fantastic module system which reduces compilation times dramatically compared to C++. According to the documentation D still provides opaque structs and unions in order to enable the pimpl idiom. My question is: How can I declare a nested struct (or union) in one module and define it in another one? What is the syntax for that? In C++ the header would look like this struct S { ... struct Impl; Impl * p; }; and the implementation file (cpp-file) would use some interesting-looking ::

Is it possible to compile unittest without running them and explicitly run unittest for a specific module?

[亡魂溺海] 提交于 2019-12-22 08:35:53
问题 I often wrote my test code in the main function while developing an API but because D has integrated unittest I want to start using them. My current work flow is the following, I have a script that watches for file changes in any .d files, if the scripts finds a modified file it will run dub build The problem is that dub build doesn't seem to build the unittest module foo struct Bar{..} unittest{ ... // some syntax error here ... } It only compiles the unittests if I explicitly run dub test .

Fast vector struct that allows [i] and .xyz-operations in D?

久未见 提交于 2019-12-22 06:46:37
问题 I'd like to create a vector struct in D that works like this: vec u, v; vec w = [2,6,8]; v.x = 9; // Sets x v[1] = w.y; // Sets y u = v; // Should copy data Later I'd also like to add stuff like u = v * u etc. But the above will do for now. This is how far I've come: struct vec3f { float[3] data; alias data this; @property { float x(float f) { return data[0] = f; } float y(float f) { return data[1] = f; } float z(float f) { return data[2] = f; } float x() { return data[0]; } float y() {

D language: initializing dynamic multidimensional array best practices?

坚强是说给别人听的谎言 提交于 2019-12-22 04:20:35
问题 Just curious if this is the best practice for initializing a dynamic, multidimensional array in D. There is a section on arrays in their language reference, but I'm not quite sure if it goes over what I'm trying to accomplish. class Map { Tile[][] tiles; this(uint width, uint height) { tiles.length = height; foreach (ref tilerow; tiles) tilerow.length = width; } } Map map1 = new Map(5000, 3000); // values determined at runtime (or an equivalent alternative like a typical for (y=0;y<height;y++

ncurses api with the D Programming Language

≯℡__Kan透↙ 提交于 2019-12-22 03:55:46
问题 I am trying to teach myself AI using neural networks. Long story short, I wanted to create a simple graphic that would display what is happening in my program using ncurses. The tutorial that I am using is found here. I was under the impression that D was compatible with C and I could theoretically call C functions relatively easily. I find that not to be the case. I am a relatively novice programmer, so even the simplistic explanations are a little above my head. I found this here. D is

Using D, how would I listen to incoming HTTP requests and respond to them?

吃可爱长大的小学妹 提交于 2019-12-21 04:29:25
问题 Using D, how would I listen to incoming HTTP traffic and respond to it? For example (in pseudocode): socket = new socket("locahost", 80) socket.onRequestRecevied(handleRequest); function response handleRequest(request) { //do something with the request and respond request.respond("hello world") } I know there is a lot more to it than that, but I haven't been able to find many resources on responding to incoming http request. EDIT: My current attempts have yielded only exceptions like "Unable

How to compile D application without the D runtime?

早过忘川 提交于 2019-12-20 23:22:18
问题 Iv been trying to figure this one out forever, and its starting to annoy me. I understand the D runtime library. What it is, what it does. I also understand that you can compile a D app without it. Like what XoMB does. Well, XoMB defines its own runtime, but there are cases where you dont need to write your own, if you dont need it. I understand that the DigitalMars D compiler (dmd) which is what im using, does alot of things behind the scenes for the runtime, like emiting references to

Getting Embedded with D (the programming language)

别来无恙 提交于 2019-12-20 16:59:50
问题 I like a lot of what I've read about D. Unified Documentation (That would make my job a lot easier.) Testing capability built in to the language. Debug code support in the language. Forward Declarations. (I always thought it was stupid to declare the same function twice.) Built in features to replace the Preprocessor. Modules Typedef used for proper type checking instead of aliasing. Nested functions. ( Cough PASCAL Cough ) In and Out Parameters. (How obvious is that!) Supports low level

Getting Embedded with D (the programming language)

我的未来我决定 提交于 2019-12-20 16:57:45
问题 I like a lot of what I've read about D. Unified Documentation (That would make my job a lot easier.) Testing capability built in to the language. Debug code support in the language. Forward Declarations. (I always thought it was stupid to declare the same function twice.) Built in features to replace the Preprocessor. Modules Typedef used for proper type checking instead of aliasing. Nested functions. ( Cough PASCAL Cough ) In and Out Parameters. (How obvious is that!) Supports low level

How to create/write a simple XML parser from scratch?

余生颓废 提交于 2019-12-20 10:37:09
问题 How to create/write a simple XML parser from scratch? Rather than code samples, I want to know what are the simplified, basic steps in English. How is a good parser designed? I understand that regex should not be used in a parser, but how much is regex's role in parsing XML? What is the recommended data structure to use? Should I use linked lists to store and retrieve nodes, attributes, and values? I want to learn how to create an XML parser so that I can write one in D programming language.