Phobos is the official runtime and standard library of the D programming language.
Questions tagged [phobos]
97 questions
4
votes
1 answer
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 this in phobos?

Denis Gladkiy
- 2,084
- 1
- 26
- 40
4
votes
1 answer
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))); //
static assert (!isInfinite!(typeof(myRange))); …

E_net4
- 27,810
- 13
- 101
- 139
4
votes
2 answers
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 do so I need to mock isFile.
I looked around a bit…

garph0
- 1,700
- 1
- 13
- 16
4
votes
1 answer
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 structs (or in fact, in general). I've not been…

Koz Ross
- 3,040
- 2
- 24
- 44
4
votes
2 answers
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 bitnum); // bts
auto ref setBitInPlace(T)(ref T a, int…

Nordlöw
- 11,838
- 10
- 52
- 99
4
votes
3 answers
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
Also a functional variant, say order(a, b, c), that…

Nordlöw
- 11,838
- 10
- 52
- 99
4
votes
1 answer
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() {
import std.stdio : writeln;
writeln(test([1, 2,…

Dominik Lohmann
- 65
- 1
- 2
- 5
4
votes
1 answer
Object.Error: Access Violation when printing result of std.algorithm.cartesianProduct
I'm using DMD 2.062 for x86.
module test;
private enum test1
{
one,
two,
three,
}
private enum test2
{
one,
two,
three,
}
auto ct = cartesianProduct([EnumMembers!test1], [EnumMembers!test2]);
unittest
{
import…

Meta
- 1,091
- 6
- 14
3
votes
4 answers
how to decode ubyte[] to a specified encoding?
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…

bioinfornatics
- 1,749
- 3
- 17
- 36
3
votes
4 answers
D- how to verify that an IP address is valid
I'm writing an HTTP parsing library (because I couldn't find a good one in pure D), and I needed to be able to validate IP addresses (for the URI field), so I wrote a couple functions to validate IP addresses:
For IPv4:
bool isIPv4(string addr) {
…

beatgammit
- 19,817
- 19
- 86
- 129
3
votes
1 answer
Can I rely on the presence of shell()?
std.process has a nice shell() function.
import std.process;
import std.stdio;
void main()
{
string Output = shell("ls .");
writeln("The contents of this directory are:");
write(Output);
}
It is documented in the Phobos source, but not…

Maxpm
- 24,113
- 33
- 111
- 170
3
votes
1 answer
Return dynamic type
i know template like
T add(T)(T a, Tb){
return a + b;
}
But this need to user ask which type will be return, me i want compute inside method which type will be returned like:
T getField( size_t column ){
if( column == 0 )
T = int;
…

bioinfornatics
- 1,749
- 3
- 17
- 36
3
votes
1 answer
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 reflection done on types at compile-time, using…

saxbophone
- 779
- 1
- 6
- 22
3
votes
2 answers
DMD Phobos-to-Tango conversion: va_arg - what is it? and what do I replace it with?
I'm trying to convert some Phobos code to its Tango equivalent, but I am stuck on this piece of code that I don't completely understand:
OutBuffer codebuf;
(...)
void gen(Loc loc, uint opcode, uint argc, ...)
{
codebuf.reserve((1 + argc) *…

Frederik
- 594
- 3
- 9
- 24
3
votes
1 answer
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 what difference between: get, coerce, toString and…

Dmitry Bubnenkov
- 9,415
- 19
- 85
- 145