FixedString

Constructors

this
this(CharT[] rhs)

constructor

Members

Functions

concat
auto concat(FixedString!(n, T) rhs)

concatenation. note that you should probably use the ~ operator instead - only use this version when you are pressed for ram and aren't making many calls, or you will end up with template bloat.

length
size_t length()
void length(size_t rhs)
opAssign
void opAssign(CharT[] rhs)
void opAssign(FixedString!(n, T) rhs)

assignment

opBinary
auto opBinary(FixedString!(n, T) rhs)

concatenation operator. generally, you should prefer this version.

opDollar
size_t opDollar()

array features...

opEquals
bool opEquals(FixedString!(n, T) rhs)
bool opEquals(CharT[] s)

equality

opIndex
auto opIndex()
CharT opIndex(size_t index)
opIndexAssign
void opIndexAssign(CharT rhs, size_t index)

array features...

opOpAssign
void opOpAssign(CharT[] rhs)
void opOpAssign(CharT rhs)
void opOpAssign(FixedString!(n, T) rhs)

assignment

opSlice
auto opSlice(size_t first, size_t last)

array features...

toHash
size_t toHash()
toString
const(CharT)[] toString()

Manifest constants

size
enum size;

Examples

1 immutable string temp = "cool";
2 auto foo = FixedString!8(temp);
3 assert(foo[0] == 'c');
4 assert(foo == "cool");
5 
6 import std.algorithm.comparison: equal;
7 assert(foo[].equal("cool"));
8 assert(foo[0 .. $] == "cool");
9 
10 foo[2] = 'd';
11 assert(foo == "codl");
12 assert(foo != "");
13 
14 foo ~= "d";
15 foo.length = 4;
16 assert(foo == "codl");
17 
18 foo.length = 6;
19 assert(foo == "codl\xff\xff");
20 
21 foo.length = 4;
22 assert(foo == "codl");
23 
24 import std.range: retro;
25 assert(equal(retro(foo[]), "ldoc"));
26 
27 import std.range: radial;
28 assert(equal(radial(foo[]), "odcl"));
29 
30 import std.range: cycle;
31 assert(foo[].cycle[4 .. 8].equal(foo[]));
32 
33 assert(foo[].save == foo[]);
34 
35 FixedString!10 bar;
36 bar = " is nic";
37 bar ~= 'e';
38 
39 immutable truth = fixedString!"codl is nice";
40 
41 assert(foo ~ bar == truth);
42 assert(foo.concat!16(bar) == truth);
43 assert(foo ~ bar == foo.concat!16(bar));
44 
45 FixedString!10 d;
46 d = foo;
47 d.length = 4;
48 
49 foreach (i, char c; d)
50 {
51 	assert(c == foo[i]);
52 }
53 
54 foo = "de";
55 foo ~= "ad";
56 assert(foo == "dead");
57 bar = "beef";
58 foo ~= bar;
59 assert(foo == "deadbeef");
60 
61 assert(fixedString!"aéiou" == "aéiou");
62 
63 immutable char[4] dead = "dead";
64 immutable(char)[4] beef = "beef";
65 
66 immutable FixedString!4 deader = dead;
67 immutable FixedString!4 beefer = beef;
68 assert(deader ~ beefer == "deadbeef");
immutable a = FixedString!16("bepis");
assert(a.toString == "bepis");

int[FixedString!16] table;
table[a] = 1;

immutable b = FixedString!16("conk");
table[b] = 2;

assert(table[a] == 1);
assert(table[b] == 2);

readme example code

FixedString!14 foo = "clang";
foo[0] = 'd';
foo ~= " is cool";
assert(foo == "dlang is cool");

foo.length = 9;

immutable bar = fixedString!"neat";
assert(foo ~ bar == "dlang is neat");

// wchars and dchars are also supported
assert(FixedString!(5, wchar)("áéíóú") == "áéíóú");

// in fact, any type is:
immutable int[4] intArray = [1, 2, 3, 4];
assert(FixedString!(5, int)(intArray) == intArray);

Meta