d

Using D programming language in a .NET context

我的未来我决定 提交于 2019-11-28 13:19:48
I'm curious: has anyone used D together with .NET languages? Is that even possible? What kind of stuff is easier/makes sense to do in D that's hard to do in, say, C++/CLI? Using D together with .NET is very possible. The reason: .NET is able to import unmanaged C libraries (.dll's which export C functions) using the dllImport attribute. D is able to export C functions. using the export and extern (C) attributes So the considering the technicalities, it's completely possible. With regards to what D makes easier than C++, the answer is fairly easy: "Everything". In a sense, D is really just a

Logical const in D

半城伤御伤魂 提交于 2019-11-28 00:49:00
D has two types of constness: immutable variables are ones that were declared immutable, and always will be immutable, while const variables are simply read only versions of an object. Logical const is when a function is marked as const , but allows write access to one or more member variables. The typical use of this is for lazy evaluation, e.g. (in C++) struct Matrix { double determinant() const { if ( m_dirty ) { m_determinant = /* expensive calculation */; m_dirty = false; } return m_determinant; } void set(int i, int j, double x) { m_dirty = true; ...; } mutable bool m_dirty; mutable

Does D have something akin to C++0x's move semantics?

♀尐吖头ヾ 提交于 2019-11-27 21:08:18
问题 A problem of "value types" with external resources (like std::vector<T> or std::string ) is that copying them tends to be quite expensive, and copies are created implicitly in various contexts, so this tends to be a performance concern. C++0x's answer to this problem is move semantics , which is conceptionally based on the idea of resource pilfering and technically powered by rvalue references . Does D have anything similar to move semantics or rvalue references? 回答1: I believe that there are

Why 0.1 + 0.2 == 0.3 in D?

旧街凉风 提交于 2019-11-27 17:29:10
assert(0.1 + 0.2 != 0.3); // shall be true is my favorite check that a language uses native floating point arithmetic. C++ #include <cstdio> int main() { printf("%d\n", (0.1 + 0.2 != 0.3)); return 0; } Output: 1 http://ideone.com/ErBMd Python print(0.1 + 0.2 != 0.3) Output: True http://ideone.com/TuKsd Other examples Java: http://ideone.com/EPO6X C#: http://ideone.com/s14tV Why is this not true for D? As understand D uses native floating point numbers. Is this a bug? Do they use some specific number representation? Something else? Pretty confusing. D import std.stdio; void main() { writeln(0.1

D: finding all functions with certain attribute

∥☆過路亽.° 提交于 2019-11-27 14:42:02
问题 Is it currently possible to scan/query/iterate all functions (or classes) with some attribute across modules? For example: source/packageA/something.d: @sillyWalk(10) void doSomething() { } source/packageB/anotherThing.d: @sillyWalk(50) void anotherThing() { } source/main.d: void main() { for (func; /* All @sillWalk ... */) { ... } } 回答1: Believe it or not, but yes, it kinda is... though it is REALLY hacky and has a lot of holes. Code: http://arsdnet.net/d-walk/ Running that will print:

What are all the syntax problems introduced by the usage of angle brackets in C++ templates?

前提是你 提交于 2019-11-27 12:48:34
问题 In C++ templates are instantiated with angle brackets vector<int> and the Java and C# languages have adopted the same syntax for their generics. The creators of D, however, have been quite vocal about the problems that angle brackets bring and they made a new syntax foo!(int) — but I've never seen too many details about what problems angle brackets bring, exactly. One of them was when instantiating a template with another template vector<vector<int>> , which would cause some (older?)

Using D programming language in a .NET context

独自空忆成欢 提交于 2019-11-27 07:44:59
问题 I'm curious: has anyone used D together with .NET languages? Is that even possible? What kind of stuff is easier/makes sense to do in D that's hard to do in, say, C++/CLI? 回答1: Using D together with .NET is very possible. The reason: .NET is able to import unmanaged C libraries (.dll's which export C functions) using the dllImport attribute. D is able to export C functions. using the export and extern (C) attributes So the considering the technicalities, it's completely possible. With regards

Why allow concatenation of string literals?

那年仲夏 提交于 2019-11-27 05:34:33
I was recently bitten by a subtle bug. char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails If you have godlike code review powers you'll notice I forgot the , after "two" . After the considerable effort to find that bug I've got to ask why would anyone ever want this behavior? I can see how this might be useful for macro magic, but then why is this a "feature" in a modern language like python? Have you ever used string literal concatenation in production code?

Alloca implementation

限于喜欢 提交于 2019-11-27 01:57:22
How does one implement alloca() using inline x86 assembler in languages like D, C, and C++? I want to create a slightly modified version of it, but first I need to know how the standard version is implemented. Reading the disassembly from compilers doesn't help because they perform so many optimizations, and I just want the canonical form. Edit: I guess the hard part is that I want this to have normal function call syntax, i.e. using a naked function or something, make it look like the normal alloca(). Edit # 2: Ah, what the heck, you can assume that we're not omitting the frame pointer.

Logical const in D

南笙酒味 提交于 2019-11-26 21:47:22
问题 D has two types of constness: immutable variables are ones that were declared immutable, and always will be immutable, while const variables are simply read only versions of an object. Logical const is when a function is marked as const , but allows write access to one or more member variables. The typical use of this is for lazy evaluation, e.g. (in C++) struct Matrix { double determinant() const { if ( m_dirty ) { m_determinant = /* expensive calculation */; m_dirty = false; } return m