Re: How to implement this?

2022-04-08 Thread Elvis Zhou via Digitalmars-d-learn
On Friday, 8 April 2022 at 09:08:07 UTC, Stanislav Blinov wrote: On Friday, 8 April 2022 at 05:53:03 UTC, Elvis Zhou wrote: assumeNoEscapeOrWhatever!DynamicArray structs; structs ~= cast(A*)&b; is it possible? That's what `@trusted` is for. And that's also why it should be

Re: How to implement this?

2022-04-07 Thread Elvis Zhou via Digitalmars-d-learn
On Friday, 8 April 2022 at 05:46:56 UTC, Elvis Zhou wrote: On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote: [...] I know where the issue comes from, dynamic array is GCed and save the reference of a local variable in GCed memory is not allowed, but here structs is assumed to not

Re: How to implement this?

2022-04-07 Thread Elvis Zhou via Digitalmars-d-learn
On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote: struct A {} struct B { A a; } struct C { A a; } A*[] structs; B b; init(&b); structs ~= cast(A*)&b; //Error: copying `cast(A*)& b` into allocated memory escapes a reference to local variable `b` C c; init(&c); struc

How to implement this?

2022-04-07 Thread Elvis Zhou via Digitalmars-d-learn
struct A {} struct B { A a; } struct C { A a; } A*[] structs; B b; init(&b); structs ~= cast(A*)&b; //Error: copying `cast(A*)& b` into allocated memory escapes a reference to local variable `b` C c; init(&c); structs ~= cast(A*)&c; //Error: copying `cast(A*)& c` into allocated memory escap

Re: Uncaught exception while running redis-pubsub-example of vibe.d

2014-04-15 Thread Elvis Zhou
On Tuesday, 15 April 2014 at 10:53:42 UTC, Rikki Cattermole wrote: On Monday, 14 April 2014 at 10:30:53 UTC, Elvis Zhou wrote: Running ./redis-pubsub-example Callback subscribe(["test1"]) Task terminated with uncaught exception: expected of $ or * The error message gives no hint of

Uncaught exception while running redis-pubsub-example of vibe.d

2014-04-14 Thread Elvis Zhou
Running ./redis-pubsub-example Callback subscribe(["test1"]) Task terminated with uncaught exception: expected of $ or * The error message gives no hint of where the exception is raised.How do you guys debug this type of error?

Re: Linker error: Symbol Undefined

2013-10-13 Thread Elvis Zhou
On Friday, 11 October 2013 at 22:33:31 UTC, Namespace wrote: On Friday, 11 October 2013 at 21:16:38 UTC, Brad Roberts wrote: It's due to having the destructor versioned out when building foo and visible when building bar. When brought together, you've created an incompatible whole. There's no

Re: Begining with D

2013-10-13 Thread Elvis Zhou
On Sunday, 13 October 2013 at 11:45:39 UTC, Elvis Zhou wrote: On Thursday, 10 October 2013 at 18:56:58 UTC, Alejandro wrote: Hi I'm new in D, have some experience in JavaScript and PHP, and learned, for long time ago, C and a bit little C++ I remember that when I learned C with co

Re: Begining with D

2013-10-13 Thread Elvis Zhou
On Thursday, 10 October 2013 at 18:56:58 UTC, Alejandro wrote: Hi I'm new in D, have some experience in JavaScript and PHP, and learned, for long time ago, C and a bit little C++ I remember that when I learned C with console output, it was two easy ways to catch input : one witch a required

Re: How to implement this?

2013-06-11 Thread Elvis
On Monday, 10 June 2013 at 14:40:05 UTC, Kenji Hara wrote: On Monday, 10 June 2013 at 09:42:56 UTC, Elvis wrote: class A { enum TypeID = 1; } class B : A { enum TypeID = 2; } class C : A { enum TypeID = 3; } class D : B { enum TypeID = 4; } ... Could anybody shed some light on

How to implement this?

2013-06-10 Thread Elvis
class A { enum TypeID = 1; } class B : A { enum TypeID = 2; } class C : A { enum TypeID = 3; } class D : B { enum TypeID = 4; } ... Could anybody shed some light on how to make these TypeIDs auto increment at compile time?

Re: test if object is instance of class at compile time

2011-12-22 Thread Elvis Maehren
Timon Gehr wrote: > On 12/21/2011 09:15 PM, Elvis Maehren wrote: [...] >> Moreover, in CTFE a failed cast terminates the interpretation ("cannot >> reinterpret class from [...] to [...] at compile time"). > > I don't think this is filed already. Maybe you want

Re: test if object is instance of class at compile time

2011-12-22 Thread Elvis Maehren
Jacob Carlborg wrote: > On 2011-12-21 21:15, Elvis Maehren wrote: >> This works fine at runtime, but explodes in CTFE: >> --- >> bool isInstanceOf(T, O)(O o) { >> return (cast(T) o) !is null; >> } >> --- >> [...] > I don't think you can do

Re: test if object is instance of class at compile time

2011-12-22 Thread Elvis Maehren
Vladimir Panteleev wrote: > I believe that's what __traits(compiles, ...) is for: __traits(compiles, cast(T) o) is true even if the cast blows up in CTFE, so that doesn't work.

test if object is instance of class at compile time

2011-12-21 Thread Elvis Maehren
This works fine at runtime, but explodes in CTFE: --- bool isInstanceOf(T, O)(O o) { return (cast(T) o) !is null; } --- CTFE doesn't like "!is null" ("cannot compare [...] at compile time"). Moreover, in CTFE a failed cast terminates the interpretation ("cannot reinterpret class from [.