Re: Derived type

2021-03-30 Thread novice3 via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 21:53:34 UTC, Basile B. wrote: struct Typedef(TBase) { TBase payload; alias payload this; } alias Xobj = Typedef!(void*); This is how std.typecons.Typedef made, IMHO. The problem is this code generate struct with name "Typedef!(void*)", then compiler show

Re: Derived type

2021-03-30 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 19:33:31 UTC, novice2 wrote: On Tuesday, 30 March 2021 at 19:12:29 UTC, Ali Çehreli wrote: "Derived type" is used in the context of object oriented programming at least in D Sorry, i use wrong termin. I just want create new type Tnew, based on exist type Tbase. Tne

Re: Derived type

2021-03-30 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 19:47:41 UTC, novice2 wrote: My tries to make template for struct and alias this: // variant 1 template Typedef(alias Tnew, Tbase) { struct Tnew { Tbase payload; alias payload this; } } you must give a name to the template specialization, using a

Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn
My tries to make template for struct and alias this: // variant 1 template Typedef(alias Tnew, Tbase) { struct Tnew { Tbase payload; alias payload this; } } Typedef!(Xobj, void*); void foo (Xobj obj) {} //compiler Error: no identifier for declarator Typedef!(Xobj, void*)

Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 19:12:29 UTC, Ali Çehreli wrote: "Derived type" is used in the context of object oriented programming at least in D Sorry, i use wrong termin. I just want create new type Tnew, based on exist type Tbase. Tnew have same allowed values, same properties, same allowed

Re: Derived type

2021-03-30 Thread Ali Çehreli via Digitalmars-d-learn
On 3/30/21 6:28 AM, novice3 wrote: > I want create derived type in D "Derived type" is used in the context of object oriented programming at least in D but your examples indicate you need something else. How about the 'alias this' feature? import std.stdio; struct Xobj { void* value; al

Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 14:45:12 UTC, WebFreak001 wrote: Xobj can then be used interchangeably with void*, so all void* arguments accept Xobj and all Xobj arguments accept void*. yes, i understand alias, and i dont want such behaviour If you want a type-safe alias that makes all void* ar

Re: Derived type

2021-03-30 Thread novice2 via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 13:43:52 UTC, Mike Parker wrote: the straightforward way is just to use an alias. i cant use alias - compiler cannot distinguish base type and alias, and cannot catch programmer errors Buf if you need a more concrete type, you can use alias this in a struct: I

Re: Windows Console and writing Unicode characters

2021-03-30 Thread Luhrel via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 13:19:02 UTC, Adam D. Ruppe wrote: On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote: I have been used this trick in C++, so it might also work in D: If you follow through the link that's what I mention as being a bad idea and provide the code given as a mor

Re: Derived type

2021-03-30 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 14:45:12 UTC, WebFreak001 wrote: When i adapt C code, i see new type creation: The typedef in C in D is just an alias: ``` alias Xobj = void*; ``` I totally overlooked the part about porting from C. Yes, this is the way to go in that case.

Re: Derived type

2021-03-30 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 13:28:55 UTC, novice3 wrote: Hello. When i adapt C code, i see new type creation: typedef void* Xobj; Or code like this: struct _Xobj; typedef struct _Xobj *Xobj; I want create derived type in D, found std.typecons.Typedef template, and write: alias Xobj

Re: Derived type

2021-03-30 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 13:28:55 UTC, novice3 wrote: This messages dont help me understand, which type should i use. What i should change? Or Typedef template should be changes? From the docs: "Unlike the alias feature, Typedef ensures the two types are not considered as equals. Param

Re: How to parse JSON in D?

2021-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/21 3:05 AM, Imperatorn wrote: On Monday, 29 March 2021 at 18:19:35 UTC, Steven Schveighoffer wrote: On 3/29/21 1:48 PM, Imperatorn wrote: On Monday, 29 March 2021 at 17:21:25 UTC, tastyminerals wrote: [...] https://youtu.be/un-bZdyumog?t=27m25s FYI that package is here: https://cod

Derived type

2021-03-30 Thread novice3 via Digitalmars-d-learn
Hello. When i adapt C code, i see new type creation: typedef void* Xobj; Or code like this: struct _Xobj; typedef struct _Xobj *Xobj; I want create derived type in D, found std.typecons.Typedef template, and write: alias Xobj = Typedef!(void*, (void*).init); But compiler use long ty

Re: Windows Console and writing Unicode characters

2021-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote: I have been used this trick in C++, so it might also work in D: If you follow through the link that's what I mention as being a bad idea and provide the code given as a more correct alternative. It changes a global (well to the console

Re: Windows Console and writing Unicode characters

2021-03-30 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote: I have been used this trick in C++, so it might also work in D: ``` import core.stdc.stdlib; import std.stdio; void main() { version(Windows) system("chcp 65001 > NUL".ptr); writeln("çéäö"); } ``` Works like a charm in

Re: Windows Console and writing Unicode characters

2021-03-30 Thread Luhrel via Digitalmars-d-learn
On Monday, 29 March 2021 at 02:12:57 UTC, Brad wrote: I am new here so I will post this in Learn. I have been doing a bit of reading on printing unicode characters in the Windows Console. Specifically W10 command prompt. I ran across a post by Adam Ruppe in a thread created a couple years a

Re: Creating a .di file for a custom C library

2021-03-30 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 04:01:12 UTC, Brad wrote: I would like to use an updated version of the Termbox library (written in C) with D. I have the .h file. This is new territory for me (why try something easy - right?). I think I need to create a .di file that corresponds to the .h file.

Re: Creating a .di file for a custom C library

2021-03-30 Thread Chris Piker via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 04:01:12 UTC, Brad wrote: I would like to use an updated version of the Termbox library (written in C) with D. I have the .h file. This is new territory for me (why try something easy - right?). I think I need to create a .di file that corresponds to the .h file.

Re: Creating a .di file for a custom C library

2021-03-30 Thread evilrat via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 04:01:12 UTC, Brad wrote: I would like to use an updated version of the Termbox library (written in C) with D. I have the .h file. This is new territory for me (why try something easy - right?). I think I need to create a .di file that corresponds to the .h file.

Re: How to parse JSON in D?

2021-03-30 Thread Imperatorn via Digitalmars-d-learn
On Monday, 29 March 2021 at 18:19:35 UTC, Steven Schveighoffer wrote: On 3/29/21 1:48 PM, Imperatorn wrote: On Monday, 29 March 2021 at 17:21:25 UTC, tastyminerals wrote: [...] https://youtu.be/un-bZdyumog?t=27m25s FYI that package is here: https://code.dlang.org/packages/jsoniopipe I re