Re: Why does Unconst exist?
On 7/27/21 10:38 PM, Tejas wrote: When I initially saw it, I was hopeful that it would allow me to bypass some of the restrictions of ```const``` , but it literally just takes a type and strips the ```const``` from it, you can't pass a variable to it in order to get rid of ```const``` . What use does it serve then? https://dlang.org/library/std/traits/unconst.html Searching under /usr/include/dmd reveals that it is used in the implementations of array property 'dup' and 'copyEmplace', which makes sense: We want copies to be mutable. Ali
Why does Unconst exist?
When I initially saw it, I was hopeful that it would allow me to bypass some of the restrictions of ```const``` , but it literally just takes a type and strips the ```const``` from it, you can't pass a variable to it in order to get rid of ```const``` . What use does it serve then? https://dlang.org/library/std/traits/unconst.html
Re: Performance issue with fiber
On Monday, 26 July 2021 at 12:09:07 UTC, hanabi1224 wrote: Thank you for your response! I've got some questions tho. On Saturday, 24 July 2021 at 09:17:47 UTC, Stefan Koch wrote: It will not use a fiber pool. Why fiber pool? Isn't fiber a lightweight logical thread which is already implemented with thread pool internally? Spawning fiber is expensive (but not so expensive as spawning thread, of course), but switching is fast. Thus, you can spawn and pause "workers" fibers for avaiting of jobs. (Probably, this behaviour is already implemented in number of libraries and it isn't actually need to implement another one.)
Re: POST request with std.net.curl
On Monday, 26 July 2021 at 19:53:05 UTC, frame wrote: All better the lib could do is to print the text for the status too and the raw payload sent by the server aka error description, if any. That's what I'm proposing. Currently std.net.curl's post function doesn't report all the information sent by the server, while curl at the command line does.
Re: Is there a "nice" way to access the names of template parameters outside?
On Tuesday, 27 July 2021 at 10:15:51 UTC, Lukas Borin wrote: On Tuesday, 27 July 2021 at 09:31:07 UTC, Paul Backus wrote: On Tuesday, 27 July 2021 at 08:15:12 UTC, Lukas Borin wrote: Consider the following template ```D auto foo(T, int W, int H)(T p1, T p2) { } ``` Is there a "nice" way from the outside the get the names of the template values? As far as I'm aware there is no way to introspect on template parameters at all. Let's say i instantiate the template does that change anything? Can I get the "placeholder" names in any way then? I don't think instantiating it changes anything. The underlying issue is that `is(symbol == __parameters)` doesn't work on templates.
Re: Is there a "nice" way to access the names of template parameters outside?
On Tuesday, 27 July 2021 at 09:31:07 UTC, Paul Backus wrote: On Tuesday, 27 July 2021 at 08:15:12 UTC, Lukas Borin wrote: Consider the following template ```D auto foo(T, int W, int H)(T p1, T p2) { } ``` Is there a "nice" way from the outside the get the names of the template values? As far as I'm aware there is no way to introspect on template parameters at all. Let's say i instantiate the template does that change anything? Can I get the "placeholder" names in any way then?
Re: Is there a "nice" way to access the names of template parameters outside?
On Tuesday, 27 July 2021 at 08:15:12 UTC, Lukas Borin wrote: Consider the following template ```D auto foo(T, int W, int H)(T p1, T p2) { } ``` Is there a "nice" way from the outside the get the names of the template values? As far as I'm aware there is no way to introspect on template parameters at all.
Is there a "nice" way to access the names of template parameters outside?
Consider the following template ```D auto foo(T, int W, int H)(T p1, T p2) { } ``` Is there a "nice" way from the outside the get the names of the template values? E.g: ```D pragma(msg, TemplateParameterNames!(foo)); // AliasSeq!("T", "W", "H") or ["T", "W", "H"] ``` I know you can find the names values in a very hacky way. (atleast in dmd 2.097.1) ```D template HackyHack(alias T) { enum RawName = T.stringof; enum HackyHack = parseRawName(RawName); // Or templateParse!RawString; } ``` I currently have the HackyHack solution *"working"* but I really don't like it and I would be supprised if it works on other dmd version or other compilers. I know I can do things like: ```D template foo(T, int W, int H) { enum names = ... // some magic with __traits or just assing it to ["T", "W", "H"] auto foo(T p1, T p2) { } } ``` Use template mixins or other solutions to get what I want but if possible I prefer to just introspect on the template. Usecase right now is to do some cuda kernel generation from a D shortfunction. Something like this: ```D @kernel auto saxpy(T, int Iters, int N, int Stride)(T a, T* x, T* y, T* output) => q{ int tid = blockIdx.x * blockDim.x + threadIdx.x; for(int idx = tid, int i = 0; i < Iters && idx < N; ++i, idx += Stride) { output[idx] = a * x[idx] + y[idx]; } }; ``` Would get transformed to: ```D template __global__ void saxpy(T a, T* x, T* y, T* output) { //Identical function body / parameters and template arguments from the @kernel //D function. int tid = blockIdx.x * blockDim.x + threadIdx.x; for(int idx = tid, int i = 0; i < Iters && idx < N; ++i, idx += Stride) { output[idx] = a * x[idx] + y[idx]; } } ``` Really need the names to make this translation, correctly. Just to be clear i'm not interested in getting the arguments a template was instantiated with. I can use TemplateArgsOf!T for that.