phobos

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

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

Using std.algorithm.map with member functions in D2

心不动则不痛 提交于 2019-12-22 10:11:15
问题 I have: Foo foo = new Foo(); foreach (i; 0..10) { Bar bar = foo.getBar(i); ... } I want to be able to instead say (equivalently): foreach (bar; foo.getAllBars()) { ... } How do I go about implementing getAllBars() ? I figured something like this: class Foo { auto getAllBars() { return map!(getBar)(iota(10)); } } But you can't do that of course because getBar depends on the this parameter, which will go out of scope. The same applies if you try to create a local function or delegate . I also

Does the D language have multiple standard libraries and issues with GC?

半城伤御伤魂 提交于 2019-12-20 09:56:15
问题 I'm wondering how mature and stable D is, and if it might be a good replacement for C/C++. I know that there are currently two standard libraries (Phobos and Tango). Is it still the case that there is no unified standard library? Additionally I heard some time ago that the languages has problems on the boundaries of GCed/non-GCed code. I couldn't find any reference about that on the D website, so is this problem still true? 回答1: Version 1 of D is mature and stable, and there are definitely

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

Does the D language have multiple standard libraries and issues with GC?

隐身守侯 提交于 2019-12-02 20:00:24
I'm wondering how mature and stable D is, and if it might be a good replacement for C/C++. I know that there are currently two standard libraries (Phobos and Tango). Is it still the case that there is no unified standard library? Additionally I heard some time ago that the languages has problems on the boundaries of GCed/non-GCed code. I couldn't find any reference about that on the D website, so is this problem still true? Version 1 of D is mature and stable, and there are definitely folks who use it for real work. Phobos is the only standard library that D has ever had or likely ever will

std.algorithm.joiner(string[],string) - why result elements are dchar and not char?

好久不见. 提交于 2019-12-01 16:43:32
问题 I try to compile following code: import std.algorithm; void main() { string[] x = ["ab", "cd", "ef"]; // 'string' is same as 'immutable(char)[]' string space = " "; char z = joiner( x, space ).front(); // error } Compilation with dmd ends with error: test.d(8): Error: cannot implicitly convert expression (joiner(x,space).front()) of type dchar to char Changing char z to dchar z does fix the error message, but I'm interested why it appears in the first place. Why result of joiner(string[]

How to get single keystroke in D2 (Phobos)?

徘徊边缘 提交于 2019-12-01 00:35:15
问题 Is there a simple, cross-platform way to get a single keystroke in D2 using Phobos? For instance, a "Press any key to continue..." prompt, or a Brainfuck interpreter. All the methods I've tried require an Enter keypress before passing the input (getchar(), for instance). 回答1: I've done some research on the matter, and I've found that, while the Phobos library under D 1.0 had exactly what you need in the form of std.c.stdio.getch() , D 2.0 lacks this function. None of the other standard input