toCStringThen

Call dg with src as input.

toCStringThen
(
alias dg
uint smallSize = 512
)
(
const(char)[] src
)
if (
is(typeof(dg((char[]).init)))
)

Examples

enum smallSize = 4;
const src = "42";
scope char[src.length + 1] y;
@safe void f(in char[] x) { y = x; }
src.toCStringThen!(f, smallSize)(); // uses stack
assert(y[0 .. $ - 1] == src);
assert(y[$ - 1 .. $] == "\0");
enum smallSize = 4;
const src = "4200";
scope char[src.length + 1] y;
@safe void f(in char[] x) { y = x; }
src.toCStringThen!(f, smallSize)(); // uses heap
assert(y[0 .. $ - 1] == src);
assert(y[$ - 1 .. $] == "\0");

See Also

Meta