On Thursday, 30 January 2025 at 17:19:19 UTC, Lance Bachmeier wrote:
>I’ll give those a try tonight. At first glance I see mention of throwing so they may not fit but I’ll know for certain soon enough.
January 31 Re: std.conv:to that does not throw? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lance Bachmeier |
January 31 Re: std.conv:to that does not throw? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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.
|
February 01 Re: std.conv:to that does not throw? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle Ingraham | On Friday, 31 January 2025 at 22:42:14 UTC, Kyle Ingraham wrote: >On Thursday, 30 January 2025 at 17:19:19 UTC, Lance Bachmeier wrote: >I’ll give those a try tonight. At first glance I see mention of throwing so they may not fit but I’ll know for certain soon enough. It turns out that they both do throw. |
February 01 Re: std.conv:to that does not throw? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle Ingraham | On Saturday, 1 February 2025 at 02:05:13 UTC, Kyle Ingraham wrote: >On Friday, 31 January 2025 at 22:42:14 UTC, Kyle Ingraham wrote: >On Thursday, 30 January 2025 at 17:19:19 UTC, Lance Bachmeier wrote: >I’ll give those a try tonight. At first glance I see mention of throwing so they may not fit but I’ll know for certain soon enough. It turns out that they both do throw. For integral types, you can try my implementation |
February 01 Re: std.conv:to that does not throw? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle Ingraham | 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
|