Questions tagged [phobos]

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

Filter by
Sorted by
Tagged with
3 votes
1 answer
95 views

Unable to recursively multiply BigInt beyond a certain number of iterations at compile-time in D

I need to get the product of an arbitrary number of variables. The actual number of variables and their values will be known at compile-time, however I cannot hardcode these because they come from ...
saxbophone's user avatar
3 votes
1 answer
125 views

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, ...
VintiumDust's user avatar
1 vote
0 answers
71 views

Adding a custom type to a RedBlackTree

I want to keep an ordered set of records and the standard provides me with RedBlackTree. The record is of type Tuple!(string, uint). Here's what it looks like: import std.json : parseJSON; uint[...
noconst's user avatar
  • 649
1 vote
1 answer
211 views

how to check for array or range length being at least N in Dlang

For N=1, I would use std.array : empty to check for length being at least N, and avoid having to go through the whole input. For N>1 (or all N), what is the idiomatic way in D language? I've tried ...
V-R's user avatar
  • 1,319
2 votes
2 answers
74 views

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 =...
A.Franzen's user avatar
  • 725
0 votes
1 answer
43 views

Make array from a range in D language

In D language, what is the shortest way to construct an array from a given range? Let I have an iterator i. How to make an array of its elements (in order)?
porton's user avatar
  • 5,338
1 vote
1 answer
40 views

Using std.algorithm.iteration.sum with Duration[]

Why I can't use std.algorithm.iteration.sum with Duration[] ? I thought I can use the sum in the same way than e.g. with int[]: int[] ints = [40, 27, 5]; int intSum = ints.sum(); assert(intSum == 72)...
user272735's user avatar
  • 10.5k
2 votes
1 answer
47 views

std.algorithm.remove() duplicating array items?

I have an array that I need to remove items from, by index. It for some reason duplicates other items in the array to take the removed item's place. Here is an example of the issue. import std.stdio: ...
Jacob Birkett's user avatar
3 votes
1 answer
654 views

What is the right way to convert Variant to proper type?

I use mysql-native that return Variant data type. I need to convert it to standard types like int, string etc. D have std.conv, but std.variant also have methods for concretion. I can't understand ...
Dmitry Bubnenkov's user avatar
3 votes
1 answer
148 views

vibe.d: Try to send a Message to a stopped Task

When sending a Message to a stopped vibe.d Task, the application gets an segmentation fault. I did not expect the message to be delivered, but to get notified about the failed sending attempt (or at ...
Skruppy's user avatar
  • 73
1 vote
2 answers
692 views

Get the variable values at runtime using reflection in Dlang

Is it possible to get the class/struct/other variables value during runtime in dlang to get/set its value? If yes how to do that please provide example. And also is it possible to get the runtime ...
Hakuna Matata's user avatar
1 vote
4 answers
294 views

Is there an equivalent for Glob in D Phobos?

In python I can use glob to search path patterns. This for instance: import glob for entry in glob.glob("/usr/*/python*"): print(entry) Would print this: /usr/share/python3 /usr/share/python3-...
Matthew Jones's user avatar
0 votes
1 answer
187 views

Why std lib from GDC is not the same that phobos from DMD

For example, I can not compile using GDC 5.2.0 (2016-02-05T11:17:49.3234388) a program importing std.meta because that file is not found. I was comparing the include folders between GDC and DMD and I ...
Jairo Andres Velasco Romero's user avatar
3 votes
1 answer
127 views

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....
Meta's user avatar
  • 1,091
5 votes
1 answer
381 views

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 ...
sigod's user avatar
  • 4,427
1 vote
1 answer
67 views

A class that can parse IP domain (e.g. 192.168.0.0/16)

I am writing a simple script in D that needs to interface with command-line network programs that use IP domain addresses (e.g. 10.0.14.0/24). Is there any ready parser existing for that in D? ...
Adam Ryczkowski's user avatar
2 votes
1 answer
67 views

std.algorithm.sorting fails with obscure errors when using Array!T and opSlice()

I'm sure I'm missing something obvious here - the rest of D (even the compiler errors) have been very sensible and easy to understand. I have a std.containers.Array of comparable structs and I'd like ...
TheWyrdsmith's user avatar
2 votes
1 answer
92 views

Why Can't I Use std.algorithm.count With a Predicate Function

The following code fails to compile: assert("(((())))()()()()))".count!(c => c.among!('(', ')')) > 0); With the error message: "Error: template std.algorithm.searching.count cannot deduce ...
Meta's user avatar
  • 1,091
4 votes
1 answer
223 views

Remove substring from string in D

How to remove all occurrences of a string in another? I can do this using the following code: std.array.replace: "the string".replace("the", "") But I wonder if there is a dedicated function for ...
Denis Gladkiy's user avatar
3 votes
2 answers
279 views

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 ...
Suliman's user avatar
  • 1,479
6 votes
2 answers
270 views

Byte InputRange from file

How to construct easily a raw byte-by-byte InputRange/ForwardRange/RandomAccessRange from a file?
Tamas's user avatar
  • 3,314
4 votes
1 answer
146 views

Should std.algorithm.find demand a reference to range elements?

I have been working on a class-based finite random access range. When performing a few tests on it: auto myRange = /* construct my range */ static assert (isRandomAccessRange!(typeof(myRange))); // ...
E_net4's user avatar
  • 28.4k
0 votes
1 answer
85 views

std.json - Any way to check if a JSONValue has a particular field

Suppose I have an unknown bit of JSON, and I want to check if it has a form similar to this: { "foo": stuff "bar": stuff } where stuff is anything - integer, object, whatever. If I do ...
Koz Ross's user avatar
  • 3,090
2 votes
1 answer
185 views

std.json - A bit confused with TRUE, FALSE and NULL values

I was looking over the std.json library as part of program I am working on, and I'm a bit confused about how to get data out of JSONValues whose types are inferred as TRUE, FALSE or NULL. For example,...
Koz Ross's user avatar
  • 3,090
4 votes
2 answers
464 views

How to mock standard library functions in D

I have a function that calls isFile (from std.file) on a filename and then proceeds appending .1, .2, .3 etc, checking whether each one of those is present. I want to unit test the function, but to ...
garph0's user avatar
  • 1,700
2 votes
1 answer
67 views

Phobos library function for converting a uint to binary string

Is there a Phobos function that converts an unsigned integer to a binary string? I've searched, but couldn't find one - just want to make sure I'm not reinventing the wheel by writing my own.
Koz Ross's user avatar
  • 3,090
2 votes
1 answer
102 views

Does phobos (D's standard library) contain "endsWith" for string type?

I need a function to test if a string ends with some suffix. I can use 'lastIndexOf' for this task, but I wonder if there is a standard phobos' function?
Denis Gladkiy's user avatar
2 votes
1 answer
124 views

D: Why is opIndex not const-qualified in the std.container.Array class?

I recently wanted to make use of std.container.Array and proceeded to create a class with a getter member function which returns a value from the Array class. I quickly realised that I was not able to ...
David Eränen's user avatar
3 votes
1 answer
884 views

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 ...
Chloride Cull's user avatar
3 votes
1 answer
47 views

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*)); ...
Koz Ross's user avatar
  • 3,090
6 votes
1 answer
265 views

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 ...
duselbaer's user avatar
  • 935
3 votes
1 answer
92 views

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 ...
Koz Ross's user avatar
  • 3,090
2 votes
1 answer
60 views

Deterministic destruction of container-owned objects (or how to put a Unique (std.typecons.Unique) into a D Phobos container)?

I'm trying to instantiate a container full of Unique resources, in an attempt to ensure that when the container is destroyed, all items managed (owned) by the container are also destroyed, ...
U007D's user avatar
  • 5,882
2 votes
1 answer
792 views

Cannot resolve type for template function

I'm trying to code up something very simple in D, but I'm having a few problems with one of the standard library template functions (specifically, nextPermutation from std.algorithm). The crux of ...
Yuushi's user avatar
  • 25.3k
4 votes
1 answer
112 views

Comparing pointers to structs for the purpose of Phobos' Binary Heap

I've written a struct called Node, and want to be able to use pointers to that struct as entries in a Phobos BinaryHeap. However, I am not sure how opEquals and opCmp are implemented for pointers to ...
Koz Ross's user avatar
  • 3,090
1 vote
1 answer
149 views

try to install Tango+D2 but compile with error symbol undefined (Window)

I try to use Tango and Phobo together in D2 and I downloaded the package from link and follow its installation process. But it has only Linux installation but not windows. This is what I do. ...
Hami's user avatar
  • 335
3 votes
1 answer
395 views

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 ...
dev1223's user avatar
  • 1,149
2 votes
1 answer
177 views

Offline copy of Phobos documentation [closed]

Is there a way for me to have an offline (preferably searchable) copy of the Phobos documentation as available here?
Koz Ross's user avatar
  • 3,090
1 vote
1 answer
141 views

Odd behaviour from Array in BinaryHeap

I have a tree-like structure using Node objects with references to other Node objects. Node is a class. Now, one of the routines I'm writing needs a minimum priority queue, which I'm implementing ...
Koz Ross's user avatar
  • 3,090
2 votes
1 answer
71 views

D: Escaping spaces in a string

I have a string "foo bar baz", and would like to turn it into "foo\ bar\ baz". Short of the hand-hacking method (call split, then re-join with the appropriate separator), is there another way I can do ...
Koz Ross's user avatar
  • 3,090
4 votes
2 answers
189 views

Manipulating Bits of Any Value Type

Has anybody cooked up some generic functions that extend core.bitop bitmanipulations to work on any value type? Something like bool getBit(T)(in T a, int bitnum); // bt T setBit(T)(in T a, int ...
Nordlöw's user avatar
  • 11.9k
1 vote
1 answer
121 views

Cartesian product of immutable ranges

Why can't we compute the cartesian product of two immutable ranges ? The following code : import std.stdio; import std.algorithm; void main() { immutable int[] B = [ 1, 2, 3 ]; immutable ...
matovitch's user avatar
  • 1,264
2 votes
1 answer
111 views

DMD linking fails because of missing _adCmp2 and _adEq2

I regularly rebuild and use DMD git master locally on Ubuntu 13.10. Yesterday my D toolchain fails to link all D programs with the error: Example compilation output from DMD: /home/per/opt/x86_64-...
Nordlöw's user avatar
  • 11.9k
4 votes
3 answers
156 views

In-Place Ordering of Elements

Does Phobos have some variadic algorithm to order l-value reference arguments in place? Something like int a=3; int b=2; int c=1; orderInPlace(a,b,c); // a is now 1 // b is now 2 // c is now 3 ...
Nordlöw's user avatar
  • 11.9k
1 vote
1 answer
192 views

D Socket Programming Basic Connection Script

I am brand new to D programming so please excuse my ignorance. I am trying to create a basic program to connect to a website and download a page or connect to a restful API and download info. Right ...
user2395126's user avatar
4 votes
1 answer
306 views

Using std.array.replace on the result of std.algorithm.map

So I was fiddling around with the D Programming Language today and just could not find any information about how to use std.array.replace on the return type of std.algorithm.map void main() { ...
Dominik Lohmann's user avatar
1 vote
2 answers
114 views

Attempt string-to-real conversion in D without exceptions

Given an array of string, I want to find the first one that can be successfully converted to a real without using exceptions. The only relevant functions I can see in Phobos are std.conv.to and std....
Peter Alexander's user avatar
1 vote
2 answers
231 views

Segfault in D for too large inputs

The following D program crashes for input 939971 or higher, but not for input 939970 or lower: #!/usr/bin/rdmd --shebang -w -d-debug --relocation-model=pic import std.stdio; import std.bigint; ...
Demi's user avatar
  • 3,555
3 votes
0 answers
109 views

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 ...
Nordlöw's user avatar
  • 11.9k
8 votes
1 answer
204 views

equivalent of remove_if in D

Recently I have taken an interest in the D programming language. I just started learning it, and am coming from a C++ background. I am wondering if there is an equivalent of std::remove_if. I only saw ...
mio iwakura's user avatar