How do I assign attributes of a function to another function?

2021-11-04 Thread Li30U via Digitalmars-d-learn
I am creating a templated object that is a storehouse for a heap object and executes their methods and returns an array of results. With the help of a template, I want to achieve this, but I want to assign the same attributes to the function. How can one pass the attributes of a function to ano

Re: Using "strcpy" to assign value to dynamic char array

2021-11-04 Thread pascal111 via Digitalmars-d-learn
On Thursday, 4 November 2021 at 01:29:57 UTC, jfondren wrote: On Monday, 1 November 2021 at 19:56:13 UTC, pascal111 wrote: But what if I want to use "strcpy" function to assign that new value to the array that the problem is that the array won't take more than its first initializing value lengt

Re: How do you declare manifest constants?

2021-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 04, 2021 at 01:17:02PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 11/4/21 10:36 AM, H. S. Teoh wrote: > > > import __stdin : myversion; > > Where can we learn more of that magic? :) [...] I kinda cheated, because I was the one who implemented dmd's stdin feature, so

Re: How do you declare manifest constants?

2021-11-04 Thread Ali Çehreli via Digitalmars-d-learn
On 11/4/21 10:36 AM, H. S. Teoh wrote: >import __stdin : myversion; Where can we learn more of that magic? :) Ali

Re: How to return a reference to structs?

2021-11-04 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 4 November 2021 at 18:21:06 UTC, Andrey Zherikov wrote: On Thursday, 4 November 2021 at 13:03:54 UTC, Paul Backus wrote: Have the lambda return by reference: ```d auto get() { return idx.map!(ref (i) => a[i]); } ``` Making this example a bit complex: I want `get` to return

Re: How to return a reference to structs?

2021-11-04 Thread Andrey Zherikov via Digitalmars-d-learn
On Thursday, 4 November 2021 at 13:03:54 UTC, Paul Backus wrote: On Thursday, 4 November 2021 at 11:26:30 UTC, Andrey Zherikov wrote: I have the following code example: ```d struct A{} A[5] a; ulong[] idx = [1,3,4]; auto get() { return idx.map!(_ => a[_]); } foreach(i; 0 .. a.length)

Re: How do you declare manifest constants?

2021-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 04, 2021 at 05:24:44PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > On Thursday, 4 November 2021 at 17:09:31 UTC, Steven Schveighoffer wrote: > > D doesn't have any equivalent for this. > > Is it possible to add this feature having `-C VERSION="1.2.3"` (`-D` > is already us

Re: How do you declare manifest constants?

2021-11-04 Thread Andrey Zherikov via Digitalmars-d-learn
On Thursday, 4 November 2021 at 17:09:31 UTC, Steven Schveighoffer wrote: D doesn't have any equivalent for this. Is it possible to add this feature having `-C VERSION="1.2.3"` (`-D` is already used) to be equal to `enum VERSION="1.2.3"` in global namespace? The closest you can get is to t

Re: How do you declare manifest constants?

2021-11-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/4/21 12:43 PM, Andrey Zherikov wrote: I want to embed some info from build system - version info, for example. I can easily do this with C++ compiler by `-DVERSION="1.2.3"` but there is no such an option in dmd. So I'm wondering how do people workaround this? I see only one way: generate

How do you declare manifest constants?

2021-11-04 Thread Andrey Zherikov via Digitalmars-d-learn
I want to embed some info from build system - version info, for example. I can easily do this with C++ compiler by `-DVERSION="1.2.3"` but there is no such an option in dmd. So I'm wondering how do people workaround this? I see only one way: generate a file and add it to the build (file might b

Re: How to return a reference to structs?

2021-11-04 Thread Andrey Zherikov via Digitalmars-d-learn
On Thursday, 4 November 2021 at 13:03:54 UTC, Paul Backus wrote: Have the lambda return by reference: ```d auto get() { return idx.map!(ref (i) => a[i]); } ``` That works, thanks!

Re: How to return a reference to structs?

2021-11-04 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 4 November 2021 at 11:26:30 UTC, Andrey Zherikov wrote: I have the following code example: ```d struct A{} A[5] a; ulong[] idx = [1,3,4]; auto get() { return idx.map!(_ => a[_]); } foreach(i; 0 .. a.length) write(&a[i], " "); writeln; foreach(ref b; get()) write(&b,

How to return a reference to structs?

2021-11-04 Thread Andrey Zherikov via Digitalmars-d-learn
I have the following code example: ```d struct A{} A[5] a; ulong[] idx = [1,3,4]; auto get() { return idx.map!(_ => a[_]); } foreach(i; 0 .. a.length) write(&a[i], " "); writeln; foreach(ref b; get()) write(&b, " "); writeln; ``` How can I change `get` function so it returns the