Re: How to get all modules in a package at CT?

2023-10-05 Thread evilrat via Digitalmars-d-learn
On Thursday, 5 October 2023 at 22:32:36 UTC, mw wrote: So ModuleInfo contains all the modules (transitive closure) built into the current binary that is running? Is there document about this ModuleInfo? I only find Struct object.ModuleInfo https://dlang.org/library/object/module_info.html

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 5 October 2023 at 22:24:06 UTC, mw wrote: On Thursday, 5 October 2023 at 21:41:38 UTC, cc wrote: If you have `T info`, T.tupleof[n] will always match up with info.tupleof[n]. You can think of `info.tupleof[n]` as being rewritten by the compiler in-place as info.whateverFieldTha

Re: How to get all modules in a package at CT?

2023-10-05 Thread mw via Digitalmars-d-learn
On Thursday, 5 October 2023 at 21:25:54 UTC, cc wrote: So how about at runtime? I just want the compiler to help to list them, instead of doing manually. At runtime, simply: ```d foreach (m; ModuleInfo) { writeln(m.name); } ``` However, Walter has hinted that he wants to remove Modul

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread mw via Digitalmars-d-learn
On Thursday, 5 October 2023 at 21:41:38 UTC, cc wrote: If you have `T info`, T.tupleof[n] will always match up with info.tupleof[n]. You can think of `info.tupleof[n]` as being rewritten by the compiler in-place as info.whateverFieldThatIs. You might try this version (note the double {{ }}

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread cc via Digitalmars-d-learn
On Sunday, 1 May 2016 at 09:42:37 UTC, ParticlePeter wrote: I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) { enum attribName = T.tupleof[i].stringof; writefln( "%s : %s", attribName, mixin(

Re: How to get all modules in a package at CT?

2023-10-05 Thread cc via Digitalmars-d-learn
On Thursday, 5 October 2023 at 20:42:26 UTC, mw wrote: On Thursday, 5 October 2023 at 20:07:38 UTC, user1234 wrote: No. Sorry. Generally compile time code cannot interact with the system. To be evaluable at compile time code has to be strongly pure, that is not the case of the function you wo

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-05 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 5 October 2023 at 16:40:49 UTC, Gaurav Negi wrote: Well, in the D programming language, both opIndex and opSlice are two different operators used to access elements of a custom type. Yeah, D is on its way to becoming a near-perfect programming language... ```d enum initialSitua

Re: How to get all modules in a package at CT?

2023-10-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 5 October 2023 at 20:42:26 UTC, mw wrote: On Thursday, 5 October 2023 at 20:07:38 UTC, user1234 wrote: No. Sorry. Generally compile time code cannot interact with the system. To be evaluable at compile time code has to be strongly pure, that is not the case of the function you wo

Re: How to get all modules in a package at CT?

2023-10-05 Thread mw via Digitalmars-d-learn
On Thursday, 5 October 2023 at 20:07:38 UTC, user1234 wrote: No. Sorry. Generally compile time code cannot interact with the system. To be evaluable at compile time code has to be strongly pure, that is not the case of the function you would need. Otherwise you'd need a new traits for that..

Re: opIndexAssign

2023-10-05 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 5 October 2023 at 12:00:22 UTC, Timon Gehr wrote: void opIndexAssign(int value, int index){ i[index] = value; } In this case I need to define many operator overloads. For example (+=), this won't work without returns ref: ```d s[1] += 3;  assert(s.i == [2, 45]); // Error: n

Re: How to get all modules in a package at CT?

2023-10-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 5 October 2023 at 18:40:36 UTC, mw wrote: On Saturday, 24 November 2018 at 15:21:57 UTC, Anonymouse wrote: On Saturday, 24 November 2018 at 08:44:19 UTC, Domain wrote: I have a package named command, and many modules inside it, such as command.build, command.pack, command.help... I

Re: How to get all modules in a package at CT?

2023-10-05 Thread mw via Digitalmars-d-learn
On Saturday, 24 November 2018 at 15:21:57 UTC, Anonymouse wrote: On Saturday, 24 November 2018 at 08:44:19 UTC, Domain wrote: I have a package named command, and many modules inside it, such as command.build, command.pack, command.help... I want to get all these modules at compile time so that I

Re: Straight Forward Arrays

2023-10-05 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 4 October 2023 at 10:51:46 UTC, dhs wrote: D and Go slices have advantages but can be confusing. I don't have a solution, but if anyone is interested, the relevant discussions about slice confusion in the Go community apply to D slices as well. I don't believe slice confusion

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-05 Thread Gaurav Negi via Digitalmars-d-learn
Well, in the D programming language, both opIndex and opSlice are two different operators used to access elements of a custom type. struct S(T) { T[] arr; T opIndex(size_t index) const { assert(index < arr.length, "Index out of range"); re

Re: T[] opIndex() Error: .. signal 11

2023-10-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/5/23 1:49 AM, ag0aep6g wrote: For some further reading, there's an open issue about the unexpected slicing: https://issues.dlang.org/show_bug.cgi?id=14619 Thank you I had forgotten about that issue! -Steve

Re: opIndexAssign

2023-10-05 Thread Timon Gehr via Digitalmars-d-learn
On 10/3/23 00:11, Salih Dincer wrote: Hi, opIndexAssign, which is void, cannot compromise with opIndex, which is a ref!  Solution: Using opSliceAssign.  Could this be a bug?  Because there is no problem in older versions (e.g. v2.0.83). ```d struct S {   int[] i;   ref opIndex(size_t inde