Re: 'typeof' question

2023-11-28 Thread DLearner via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 18:43:37 UTC, Adam D Ruppe wrote: On Tuesday, 28 November 2023 at 18:41:49 UTC, DLearner wrote: A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from A_Ptr of type A*. I think what you really want is

Re: 'typeof' question

2023-11-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 18:41:49 UTC, DLearner wrote: A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from A_Ptr of type A*. I think what you really want is typeof(*A_Ptr) ASUB; the typeof thing returns the type you'd get from the

'typeof' question

2023-11-28 Thread DLearner via Digitalmars-d-learn
Trying to manipulate 'typeof' return strings, preferably at compile-time. e.g. to produce struct B below (intended to have an A sub-struct), from A_Ptr alone. ``` struct A { int AFld1; } A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from

Re: interface inference

2023-11-28 Thread Antonio via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 15:46:18 UTC, Paul Backus wrote: On Thursday, 23 November 2023 at 19:17:20 UTC, Antonio wrote: Basically, the ternary conditional ```?:``` result type is not inferred even if the type returned by the two possibilities are the same. **Is it a bug or the

Re: interface inference

2023-11-28 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 23 November 2023 at 19:17:20 UTC, Antonio wrote: Basically, the ternary conditional ```?:``` result type is not inferred even if the type returned by the two possibilities are the same. **Is it a bug or the expected behaviour?** Known bug, first reported in 2009:

Re: interface inference

2023-11-28 Thread Antonio via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 14:10:30 UTC, Dom DiSc wrote: On Tuesday, 28 November 2023 at 11:01:14 UTC, Antonio wrote: ```d I aOrB(bool check){ if(check) return new A(); else return new B(); } ``` **Is it the expected behaviour for ternary conditional?** Here the compiler

Re: interface inference

2023-11-28 Thread Dom DiSc via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 11:01:14 UTC, Antonio wrote: ```d I aOrB(bool check){ if(check) return new A(); else return new B(); } ``` **Is it the expected behaviour for ternary conditional?** Here the compiler knows what type to return (from the function signature). But the

Re: interface inference

2023-11-28 Thread Antonio via Digitalmars-d-learn
On Thursday, 23 November 2023 at 19:17:20 UTC, Antonio wrote: ```d interface I { bool check(); } class A : I { bool check() =>true; } class B : I { bool check() =>false; } I aOrB(bool check) => check ? new A() : new B(); void main() { assert( aOrB(true).check ); } ```

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-28 Thread Julian Fondren via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 08:51:21 UTC, Mark Davies wrote: I did it this way ... You always print the full array of bytes this way. Output piped to `od -c` is ``` 000 1 2 3 4 5 377 377 377 377 377 \n - 1 2 3 4 020 5 377 377 377 377 \n ``` Those 377s

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-28 Thread Dom DiSc via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 08:51:21 UTC, Mark Davies wrote: On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: ``` import std.stdio; char[10] longToString(long n) @nogc ``` For a 'long' 10 characters is likely to be not enough (long max is 9223372036854775808 which has 19 chars,

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-28 Thread Mark Davies via Digitalmars-d-learn
On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: I tried to look into https://dlang.org/phobos/std_conv.html Most of the functions inside `std.conv` seem to be dependant on [Garbage Collection](https://dlang.org/spec/garbage.html). And I couldn't find a straightforward way to