Questions tagged [phobos]

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

97 questions
2
votes
1 answer

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: writeln; import std.algorithm: remove; void…
Jacob Birkett
  • 1,927
  • 3
  • 24
  • 49
2
votes
2 answers

Extension methods in D?

Hey folks, I'm trying to get these bits of syntax to make sense to me: S[] split(S)(S s) if (isSomeString!S) { ... } and string join(in string[] words, string sep) { ... } (As seen in phobos/src/std/string.d) As far as I can tell, this is…
Kris
  • 40,604
  • 9
  • 72
  • 101
2
votes
1 answer

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 least not to crash). The following example…
Skruppy
  • 63
  • 6
2
votes
1 answer

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 to sort it. the std.containers documentation…
2
votes
1 answer

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 function from argument types !((c) => c.among!('(',…
Meta
  • 1,091
  • 6
  • 14
2
votes
1 answer

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, if I parse the following JSON: { "foo" :…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
2
votes
1 answer

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

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
  • 2,084
  • 1
  • 26
  • 40
2
votes
1 answer

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 const-qualify my getter, since opIndex is a…
2
votes
1 answer

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, automatically and right then. The following (non-Unique)…
U007D
  • 5,772
  • 2
  • 38
  • 44
2
votes
1 answer

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 what I'm trying to do is to create all permutations…
Yuushi
  • 25,132
  • 7
  • 63
  • 81
2
votes
1 answer

Offline copy of Phobos documentation

Is there a way for me to have an offline (preferably searchable) copy of the Phobos documentation as available here?
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
2
votes
1 answer

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 this? Does something like a replace function…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
2
votes
1 answer

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…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
2
votes
1 answer

How to detect if a function is annotated with @property

Is it possible using D's builtin traits and/or std.traits to detect whether a function (either within a class/struct or without) is annotated with @property? I know @property isn't really an attribute, but I thought __traits(getAttributes, ...)…
Meta
  • 1,091
  • 6
  • 14