d

Open a File in D

Deadly 提交于 2019-12-11 01:45:39
问题 If I want to safely try to open a file in D, is the preferred way to either try to open it, catch exception (and optionally figure out why) if it fails or check if it exists, is readable and only then open it I'm guessing the second alternative results in more IO and is more complex right? 回答1: Generally, it's better to check whether the file exists first, because it's often very likely that the file doesn't exist, and simply letting it fail when you try and open it is a case of using

How to load files to local file system with vibed?

别说谁变了你拦得住时间么 提交于 2019-12-11 00:32:59
问题 I need to send data from web-browser to local FS. For sending data I am using Vue-JS component <file-upload class="my-file-uploader" name="myFile" id="myCustomId" action="/upload" multiple>Inside Slot Text</file-upload> My server side based on vibed. But I can't find example how to save binary data to local FS. router.any("/upload", &upload); ... void upload(HTTPServerRequest req, HTTPServerResponse res) { } It's seems that I should use HTTPServerRequest.files But I can't understand how to

Namespaces with classes and structs?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 00:29:08
问题 Will be nice if I got 'nested members' in D language, so I have the inglorious idea to code class Keyboard { struct Unused { string key1 = "Wake Up"; string key2 = "Sleep"; string key3 = "Power"; } Unused unused; } int main() { Keyboard kb; kb.unused.key1 = "Scroll Lock"; return 0; } Okay, it's a bad example that segfault too. But I'm learning object-oriented programming and don't know if it's a good thing to do, or how to do. 回答1: There's nothing wrong with doing that per se , the problem

Updated GUI libraries for D in 2013?

你离开我真会死。 提交于 2019-12-10 22:01:40
问题 I'm developing a game in D. So far I really appreciate the D language, and for the most libraries there are good bindings. Now, for the editor I'm in search for a portable GUI library. wxD or DWT seemed like good options, but they seem abandoned, as the latest updates date from years ago. Also on the forum is not much life left. Are there any frequently updated mature GUI libraries out there? Is D even worth going on with? Which language besides D is good for games? Thanks in advance! 回答1: If

Interface and template functions

流过昼夜 提交于 2019-12-10 20:40:33
问题 I'm trying to have interface over two different classes where implementation of a function is in the subclass. It works for regular functions, but unfortunately not for template functions. See example: import std.conv; import std.stdio; interface Num { T num(T)(); } class A : Num { T num(T)() { return 5.to!T; } } class B : Num { T num(T)() { return 2.to!T; } } void main() { auto a = new A(); auto b = new B(); Num somea = a; Num someb = b; writeln(a.num!int()); writeln(somea.num!int());

Using OpenGL 3.2 with Derelict3 and GLFW 3 on OSX Lion

£可爱£侵袭症+ 提交于 2019-12-10 19:23:45
问题 I'm having trouble getting OpenGL 3.2 to run on Lion (osx 10.7.4) using Derelict3 and GLFW 3. Here's my test program: module glfw3Test; import std.stdio, std.conv; import derelict.glfw3.glfw3; import derelict.opengl3.gl3; string programName = "glfw3Test"; int width = 640; int height = 480; GLFWwindow window; void main() { // load opengl DerelictGL3.load(); // load GLFW DerelictGLFW3.load(); if(!glfwInit()) { glfwTerminate(); throw new Exception("Failed to create glcontext"); } writefln("GLFW:

D concurrent writing to buffer

余生颓废 提交于 2019-12-10 19:05:16
问题 Say you have a buffer of size N which must be set to definite values (say to zero, or something else). This value setting in the buffer is divided over M threads, each handling N / M elements of the buffer. The buffer cannot be immutable , since we change the values. Message passing won't work either, since it is forbidden to pass ref or array (= pointer) types. So it must happen through shared ? No, since in my case the buffer elements are of type creal and thus arithmetics are not atomic.

Lazily Reading a File in D

拈花ヽ惹草 提交于 2019-12-10 18:03:29
问题 I'm writing a directory tree scanning function in D that tries to combine tools such as grep and file and conditionally grep for things in a file only if it's not matching a set of magic bytes indicating filetypes such as ELF, images, etc. What is the best approach to making such an exclusion logic run as fast as possible with regards to minimizing file io? I typically don't want to read in the whole file if I only need to read some magic bytes in the beginning. However to make the code more

How do I get gdb working with D programs under linux?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 17:17:13
问题 I have a patched gdb 6.8, but I can't get any debugging to work. Given this test file: import std.stdio; void main() { float f = 3.0; int i = 1; writeln(f, " ", i); f += cast(float)(i / 10.0); writeln(f, " ", i); i++; f += cast(float)(i / 10.0); writeln(f, " ", i); i += 2; f += cast(float)(i / 5.0); writeln(f, " ", i); } And attempting to debug on the command line: bash-4.0 [d]$ dmd -g test.d # '-gc' shows the same behaviour. bash-4.0 [d]$ ~/src/gdb-6.8/gdb/gdb test GNU gdb 6.8 Copyright (C)

Cannot Slice Take!R from std.range in D?

痴心易碎 提交于 2019-12-10 15:36:12
问题 I'm trying to use the slice operator to obtain a slice of the return value of the take function from std.range. My code: auto tempChunk = ['a', 'b', 'c', 'd']; auto a = tempChunk.take(3); writeln(a[0..2]); As Take!R in this case is just an alias for char[], I'd expect this to compile. However, the compiler tells me that Take!(char[]) cannot be sliced with [] . Taking another example: int[] arr1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; auto s = arr.take(5); writeln(s[0..4]); This will compile and