d

How to create a Dynamic Library in D?

被刻印的时光 ゝ 提交于 2019-12-04 06:00:54
I want to create a Dynamic library (cross-platform) in D, so I did some Googling. After some time I found this page. I am absolutely stunned by how much complexities there are in writing, compiling and even linking to a DLL. Isn't there a uniform way of creating a shared library like you would in C? (just leave out the main function and pass some flags to the linker) Well, I decided to spend some time today messing with this and I kinda sorta have something that works, at least if the main program is also written in D (on Linux, I think it will work from C too on Windows. The reason is I didn

Is there a Future/Promise equivalent of C++ in D?

爱⌒轻易说出口 提交于 2019-12-04 05:29:33
问题 Does there exist a future/promise equivalent from the C++ world in the D world? Sure there is std.parallelism but it's doesn't have exactly the functionality of the promise/future combination (there is no equivalent to get the future or the set the result or the exception, you can't also wait for completion). 回答1: I believe you did not seriously look at std.parallelism ... Equivalent to "get the future" (if by that you mean the std::future 's get() method) are yieldForce(), spinForce() and

enum vs immutable in D

谁都会走 提交于 2019-12-04 01:45:49
What's the difference between enum i = 2; enum s = "Hello"; and immutable i = 2; immutable s = "Hello"; in D 2.0? stephan An enum is a user-defined type, not a variable. enum e = 2; is a short-hand for something like this enum : int { e = 2 } (i.e. an anonymous enum with one member e ), see the documentation . By definition, all members of an anonymous enum are placed into the current scope. So, e is a type member placed into the current scope, where it behaves like a literal . immutable i = 2; on the other hand actually creates a variable i of type int. This difference has a couple of

Are there any C++ language obstacles that prevent adopting D ranges?

天涯浪子 提交于 2019-12-04 00:32:28
This is a C++ / D cross-over question. The D programming language has ranges that -in contrast to C++ libraries such as Boost.Range - are not based on iterator pairs. The official C++ Ranges Study Group seems to have been bogged down in nailing a technical specification. Question : does the current C++11 or the upcoming C++14 Standard have any obstacles that prevent adopting D ranges -as well as a suitably rangefied version of <algorithm> - wholesale? I don't know D or its ranges well enough, but they seem lazy and composable as well as capable of providing a superset of the STL's algorithms.

CMake or Waf for D project

♀尐吖头ヾ 提交于 2019-12-04 00:08:46
We are looking for adequate build tool for a desktop GUI application to be written in D (using Qt toolkit), consisting of several native libraries, using 3rd party C-lib(s). It has to build on Linux (native development) and Mac as well on Windows. We might adopt Code::Blocks as IDE. Waf already has support for D language, while CMake is just receiving it cmaked2 . CMake uses special language, while Waf is pure Python...Otoh, CMake, via CPack, can produce packages in several formats as well as GUI installer for e.g. Windoze. Any pro/cons and what would you use? We excluded Scons for speed

ptrdiff_t too small?

回眸只為那壹抹淺笑 提交于 2019-12-03 15:33:54
问题 I've always wondered: isn't ptrdiff_t supposed to be able to hold the difference of any two pointers by definition ? How come it fails when the two pointers are too far? (I'm not pointing at any particular language... I'm referring to all languages which have this type.) (e.g. subtract the pointer with address 1 from the byte pointer with address 0xFFFFFFFF when you have 32-bit pointers, and it overflows the sign bit...) 回答1: No, it is not. $5.7 [expr.add] (from n3225 - C++0x FCD) When two

Can traits in D be used for type classes?

邮差的信 提交于 2019-12-03 15:18:15
问题 I'm new to D, and I'm looking for a good way to program with Haskell-like type classes e.g. Functors, Monoids, etc. in D. Is something like this implemented in Tango or Phobos? I've heard about traits which enable compile-time type checking for certain properties. Can they be used for type classes? I've tried a little bit with template specialization and come up with this: // Monoid.d // generic Monoid gets called when there is no instance of Monoid for Type T class Monoid(T) { pragma(msg,

Elegant operator overloading in D

点点圈 提交于 2019-12-03 15:09:39
问题 For a while I was confused about the direction of D's operator overloading, but now I realize it's a beautiful system... if It would only work with core types (int, float, etc). Consider the follow code: struct Vector { float X, Y; void opOpAssign(string op)(Vector vector) { X.opOpAssign!op(vector.X); // ERROR: no property "opOpAssign" for float Y.opOpAssign!op(vector.Y); // ERROR: ditto } } This would be beautiful code if it worked, seeing as it overloads all +=, -=, *=, etc.. operators in

Platform independent file locking?

三世轮回 提交于 2019-12-03 14:37:04
I'm running a very computationally intensive scientific job that spits out results every now and then. The job is basically to just simulate the same thing a whole bunch of times, so it's divided among several computers, which use different OSes. I'd like to direct the output from all these instances to the same file, since all the computers can see the same filesystem via NFS/Samba. Here are the constraints: Must allow safe concurrent appends. Must block if some other instance on another computer is currently appending to the file. Performance does not count. I/O for each instance is only a

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

落爺英雄遲暮 提交于 2019-12-03 14:05:40
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 to create socket: Operation not permitted." which may mean I'm doing it correctly but am simply