Questions tagged [phobos]

Phobos is the official runtime and standard library of the D programming language.

97 questions
6
votes
1 answer

Can I functionally concatenate a number and string?

I am trying to make a pure function that embeds a number in a string. The obvious concatenation methods do not work: pure string foo(immutable int bar) { return "Number: " ~ bar; // Error: strings and ints are incompatible. return "Number:…
Maxpm
  • 24,113
  • 33
  • 111
  • 170
6
votes
4 answers

Simple Set implementation in D?

I was fishing around in D's standard library looking for a Set implementation, and I only found these: BinaryHeap RedBlackTree These both would work fine, if I could only figure out how to use them. I started with the RedBlackTree (because I'm…
beatgammit
  • 19,817
  • 19
  • 86
  • 129
6
votes
3 answers

Stack-based object instantiation in D

I'm learning D, and am confused by an error I'm getting. Consider the following: module helloworld; import std.stdio; import std.perf; ptrdiff_t main( string[] args ) { auto t = new PerformanceCounter; //From managed heap …
anoncow
  • 73
  • 4
6
votes
2 answers

D/Phobos Style guide

I've just begun looking at the phobos source, and it's littered with several different styles and commented out code. The style guide on the web side is very small, and I only found broken links from 2006 and another one from 2004... Is there a…
simendsjo
  • 4,739
  • 2
  • 25
  • 53
6
votes
2 answers

Byte InputRange from file

How to construct easily a raw byte-by-byte InputRange/ForwardRange/RandomAccessRange from a file?
Tamas
  • 3,254
  • 4
  • 29
  • 51
6
votes
1 answer

Representing optional values in D

I'm about to write a parser to read a text file line by line into structs of different types and giving these structs to a callback (observer or visitor - not sure yet). The text file contains MT-940 data - a SWIFT bank statement. These lines…
duselbaer
  • 935
  • 2
  • 6
  • 10
5
votes
1 answer

How interface this C code to D?

How should this C be convert to D : typedef const gchar* (*GModuleCheckInit) (GModule *module); typedef void (*GModuleUnload) (GModule *module); Is this correct ? alias const gchar* function( GModule *module ) GModuleCheckInit; alias void function(…
bioinfornatics
  • 1,749
  • 3
  • 17
  • 36
5
votes
1 answer

D etc.c.curl examples

D, being the lesser known language of the bunch, has very little going for it in the way of libraries. I am trying to download a file, and the way I can see to do that with DMD 2 and phobos is with etc.c.curl, but... Curl is very difficult to use.…
alexmherrmann
  • 1,055
  • 2
  • 9
  • 17
5
votes
2 answers

Do Phobos (and/or Tango) have a set of predefined exception types?

The D documentation seems to be a bit messy, and I'm not able to find this information anywhere on the official site. I'm needing some common exception types (e.g. NotFiniteNumberException, FileIOException, types like that), do these exist in the…
Mark LeMoine
  • 4,478
  • 3
  • 31
  • 52
5
votes
1 answer

compilation issue with split/splitter

Here's simple code: import std.algorithm; import std.array; import std.file; void main(string[] args) { auto t = args[1].readText() .splitter('\n') .split("---") ; } Looks like it should work, but it won't compile. DMD…
sigod
  • 3,514
  • 2
  • 21
  • 44
5
votes
1 answer

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

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…
Meta
  • 1,091
  • 6
  • 14
4
votes
2 answers

Checking in D if a string is in array?

How do I check for a string occurance in an array? I mean sure I can loop, but is there a standard function? at first I did: if(str in ["first", "second", "third"]) but it complained that in only works with associative arrays. I tried to quickly…
hasen
  • 161,647
  • 65
  • 194
  • 231
4
votes
3 answers

Remove white space characters from a char[] array in D

What is the recomended way to remove white space from a char[] in D. for example using dmd 2.057 I have, import std.stdio; import std.string; import std.algorithm; char[] line; int main(){ line = r"this is a line with spaces "; line =…
eastafri
  • 2,186
  • 2
  • 23
  • 34
4
votes
2 answers

What's the proper usage of approxEqual()?

At first I thought I could rely on the maximum relative difference only, but I was wrong. For example, if a = 0.0, and b = 0.5, their relative difference is 1.0. In this case approxEquals(lhs, rhs, maxRelDiff, maxAbsDiff) relies on the maximum…
Arlen
  • 6,641
  • 4
  • 29
  • 61
4
votes
2 answers

What's the status of phobos' std.xml

I'm working on the beginnings of porting my php based OOP web framework to the d language and I'm having some trouble figuring out if it is safe to rely on phobos' std.xml classes to read xml from files and/or streams. There seems to be quite a bit…
Kris
  • 40,604
  • 9
  • 72
  • 101