stringifiable

Constructs a functor type from a function alias, and wraps it into a stringifiable object. Can be used to create stringifiable widgets which need a sink for more complex behavior.

  1. auto stringifiable(T values)
    template stringifiable(alias fun, T...)
    stringifiable
    ()
    (
    auto ref T values
    )
  2. auto stringifiable(F functor)

Members

Functions

stringifiable
auto stringifiable(T values)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

alias humanSize = stringifiable!(
	(size, sink)
	{
		import std.format : formattedWrite;
		if (!size)
			// You would otherwise need to wrap everything in fmtIf:
			return sink("0");
		static immutable prefixChars = " KMGTPEZY";
		size_t power = 0;
		while (size > 1000 && power + 1 < prefixChars.length)
			size /= 1024, power++;
		sink.formattedWrite!"%s %sB"(size, prefixChars[power]);
	}, real);

import std.conv : text;
assert(humanSize(0).text == "0");
assert(humanSize(8192).text == "8 KB");

Meta