assert("42_1".toDefaulted!int(43) == 43); assert(42.toDefaulted!string("_43") == "42");
enum E { unknown, x, y, z, z2 = z, } assert("x".toDefaulted!(E)(E.init) == E.x); assert("z".toDefaulted!(E)(E.init) == E.z); assert("z2".toDefaulted!(E)(E.init) == E.z); assert("_".toDefaulted!(E)(E.init) == E.unknown);
https://forum.dlang.org/post/bnbbheofzaxlabvnvrrc@forum.dlang.org http://forum.dlang.org/post/tsszfamjalzviqjhpdcr@forum.dlang.org https://forum.dlang.org/post/kdjbkqbnspzshdqtsntg@forum.dlang.org
Variant of std.conv.to with defaultValue making it nothrow.