Questions tagged [phobos]

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

97 questions
3
votes
1 answer

Using std.algorithm.map with member functions in D2

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…
Peter Alexander
  • 53,344
  • 14
  • 119
  • 168
3
votes
1 answer

Why does Nullable!(Nullable!int) refuse to compile?

The following code refuses to compile: Nullable!(Nullable!int) nni = Nullable!(Nullable!int)(10); With this error message: Error: inout method nullable.Nullable!(Nullable!(immutable(int))).Nullable.this is not callable using a mutable object Why?
Meta
  • 1,091
  • 6
  • 14
3
votes
2 answers

Where is Date roll is useful?

I am reading Phobos docs. Sometimes I can't understand the logic of some methods. Date roll Adds the given number of years or months to this Date. A negative number will subtract. The difference between rolling and adding is that rolling does not…
Suliman
  • 1,469
  • 3
  • 13
  • 19
3
votes
1 answer

Reading a single character from stdin in D

The documentation for std.stdio does not list a read function which could be used to get a single character from standard input, only readln to get a line. std.file has read function, but it needs a file name, which is not available for the standard…
Chloride Cull
  • 741
  • 1
  • 7
  • 16
3
votes
1 answer

D: Cannot seem to create an std.container.Array of const struct pointers

Suppose I have a struct type Foo. I'm trying to create an std.container.Array of const pointers to Foo. I tried the obvious first: import std.container; alias FooArray = Array!(const(Foo*)); However, this causes a compiler error. Then I tried it…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
3
votes
1 answer

Return value of std.regex.regex?

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…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
3
votes
1 answer

D parallel loop

First, how D create parallel foreach (underlying logic)? int main(string[] args) { int[] arr; arr.length = 100000000; /* Why it is working?, it's simple foreach which working with reference to int from arr, parallel function…
dev1223
  • 1,148
  • 13
  • 28
3
votes
0 answers

Reflections on Serialization APIs in D

In the road to develop a new kind of search engine that caches types, statistics, etc about files and directories I'm currently trying to implement persistent caching of my internal directory tree using msgpack-d: Why doesn't msgpack-d and, from…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
3
votes
2 answers

Check if string starts with a substring in D / phobos?

I haven't so far found how I can most easily check if a string starts with a certain character in D. I want something like: if (my_str.startswith("/")) { // Do something } The closest I found was "chompPrefix" (here), but that is not really…
Samuel Lampa
  • 4,336
  • 5
  • 42
  • 63
3
votes
1 answer

Using std.range.Lockstep as an input range

Duplicating http://forum.dlang.org/thread/arlokcqodltcazdqqlby@forum.dlang.org to compare answer speed :) I basically want to be able to do stuff like this: auto result = map!( (a, b) => a+b )( lockstep(range1, range2) ); Are there any standard…
Mihails Strasuns
  • 3,783
  • 1
  • 18
  • 21
2
votes
1 answer

How to encapsulate an existing array using D2's phobos std.range

I would like to encapsulate an existing data array ( created by Python's Numpy Lib ) into an Array like object in the D2 Language... without having to copy the array data... I already use Python's cTypes Lib to make a DLL call, passing array lengths…
Peter Li
  • 295
  • 1
  • 2
  • 9
2
votes
1 answer

How do I create a 2D Array in D?

This should be simple enough, but it's not. import std.container, std.stdio; void main(){ alias Array!double _1D; alias Array!_1D _2D; _1D a = _1D(); _2D b = _2D(); a.insert(1.2); a.insert(2.2); a.insert(4.2); b.insert(a); …
Arlen
  • 6,641
  • 4
  • 29
  • 61
2
votes
1 answer

How convert a D array to C variadic?

I would like convert an array in D of the form: string[] arrayStr = [ "hi, "is fun", "use D programming" ]; I have a C function which takes a C variadic: void c_func( const char* format, ... ); I could do: foreach(str; arrayStr) func( str…
bioinfornatics
  • 1,749
  • 3
  • 17
  • 36
2
votes
1 answer

Where is D's `std.sumtype`?

I'm working on a project in the D language and I want to use a module from the standard library called std.sumtype. I'm on debian oldstable, and I've tried both GDC and LDC. DMD is unavailable, because I'm using a machine with an armhf architecture.…
VintiumDust
  • 95
  • 1
  • 6
2
votes
2 answers

How to use tolower in D

I want to to put the first letter of a string into lowercase in D. As a string is imutable in D, there doesn't seem to be a simple way. I came up with this: string mystr = "BookRef"; string outval = toLower( mystr[0..1] ) ~ mystr[1..$]; writeln(…
A.Franzen
  • 725
  • 4
  • 10