The OpenD Programming Language

parse

Parses an enum type from a string representing an enum member name.

Parameters

Target

the enum type to convert to

s Source

the lvalue of the range to parse

doCount

the flag for deciding to report the number of consumed characters

Return Value

Type: auto
  • An enum of type Target if doCount is set to No.doCount
  • A tuple containing an enum of type Target and a size_t if doCount is set to Yes.doCount

Throws

A ConvException if type Target does not have a member represented by s.

Examples

import std.typecons : Flag, Yes, No, tuple;
enum EnumType : bool { a = true, b = false, c = a }

auto str = "a";
assert(parse!EnumType(str) == EnumType.a);
auto str2 = "a";
assert(parse!(EnumType, string, No.doCount)(str2) == EnumType.a);
auto str3 = "a";
assert(parse!(EnumType, string, Yes.doCount)(str3) == tuple(EnumType.a, 1));

Meta