digitalmars.D.learn - Transparent cast from class to member pointer?
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (25/25) Apr 14 2019 struct IM;
- diniz (6/37) Apr 14 2019 Do you have a clear and correct view of what you want to express, of the...
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (12/48) Apr 14 2019 Well, ok... even it really doesn't matter a lot.
- diniz (4/7) Apr 15 2019 All right! Did not think at this usage case, interfacing with C.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (24/57) Apr 15 2019 'alias this' can do that:
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (9/38) Apr 15 2019 Bingo, I didn't know that I can do an 'alias this' using a function and
- Alex (3/8) Apr 15 2019 Well, as I know, multiple alias this won't work yet...
struct IM; struct C { IM *impl; }; int cInit(C* self); class I { C handler; this(){cInit(&handler);} } Is there a simple way that I can use handler without the address-of operator and automatically get *impl? Something like: class I { C handler; this(){cInit(handler);} } And later can use I in a way like this without having to define/write explicit casts everywhere? someFunc(C* self); I myI; someFunc(myI); -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Apr 14 2019
Le 14/04/2019 à 20:03, Robert M. Münch via Digitalmars-d-learn a écrit :struct IM; struct C {  IM *impl; }; int cInit(C* self); class I {     C handler;     this(){cInit(&handler);} } Is there a simple way that I can use handler without the address-of operator and automatically get *impl? Something like: class I {     C handler;     this(){cInit(handler);} } And later can use I in a way like this without having to define/write explicit casts everywhere? someFunc(C* self); I myI; someFunc(myI);Do you have a clear and correct view of what you want to express, of the application? How does it look (for us), if you replace IM, C, impl, cInit, I, handler, with meaningful (and correctly chosen) terms? -- diniz {la vita e estranj}
Apr 14 2019
On 2019-04-14 20:01:27 +0000, diniz said:Le 14/04/2019 à 20:03, Robert M. Münch via Digitalmars-d-learn a écrit :Well, ok... even it really doesn't matter a lot. IM = Implementaiton Context (C-API) C = Core Context (C-API) I = Implementation D Class The C side requires that *impl is the 1st member in the struct/class whereever it is stored. Hence, the wrapping in a struct and not directly putting it into a D class. -- Robert M. Münch http://www.saphirion.com smarter | better | fasterstruct IM; struct C { IM *impl; }; int cInit(C* self); class I { C handler; this(){cInit(&handler);} } Is there a simple way that I can use handler without the address-of operator and automatically get *impl? Something like: class I { C handler; this(){cInit(handler);} } And later can use I in a way like this without having to define/write explicit casts everywhere? someFunc(C* self); I myI; someFunc(myI);Do you have a clear and correct view of what you want to express, of the application? How does it look (for us), if you replace IM, C, impl, cInit, I, handler, with meaningful (and correctly chosen) terms?
Apr 14 2019
Le 15/04/2019 à 08:30, Robert M. Münch via Digitalmars-d-learn a écrit :The C side requires that *impl is the 1st member in the struct/class whereever it is stored. Hence, the wrapping in a struct and not directly putting it into a D class.All right! Did not think at this usage case, interfacing with C. -- diniz {la vita e estranj}
Apr 15 2019
On 04/14/2019 11:03 AM, Robert M. Münch wrote:struct IM; struct C {  IM *impl; }; int cInit(C* self); class I {     C handler;     this(){cInit(&handler);} } Is there a simple way that I can use handler without the address-of operator and automatically get *impl? Something like: class I {     C handler;     this(){cInit(handler);} } And later can use I in a way like this without having to define/write explicit casts everywhere? someFunc(C* self); I myI; someFunc(myI);'alias this' can do that: struct IM; struct C { IM *impl; }; int cInit(C* self) { return 0; } class I { C handler; this(){cInit(&handler);} C* ptr() { // <== ADDED return &handler; } alias ptr this; // <== ADDED } void someFunc(C* self) { } void main() { I myI = new I(); someFunc(myI); } Ali
Apr 15 2019
On 2019-04-15 08:19:57 +0000, Ali ‡ehreli said:'alias this' can do that:Hi, I had the suspicion already...struct IM; struct C { IM *impl; }; int cInit(C* self) { return 0; } class I { C handler; this(){cInit(&handler);} C* ptr() { // <== ADDED return &handler; } alias ptr this; // <== ADDED } void someFunc(C* self) { } void main() { I myI = new I(); someFunc(myI); }Bingo, I didn't know that I can do an 'alias this' using a function and not only a type... pretty cool. So, with several of these I can setup implicit conversions to different types. Thanks. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Apr 15 2019
On Monday, 15 April 2019 at 15:07:10 UTC, Robert M. Münch wrote:On 2019-04-15 08:19:57 +0000, Ali ‡ehreli Bingo, I didn't know that I can do an 'alias this' using a function and not only a type... pretty cool. So, with several of these I can setup implicit conversions to different types. Thanks.Well, as I know, multiple alias this won't work yet... https://wiki.dlang.org/DIP66
Apr 15 2019