std.conv:to that does not throw?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sat Feb 1 20:08:55 UTC 2025
On Friday, January 31, 2025 3:45:55 PM MST Kyle Ingraham via Digitalmars-d-learn wrote:
> On Thursday, 30 January 2025 at 04:44:02 UTC, Jonathan M Davis
> wrote:
> > What we really need is something like tryTo that returns a
> > Nullable which has no value when the conversion fails, and then
> > preferably, tryTo would share its implementation with to
>
> I like a Nullable return much more than what I presented. I’ll
> have a look at how hard it might be to throw that together.
If all you need is to convert strings to integers, then it's quite
straightforward and shouldn't take long to write. The problem with regards
to something like std.conv.to is that it does a _lot_ of different types of
conversions. So, while we definitely should have something like tryTo in
addition to having to, it's non-trivial due to how much to does.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list