parse

$(PANEL The `parse` family of functions works quite like the $(LREF to) family, except that: $(OL $(LI It only works with character ranges as input.) $(LI It takes the input by reference. This means that rvalues (such as string literals) are not accepted: use `to` instead.) $(LI It advances the input to the position following the conversion.) $(LI It does not throw if it could not convert the entire input.)) )

This overload parses a bool from a character input range.

Parameters

Target

the boolean type to convert to

source Source

the lvalue of an input range

doCount

the flag for deciding to report the number of consumed characters

Return Value

Type: auto
  • A bool if doCount is set to No.doCount
  • A tuple containing a bool and a size_t if doCount is set to Yes.doCount

Throws

A ConvException if the range does not represent a bool.

Note: All character input range conversions using to are forwarded to parse and do not require lvalues.

Examples

import std.typecons : Flag, Yes, No;
auto s = "true";
bool b = parse!bool(s);
assert(b);
auto s2 = "true";
bool b2 = parse!(bool, string, No.doCount)(s2);
assert(b2);
auto s3 = "true";
auto b3 = parse!(bool, string, Yes.doCount)(s3);
assert(b3.data && b3.count == 4);
auto s4 = "falSE";
auto b4 = parse!(bool, string, Yes.doCount)(s4);
assert(!b4.data && b4.count == 5);

Meta