D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1733 - parse() function does not handle all build-in types
Summary: parse() function does not handle all build-in types
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 All
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2007-12-16 08:48 UTC by Marcin Kuszczak
Modified: 2015-06-09 01:14 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Marcin Kuszczak 2007-12-16 08:48:48 UTC
string str = "aaaaa";
writefln(parse!(char)(str));

--
Result: 
conv.d(650): static assert  "Dunno how to parse a char"
---
Should work for generic code.
Comment 1 Marcin Kuszczak 2007-12-26 10:07:26 UTC
Types which should at least be handled:
- char, wchar, dchar
- cfloat, cdouble, creal
- ifloat, idouble, ireal

Probably also (with default behaviour e.g. bool -> "true" -> true, "false" -> false):
- bool
- string, wstring, dstring
Comment 2 Marcin Kuszczak 2007-12-26 10:13:54 UTC
I initially thought that more types are covered by parse, but find out after looking at code that it works only for integral and real types.

So at least documentation should be improved.
Comment 3 Lars T. Kyllingstad 2010-06-15 01:45:00 UTC
to() and parse() can now convert from string to bool:
http://www.dsource.org/projects/phobos/changeset/1646