ctQuantityParser

Creates a compile-time parser capable of working on user-defined units and prefixes.

Contrary to a runtime parser, a compile-time parser infers the type of the parsed quantity automatically from the dimensions of its components.

template ctQuantityParser (
N
alias symbolList
alias parseFun =
(
ref string s
)
=> parse!N(s)
) {}

Members

Templates

ctQuantityParser
template ctQuantityParser(string str)
Undocumented in source.

Parameters

N

The type of the value type stored in the Quantity struct.

symbolList

A prefilled SymbolList struct that contains all units and prefixes.

parseFun

A function that can parse the beginning of a string to return a numeric value of type N. After this function returns, it must have consumed the numeric part and leave only the unit part.

Examples

enum bit = unit!("bit", ulong);
alias BinarySize = typeof(bit);
enum byte_ = 8 * bit;

enum symbolList = makeSymbolList!ulong(
    withUnit("bit", bit),
    withUnit("B", byte_),
    withPrefix("hob", 7)
);

alias sz = ctQuantityParser!(ulong, symbolList);

assert(sz!"1 hobbit".value(bit) == 7);

Meta