Re: BetterC, int to string?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 9:46 AM, Steven Schveighoffer wrote: On 6/18/21 5:05 AM, Mike Brown wrote: Hi all, I would like to convert a D string to an int - im doing this in a compile time function as well. conv throws an error due to it using TypeInfo? How would I do this? std.conv.to really should

Re: BetterC, int to string?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 5:05 AM, Mike Brown wrote: Hi all, I would like to convert a D string to an int - im doing this in a compile time function as well. conv throws an error due to it using TypeInfo? How would I do this? std.conv.to really should support it, that seems like a bug. But just FYI,

Re: @trusted methods

2021-06-18 Thread ag0aep6g via Digitalmars-d-learn
On 18.06.21 14:40, vit wrote: Are asserts enough to make method @trusted or is something like throw exception or return error code necessary? Asserts are a debugging feature. They're not suitable to ensure safety, because they're simply skipped in release mode. `assert(false);` is the

@trusted methods

2021-06-18 Thread vit via Digitalmars-d-learn
Are asserts enough to make method @trusted or is something like throw exception or return error code necessary? How it work in phobos? Example: ```d struct Slice(T){ private T[] data; this(T[] data){ this.data = data; } inout(T)[] opSlice()inout scope return

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 12:40 AM, Mathias LANG wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. However, sometimes the data I'm switching on is coming from elsewhere (i.e. a

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 6:35 AM, Johan wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the data is valid (it's one of the enum values), I don't want to crash

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/21 5:54 PM, H. S. Teoh wrote: On Thu, Jun 17, 2021 at 05:41:28PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [.[..] Oh, and to throw a monkey wrench in here, the value is a string, not an integer. So I can't use std.conv.to to verify the enum is valid (plus, then I'm

Re: semi-final switch?

2021-06-18 Thread Johan via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the data is valid (it's one of the enum values), I don't want to crash the program if the incoming

Re: BetterC, int to string?

2021-06-18 Thread Dennis via Digitalmars-d-learn
On Friday, 18 June 2021 at 09:05:38 UTC, Mike Brown wrote: im doing this in a compile time function as well. If it's a compile time string you can use mixin()

Re: BetterC, int to string?

2021-06-18 Thread jfondren via Digitalmars-d-learn
On Friday, 18 June 2021 at 09:05:38 UTC, Mike Brown wrote: Hi all, I would like to convert a D string to an int - im doing this in a compile time function as well. conv throws an error due to it using TypeInfo? How would I do this? Kind regards, Mike BetterC has [some CTFE-related

BetterC, int to string?

2021-06-18 Thread Mike Brown via Digitalmars-d-learn
Hi all, I would like to convert a D string to an int - im doing this in a compile time function as well. conv throws an error due to it using TypeInfo? How would I do this? Kind regards, Mike