digitalmars.D.learn - 'typeof' question
- DLearner (17/17) Nov 28 2023 Trying to manipulate 'typeof' return strings, preferably at
- Adam D Ruppe (4/9) Nov 28 2023 I think what you really want is
- DLearner (2/12) Nov 28 2023 Thanks - worked.
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 A_Ptr of type A*. } ``` But this fails with 'can only slice tuple types...'. Suggestions?
Nov 28 2023
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 code inside
Nov 28 2023
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:Thanks - worked.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 code inside
Nov 28 2023