Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread mw via Digitalmars-d-learn
On Sunday, 13 September 2020 at 01:25:43 UTC, mw wrote: On Saturday, 12 September 2020 at 20:29:40 UTC, Paul Backus If you have a "real-life" application in mind for this, I'd be curious to hear what it is. I'm wrapping a C library, trying to write a single D function / template that can

Re: Why does a directly defined constructor hide a mixed-in constructor?

2020-09-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 13 September 2020 at 12:34:06 UTC, 60rntogo wrote: However, if I directly insert the contents of X into Bar instead of mixing it in, it compiles just fine. What's going on here? You can override members from mixin templates by giving a member with the same *name* (not the same

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 07:00:36 UTC, mw wrote: Here it is: D wrapper for https://ta-lib.org/ https://github.com/mingwugmail/talibd I end up using C macro to generate D functions, the single template is this one:

Why does a directly defined constructor hide a mixed-in constructor?

2020-09-13 Thread 60rntogo via Digitalmars-d-learn
This code: --- mixin template X() { int[2] x; this(int[2] x...) { this.x = x; } } struct Foo { } struct Bar { mixin X; this(Foo foo) { this.x = [0, 0]; } } void main() { auto bar = Bar(1, 2); } --- produces the following error: --- source/app.d(27,17): Error:

passing a parrameter read-only ref?

2020-09-13 Thread Martin via Digitalmars-d-learn
Hi, i would like to create a function which takes the first parameter as a reference to a struct - but assure the calle that the reference is read-only. Can this be done? If i am not mistaken, then the "in" Parameter Storage Class is what i want(?). But the documentation states that this

Red-Black Gauss-seidel with mir

2020-09-13 Thread Christoph via Digitalmars-d-learn
Hi all, I am trying to implement a sweep method for a 2D Red-black Gauss-Seidel Solver with the help of mir and its slices. The fastest Version I discovered so far looks like this: ``` void sweep(T, size_t Dim : 2, Color color)(in Slice!(T*, 2) F, Slice!(T*, 2) U, T h2) { const auto m =

Re: Why does a directly defined constructor hide a mixed-in constructor?

2020-09-13 Thread 60rntogo via Digitalmars-d-learn
On Sunday, 13 September 2020 at 13:10:15 UTC, Adam D. Ruppe wrote: This is pretty useful in a lot of cases but kinda annoying with overloading. To overload, you must use `alias` to merge the overload sets. For constructors, you need to use the name `__ctor` instead of `this` to make it

Re: passing a parrameter read-only ref?

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 13:35:15 UTC, Martin wrote: Hi, i would like to create a function which takes the first parameter as a reference to a struct - but assure the calle that the reference is read-only. Can this be done? Yes, you can do this with `ref const`.

Call C variadic function from D variadic function

2020-09-13 Thread James Blachly via Digitalmars-d-learn
Summary: Can a typesafe D variadic function, or D variadic template pass its parameters to a C variadic function? Background: I maintain a library binding [0] to htslib, a high-performance and very widely used C library for high-throughput sequencing (hts) data files. We use this internally

Re: Call C variadic function from D variadic function

2020-09-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/13/20 12:55 PM, James Blachly wrote: Summary: Can a typesafe D variadic function, or D variadic template pass its parameters to a C variadic function? Background: I maintain a library binding [0] to htslib, a high-performance and very widely used C library for high-throughput sequencing

Re: Call C variadic function from D variadic function

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 17:23:42 UTC, Steven Schveighoffer wrote: On 9/13/20 12:55 PM, James Blachly wrote: ```     /// Add a single line to an existing header     auto addLine(T...)(RecordType type, T kvargs)     if(kvargs.length > 0 && isSomeString!(T[0]))     {     static

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread mw via Digitalmars-d-learn
On Sunday, 13 September 2020 at 10:16:46 UTC, Paul Backus wrote: On Sunday, 13 September 2020 at 07:00:36 UTC, mw wrote: Here it is: D wrapper for https://ta-lib.org/ https://github.com/mingwugmail/talibd I end up using C macro to generate D functions, the single template is this one:

Re: Call C variadic function from D variadic function

2020-09-13 Thread ag0aep6g via Digitalmars-d-learn
```     /// Add a single line to an existing header     auto addLine(T...)(RecordType type, T kvargs)     if(kvargs.length > 0 && isSomeString!(T[0]))     {     static assert (kvargs.length %2 == 0);   // K-V pairs => even number of variadic args     string varargMagic(size_t

Re: Call C variadic function from D variadic function

2020-09-13 Thread James Blachly via Digitalmars-d-learn
On 9/13/20 2:35 PM, ag0aep6g wrote: Easy peasy:     import std.meta: Repeat;     Repeat!(kvargs.length, const(char)*) zs;     foreach (i, ref z; zs) z = toStringz(kvargs[i]);     return sam_hdr_add_line(this.h, type.ptr, zs, null); Great, thank you! By the way, `kvargs`

Re: Call C variadic function from D variadic function

2020-09-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/13/20 2:35 PM, Paul Backus wrote: On Sunday, 13 September 2020 at 17:23:42 UTC, Steven Schveighoffer wrote: On 9/13/20 12:55 PM, James Blachly wrote: ``` /// Add a single line to an existing header auto addLine(T...)(RecordType type, T kvargs) if(kvargs.length > 0 &&

Re: Red-Black Gauss-seidel with mir

2020-09-13 Thread 9il via Digitalmars-d-learn
On Sunday, 13 September 2020 at 14:48:30 UTC, Christoph wrote: Hi all, I am trying to implement a sweep method for a 2D Red-black Gauss-Seidel Solver with the help of mir and its slices. The fastest Version I discovered so far looks like this: ``` void sweep(T, size_t Dim : 2, Color color)(in

Re: how to do this meta-programming? print the address of random element's address of a variable length of arrays?

2020-09-13 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 13 September 2020 at 18:24:01 UTC, mw wrote: But, I'd reflect on my experience so far on compile-time meta-programming in D as a novice user, the big problems are: -- in D, there are too many choices, with no clear guideline which one is *THE* one to use for a particular purpose:

Re: Call C variadic function from D variadic function

2020-09-13 Thread mw via Digitalmars-d-learn
Just a observation, from the questions & answers in this thread and mine[1]: I think meta-programming in D is somehow like C++, it starts becoming a baroque language. The language is complex enough that there may be ways to get things done, but it's just quite difficult for ordinary users to

Get enum value name as string at compile time?

2020-09-13 Thread Steven Schveighoffer via Digitalmars-d-learn
Consider the enum: enum Foo { a, b } Foo.a.stringof => "a" enum x = Foo.a; x.stringof => "cast(Foo)0" Is there another way I can take an enum value that's known at compile time (but not the actual identifier), and get the name of it? I know I can use a switch, or to!string. But I was hoping