d

Return value of std.regex.regex?

这一生的挚爱 提交于 2019-12-23 21:45:53
问题 I'm trying to write a function that takes an input string, a regex (made by std.regex.regex from a rawstring) and an error message string, and attempt to match something from the input string using the regex, displaying the error message if there are no matches. I came up with the following signature so far: string check_for_match (string input, Regex r, string error_message) However, this doesn't seem to work, as the compiler complains, saying: struct std.regex.Regex(Char) is used as a type

const immutable BigInt and range.join in D

时光总嘲笑我的痴心妄想 提交于 2019-12-23 21:23:13
问题 I'm learning D and I have been playing with more and more functions and tools defined in phobos. I came across two functions that don't work when the parameters are const or immutable. BigInt i = "42", j = "42"; writeln(i + j); // This works, except when I add a const/immutable qualifier to i and j // When const: main.d(23): Error: incompatible types for ((i) + (j)): 'const(BigInt)' and 'const(BigInt)' // When immutable: main.d(23): Error: incompatible types for ((i) + (j)): 'immutable(BigInt

how to decode ubyte[] to a specified encoding?

谁说我不能喝 提交于 2019-12-23 20:03:08
问题 The problem is : how to parse a file when encoding is set at runtime? encoding could be: utf-8 , utf-16 , latin1 or other The goal it is to convert ubyte[] to a string from the selected encoding. Because when you use std.stdio.File.byChunk or std.mmFile.MmFile you have ubyte[] as data. 回答1: Are you trying to convert text file to utf-8? If answer is 'yes', Phobos have function specialy for this: @trusted string toUTF8(in char[] s) . See http://dlang.org/phobos/std_utf.html for details. Sorry

Gtk/GtkD Detect release of mouse button on window resize?

微笑、不失礼 提交于 2019-12-23 18:48:38
问题 I'm trying to improve a plotting library that I wrote with GtkD (the D bindings for Gtk). Scatter plots with a lot of points take a long time to resize. I want to rescale the image, allowing pixelation, while the user is dragging the window edge to resize, and only re-render it when the mouse button is released. Is there an API to detect whether the user is still holding down the mouse button to drag the window edge when a window is being resized? If you are not familiar with GtkD, a response

FIFO /Named Pipes in D?

ⅰ亾dé卋堺 提交于 2019-12-23 16:26:50
问题 I am trying to do the following : A central application, let us call it alpha, accepts user inputs in command lines, and based on those inputs, spawns other processes, call them bravo, charlie, etc. I want the parent and child to communicate both way. That is, alpha can read from and write to bravo (resp. charlie) and vice-versa In C++, i can use fork() then exec(), and use FIFO-s - some excellent tutorials, are here : Pipe, Fork, and Exec - Two Way Communication Between Parent and Child

Using a foreach loop — variable cannot be read

我怕爱的太早我们不能终老 提交于 2019-12-23 16:06:23
问题 Should be rather simple but it's not. Here's my code : string cases() { string ret = ""; string[] methods; methods = [__traits(derivedMembers,mixin("Math"))]; foreach (string s; methods) ret ~= "case \"" ~ s ~ "\": return Math."~s~"(params);"; methods = [__traits(derivedMembers,mixin("OtherClass"))]; foreach (string s; methods) ret ~= "case \"" ~ s ~ "\": return OtherClass."~s~"(params);"; return ret; } string execute(string what, string[] params) { switch (what) { mixin(cases()); default:

Making a heap copy of a struct in D

我们两清 提交于 2019-12-23 15:37:11
问题 How can I create a garbage-collected copy of a struct that's on the stack? Coming from a C++ background, my first guess would be a copy constructor like the one below, but it doesn't seem very idiomatic for D, and I haven't seen one in any of the D projects I've taken a look at. struct Foo { immutable int bar; this(int b) { bar = b; } // A C++-style copy constructor works but doesn't seem idiomatic. this(ref const Foo f) { bar = f.bar; } } void main() { // We initialize a Foo on the stack

Is there a HTML parsing for D?

柔情痞子 提交于 2019-12-23 13:08:55
问题 I'm looking for a HTML parsing for D language(that supports XPath, if possible). I did some googling, but no luck (hard find solutions with "D" keyword; it's like C, I say "C", google say C# .). On http://www.dsource.org and https://stackoverflow.com/questions/tagged/html-parsing+d there is no too. Note: I want not to mix C++ and D code. I am seeking solutions either in C or in libxml2. 回答1: Check out Adam Ruppe's dom.d: https://github.com/adamdruppe/misc-stuff-including-D-programming

Listing a class's methods trough mixin

半世苍凉 提交于 2019-12-23 12:24:13
问题 I want to list methods of a class in a mixin. To do it I assume I have to open the file containing the source code in the mixin, but finding that file's name is harder than I thought. I tried using __FILE__ but it gives the mixin declaration's file... so I would have to define the mixin in every file... which doesn't make any sense since the goal is to reduce boilerplate code. For now my solution is to pass the filename as an argument inside the class's constructor and call the mixin from

Struct composition with mixin and templates

别说谁变了你拦得住时间么 提交于 2019-12-23 12:16:05
问题 I can compose an AB struct that has all the members of structs A and B : template AFields() {int a;} struct A { mixin AFields; } template BFields() {int b;} struct B { mixin BFields; } struct AB { mixin AFields; mixin BFields; } A a; a.a = 1; B b; b.b = 2; AB ab; ab.a = 3; ab.b = 4; But how can I construct AB , if I don't have control over A and B and I don't have AFields and BFields ? I.e. how to write the CatStruct template so the code below compiles? struct A { int a; } struct B { int b; }