Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Tejas via Digitalmars-d-learn
On Wednesday, 18 August 2021 at 05:33:13 UTC, james.p.leblanc wrote: On Tuesday, 17 August 2021 at 20:28:20 UTC, Alexandru Ermicioi wrote: On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote: Wow! That is absolutely beautiful ... I had never seen (or even imagined) a recursive

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 18 August 2021 at 05:33:13 UTC, james.p.leblanc wrote: If I wanted to ensure that a function accepts only arguments of byte, int, uint, long, etc. (i.e. integer-like types). Is the accepted way to do this like so?: **auto foo( T : long )(T a, T b){ ... }** I very much prefer

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread james.p.leblanc via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 20:28:20 UTC, Alexandru Ermicioi wrote: On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote: Wow! That is absolutely beautiful ... I had never seen (or even imagined) a recursive template! This expands my mind in a good way ... and is going into m

Re: Concurrency message passing

2021-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/21 2:36 PM, JG wrote: Thanks for the suggestions and explanations. I am not sure what to do in my case though. The situation is as follows. I have a struct that is populated via user input not necessarily at single instance (so that seems to rule out immutable). On the other hand while

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 20:29:51 UTC, james.p.leblanc wrote: So, below is my code: import std.stdio; import std.meta : AliasSeq; template isAmong(T, S...) { static if (S.length == 0) enum isAmong = false; else enum isAmong = is(T == S) || isAmong(T, S[1..$]); } alias My

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 17, 2021 at 07:53:52PM +, james.p.leblanc via Digitalmars-d-learn wrote: > On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote: > > You could use a helper template and an AliasSeq for this: > > > > template isAmong(T, S...) { > > static if (S.length == 0)

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread james.p.leblanc via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 20:13:59 UTC, Paul Backus wrote: FYI: in this particular case, you can use std.meta.staticIndexOf instead of writing the recursion out yourself: import std.meta: staticIndexOf; enum isAmong(T, S...) = staticIndexOf!(T, S) >= 0; Docs: https://phobos.dpldo

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote: Wow! That is absolutely beautiful ... I had never seen (or even imagined) a recursive template! This expands my mind in a good way ... and is going into my toolbox immediately. Best Regards, James Just don't over rely on it.

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc wrote: On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote: You could use a helper template and an AliasSeq for this: template isAmong(T, S...) { static if (S.length == 0) enum

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread james.p.leblanc via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote: You could use a helper template and an AliasSeq for this: template isAmong(T, S...) { static if (S.length == 0) enum isAmong = false; else enum

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 17, 2021 at 07:22:54PM +, james.p.leblanc via Digitalmars-d-learn wrote: [...] > auto moo(T : (int || float || mySpecialStruct )(T myMoo) {•••} > > When re-using any such sets, it would be nice to define the set as > follows: > > S = (int || float || mySpecialStruct) > > and the

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread james.p.leblanc via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 18:28:53 UTC, Steven Schveighoffer wrote: On 8/17/21 2:11 PM, james.p.leblanc wrote: Evening All, [Template constraints](https://dlang.org/spec/template.html#template_constraints). -Steve Dear All, Thanks! I was aware of, and have used template constraints

Re: Concurrency message passing

2021-08-17 Thread Ali Çehreli via Digitalmars-d-learn
On 8/17/21 11:36 AM, JG wrote: >>> Maybe message parsing isn't the >>> correct solution? I use message passing in many of my programs. > After being populated it should be passed to > the other thread and no references are kept. Then you simply cast to-and-from 'shared' and be happy with it. :

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Ali Çehreli via Digitalmars-d-learn
On 8/17/21 2:59 AM, Rekel wrote: > template TFoo(T){ void foo(){writeln("1");} } // #1 > template TFoo(T : T[]) { void foo(){writeln("2");} } // #2 I don't have such problems because I am not smart enough to understand that syntax so I don't use it. :) I use template constraints (which

Re: Concurrency message passing

2021-08-17 Thread JG via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:24:14 UTC, Steven Schveighoffer wrote: On 8/17/21 7:05 AM, JG wrote: Hi I have a program with two threads. One thread produces data that is put in a queue and then consumed by the other thread. I initially built a custom queue to do this, but thought this shou

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/21 2:11 PM, james.p.leblanc wrote: Evening All, Eponymous templates allow a nice calling syntax.  For example, "foo" here can be called without needing the exclamation mark (!) at calling sites.  We see that foo is restricting a, and b to be of the same type ... so far, so good. auto

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Ali Çehreli via Digitalmars-d-learn
On 8/17/21 11:11 AM, james.p.leblanc wrote: > auto foo(T)(T a, T b) { ... } > > Now, suppose I need to restrict "T" only certain subsets of variable types. There are template constraints: import std.traits; auto foo(T)(T a, T b) if (isArray!T) { // ... } auto foo(T)(T a, T b) if (isFloati

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/21 2:07 PM, Rekel wrote: On Tuesday, 17 August 2021 at 16:24:38 UTC, Steven Schveighoffer wrote: All these are calling with array literals, which default to dynamic arrays, not static arrays. I realise that is their default, though in this scenario they should (I believe) be used as

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 17, 2021 at 06:11:56PM +, james.p.leblanc via Digitalmars-d-learn wrote: > Evening All, > > Eponymous templates allow a nice calling syntax. For example, "foo" > here can be called without needing the exclamation mark (!) at calling > sites. We see that foo is restricting a, and

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 18:11:56 UTC, james.p.leblanc wrote: Is there a more elegant way, to do this? Regards, James PS Any violations should be caught at compile time. That is template specialization: ``` auto moo(T : YourSpecialClassOrDType)(T myMoo) {•••} ``` You can also declare o

simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread james.p.leblanc via Digitalmars-d-learn
Evening All, Eponymous templates allow a nice calling syntax. For example, "foo" here can be called without needing the exclamation mark (!) at calling sites. We see that foo is restricting a, and b to be of the same type ... so far, so good. auto foo(T)(T a, T b) { ... } Now, suppose I n

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Rekel via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 16:24:38 UTC, Steven Schveighoffer wrote: void foo(T:U[L], uint L)(T a){...} This is an invalid specification, what is U? Did you mean: Yes, sorry typo in the forum. void foo(T: U[L], U, uint L)(T a) {...} void foo(T:U[L][L], uint L)(T a){...} // Never matche

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/21 10:20 AM, Rekel wrote: As my post was not the actual cause of my issue (my apology for the mistake), I think I have found the actual reason I'm currently having problems. This seems to be related to a (seeming, I might be wrong) inability to specialize over both 1d and 2d arrays sepa

Re: Anyway to achieve the following

2021-08-17 Thread Rekel via Digitalmars-d-learn
On Saturday, 14 August 2021 at 20:50:47 UTC, Carl Sturtivant wrote: ``` struct S { int x = 1234; } void main() { import std.stdio; S s; //construction of a using &(s.x) auto a = Ref!(int)(&s.x); writeln(a); //displays 1234 s.x += 1; writeln(a); //displays 1235 a += 1;

Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 13:14:44 UTC, Steven Schveighoffer wrote: On 8/17/21 8:21 AM, Ferhat Kurtulmuş wrote: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.tr

Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:49:02 UTC, drug wrote: 17.08.2021 15:21, Ferhat Kurtulmuş пишет: [...] https://dlang.org/library/std/range/primitives/element_type.html Yes, that is neat. Thank you.

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Rekel via Digitalmars-d-learn
As my post was not the actual cause of my issue (my apology for the mistake), I think I have found the actual reason I'm currently having problems. This seems to be related to a (seeming, I might be wrong) inability to specialize over both 1d and 2d arrays separately. (If constraining the lengt

Re: Union member positions?

2021-08-17 Thread Dennis via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 13:46:22 UTC, z wrote: Is it possible to set a "position" on a union member? You can use anonymous `struct` and `union` blocks. ```D union UnionExample{ uint EAX; struct { //upper union { ushort EAHX; struct {

Re: Union member positions?

2021-08-17 Thread ag0aep6g via Digitalmars-d-learn
On 17.08.21 15:46, z wrote: Is it possible to set a "position" on a union member? or is there is a language-integrated equivalent? For example, to get access to each byte in an unsigned integer while still supporting the original type. ```D ///a single uint that would be accessed as two ushort,

Union member positions?

2021-08-17 Thread z via Digitalmars-d-learn
Is it possible to set a "position" on a union member? or is there is a language-integrated equivalent? For example, to get access to each byte in an unsigned integer while still supporting the original type. ```D ///a single uint that would be accessed as two ushort, or four separate ubyte uni

Re: How to get element type of a slice?

2021-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/21 8:21 AM, Ferhat Kurtulmuş wrote: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution something like ElementTypeOf!

Re: How to get element type of a slice?

2021-08-17 Thread drug via Digitalmars-d-learn
17.08.2021 15:21, Ferhat Kurtulmuş пишет: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution something like ElementTypeOf!T.

Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:32:45 UTC, Paul Backus wrote: On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searche

Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:26:36 UTC, jfondren wrote: On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: [...] This one's not in std.traits: ```d import std.range : ElementType; struct Point { int x, y; } unittest { Point[] points; assert(is(ElementType!(typeo

Re: How to get element type of a slice?

2021-08-17 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution somet

Re: How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:26:36 UTC, jfondren wrote: On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: [...] This one's not in std.traits: ```d import std.range : ElementType; struct Point { int x, y; } unittest { Point[] points; assert(is(ElementType!(typeo

Re: How to get element type of a slice?

2021-08-17 Thread jfondren via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution somet

How to get element type of a slice?

2021-08-17 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution something like ElementTypeOf!T. Is there any neater solution for it? Than

Re: Concurrency message passing

2021-08-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/17/21 7:05 AM, JG wrote: Hi I have a program with two threads. One thread produces data that is put in a queue and then consumed by the other thread. I initially built a custom queue to do this, but thought this should have some standard solution in D? I looked at std.concurrency and tho

Re: Concurrency message passing

2021-08-17 Thread jfondren via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 11:05:09 UTC, JG wrote: Hi I have a program with two threads. One thread produces data that is put in a queue and then consumed by the other thread. I initially built a custom queue to do this, but thought this should have some standard solution in D? I looked at

Concurrency message passing

2021-08-17 Thread JG via Digitalmars-d-learn
Hi I have a program with two threads. One thread produces data that is put in a queue and then consumed by the other thread. I initially built a custom queue to do this, but thought this should have some standard solution in D? I looked at std.concurrency and thought that message passing coul

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Rekel via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 10:21:39 UTC, Mike Parker wrote: We do have a paid Issue/Pull-Request manager now (Razvan Nitu), and he's prioritizing issues for strike teams composed of volunteers willing to fix them. If you find a specific bug that is a blocker or a major headache, make a post

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Rekel via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 10:14:07 UTC, Mike Parker wrote: The error is in your code. Both of your `foo` templates are implemented to print `"1"`. Change the second one to print "2" and you will see the desired output. I keep managing to disappoint myself greatly... this is absurd, so sor

Re: Anyway to achieve the following

2021-08-17 Thread Johan via Digitalmars-d-learn
On Monday, 16 August 2021 at 19:30:19 UTC, JG wrote: On Sunday, 15 August 2021 at 21:53:14 UTC, Carl Sturtivant wrote: On Sunday, 15 August 2021 at 07:10:17 UTC, JG wrote: [...] What you are asking for are reference variables. C++ has them: the example here illustrates the behavior you want.

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 09:59:53 UTC, Rekel wrote: time in the future. Even bugs don't seem to get fixed in any timely manner (Not meant as an insult, just being realistic :/). We do have a paid Issue/Pull-Request manager now (Razvan Nitu), and he's prioritizing issues for strike teams

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 09:59:53 UTC, Rekel wrote: When using implicit function templates, identical specialization yield different results. Example: ```d template TFoo(T){ void foo(){writeln("1");} } // #1 template TFoo(T : T[]) { void foo(){writeln("2");} } // #2 void foo(T)()

Non-consistent implicit function template specializations

2021-08-17 Thread Rekel via Digitalmars-d-learn
When using implicit function templates, identical specialization yield different results. Example: ```d template TFoo(T){ void foo(){writeln("1");} } // #1 template TFoo(T : T[]) { void foo(){writeln("2");} } // #2 void foo(T)(){ writeln("1"); } void foo(T : T[])(){ wr

Re: Nondeterministic unittest debugging problem.

2021-08-17 Thread Rekel via Digitalmars-d-learn
On Monday, 16 August 2021 at 22:01:21 UTC, russhy wrote: remove the .dub folder and try again, as stated in other reply, might be a cache issue, or something that picks an outdated file in the cache Thanks, I'll try that, sadly clear didn't seem to fix it.