Standard Library Tour (Phobos)

Console and file I/O std.algorithm.*, std.range.*, std.array Algorithms and ranges

std.string, std.uni, std.utf, std.ascii, std.format, std.conv Text and conversion

Regular expressions (runtime and compile-time) Array, DList, SList, RedBlackTree, BinaryHeap

std.typecons, std.sumtype, std.variant Type utilities, sum types std.traits, std.meta Function composition, memoization

std.math, std.numeric, std.bigint, std.complex, std.mathspecial, std.checkedint Dates, times, durations, stopwatch

std.file, std.path, std.process, std.mmfile, std.stdio.File Filesystem and processes

std.json, std.csv, std.base64, std.zip, std.zlib, std.outbuffer, std.bitmanip std.net.curl, std.socket, std.uri std.concurrency, std.parallelism

std.digest.* (md5, sha, crc, murmurhash, hmac), std.uuid

std.logger (formerly std.experimental.logger) enforce, assumeUnique, collectException std.windows.*, core.sys.*

42.1 Containers

import std.container;
auto arr = Array!int(1, 2, 3);          // deterministic memory (malloc), not GC
arr.insertBack(4);
auto list = DList!string(["a", "b"]);
list.insertFront("z");
auto tree = redBlackTree(5, 1, 3);       // sorted set
tree.insert(2);
writeln(tree[], 3 in tree);
auto heap = heapify!"a > b"([5, 1, 9]);  // max-heap... (comparison decides the order)
writeln(heap.front);
heap.removeFront();

42.2 Date and Time

import std.datetime, std.datetime.stopwatch;
auto now = Clock.currTime();
writeln(now.toISOExtString, " ", now.year, " ", now.dayOfWeek);
auto date = Date(2025, 10, 24);
writeln(date + days(30), " ", (Date(2025, 12, 31) - date).total!"days");
auto dur = 2.hours + 30.minutes;
auto sw = StopWatch(AutoStart.yes);
/* work */
writeln(sw.peek.total!"msecs", " ms");
auto results = benchmark!(funA, funB)(1000);
auto parsed = SysTime.fromISOExtString("2025-10-24T10:30:00Z");

42.3 Random, Math and BigInt

import std.random, std.math, std.bigint;
auto rnd = Random(42);
writeln(uniform(1, 7, rnd), uniform01(rnd), [1, 2, 3].choice(rnd));
auto arr = [1, 2, 3, 4];
arr.randomShuffle(rnd);
writeln(sqrt(2.0), pow(2.0, 10), PI, E, floor(3.7), round(2.5), abs(-3), isNaN(double.nan));
BigInt big = BigInt("123456789012345678901234567890");
writeln(big * big);