Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) { auto opDispatch(T, Args...)(Args args) { ... } } [...] NOTE: opDispatch suppresses internal compile errors, it will

Re: Nice readable code with initializer

2020-03-06 Thread Виталий Фадеев via Digitalmars-d-learn
On Thursday, 5 March 2020 at 07:01:27 UTC, Виталий Фадеев wrote: On Thursday, 5 March 2020 at 06:48:53 UTC, Виталий Фадеев wrote: Searching for beauty code implementation. Goal is: Create new object with "custom initializer". "custom initializer" - is function, executed in _ctor, in object

Re: DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-06 Thread Basile B. via Digitalmars-d-learn
On Friday, 6 March 2020 at 04:56:28 UTC, Marcone wrote: Is it possible change compile time errors to runtime errors in Dlang? no If yes, how can I make it? if you deactivate all the errors emitted during the semantic then there are very good chance that the compiler crashes while

Re: Safe cast

2020-03-06 Thread Виталий Фадеев via Digitalmars-d-learn
On Friday, 6 March 2020 at 12:35:29 UTC, Виталий Фадеев wrote: Searching info for object casting with checking class type at runtime. Like this: class A { // } class B { int bVar; } unittest { A a = new A(); A x = cast( A )a; // ok A x = cast( B )a; // ok, but

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 March 2020 at 11:51:54 UTC, wjoe wrote: I don't understand this error message. Which type can't be resolved? I don't know. It works if you rename the inner one but it doesn't like eponymous templates like this. I suspect either the spec subtly doesn't allow it or a compiler

Safe cast

2020-03-06 Thread Виталий Фадеев via Digitalmars-d-learn
Searching info for object casting with checking class type at runtime. Like this: class A { // } class B { int bVar; } unittest { A a = new A(); A x = cast( A )a; // ok A x = cast( B )a; // ok, but unsafe A x = safeCast( B )a; // throw exception A x =

Re: DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-06 Thread Marcone via Digitalmars-d-learn
On Friday, 6 March 2020 at 05:31:57 UTC, Mathias Lang wrote: On Friday, 6 March 2020 at 04:56:28 UTC, Marcone wrote: Is it possible change compile time errors to runtime errors in Dlang? If yes, how can I make it? No it's not possible, D is a statically typed language. Why would you want

Re: Safe cast

2020-03-06 Thread drug via Digitalmars-d-learn
It's too complex On 3/6/20 3:45 PM, Виталий Фадеев wrote: On Friday, 6 March 2020 at 12:35:29 UTC, Виталий Фадеев wrote: Searching info for object casting with checking class type at runtime. Like this: class A {     // } class B {     int bVar; } unittest {     A a = new A();     A x =

Re: Safe cast

2020-03-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 March 2020 at 13:03:22 UTC, drug wrote: Here x will be null. You can use `enforce(x !is null);` if you want exception. or since enforce returns it thing, just do B b = enforce(cast(B) x); you can also check easily in if statements: if(auto b = cast(B) x) { // x was a b, use

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 6:51 AM, wjoe wrote: On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) {     auto opDispatch(T, Args...)(Args args) {    ...     } } [...] NOTE: opDispatch suppresses

Re: DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 8:59 AM, Marcone wrote: On Friday, 6 March 2020 at 05:31:57 UTC, Mathias Lang wrote: On Friday, 6 March 2020 at 04:56:28 UTC, Marcone wrote: Is it possible change compile time errors to runtime errors in Dlang? If yes, how can I make it? No it's not possible, D is a statically

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 8:55 AM, Steven Schveighoffer wrote: Instantiate!(f.opDispatch!fname, Bitmap)("path/to/wallpaper.png") I realized, this doesn't work. Because f.opDispatch is a `this` call, but is not called that way in this case. Adam's way doesn't work either, because the call doesn't use the

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?! so yeah just kinda screwed. I'd probably suggest at tis point

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 March 2020 at 15:05:56 UTC, wjoe wrote: But didn't like the string part and that's when I introduced the alias fn because I figured maybe it's possible to do something like: factory.dispatch!(Bitmap.load)(handle, path); and get the Bitmap part from that alias and hence save the

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 13:55:25 UTC, Steven Schveighoffer wrote: On 3/6/20 6:51 AM, wjoe wrote: On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) {     auto opDispatch(T,

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 9:42 AM, Steven Schveighoffer wrote: alias opdispatch(T) = other_name!(name, T); And obviously, this should be opDispatch with a capital D ! -Steve

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 9:14 AM, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?! so yeah just kinda

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 14:14:04 UTC, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?!

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 15:19:39 UTC, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 15:05:56 UTC, wjoe wrote: But didn't like the string part and that's when I introduced the alias fn because I figured maybe it's possible to do something like: factory.dispatch!(Bitmap.load)(handle,

Re: DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-06 Thread Ali Çehreli via Digitalmars-d-learn
On 3/6/20 5:59 AM, Marcone wrote:> On Friday, 6 March 2020 at 05:31:57 UTC, Mathias Lang wrote: > I'm coming from Python The fact that errors are delayed until run time is a Python deficiency. We accept that deficiency because we also accept claimed benefits that Python brings. If you want

Re: Converting Lua source to D

2020-03-06 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 5 March 2020 at 16:54:35 UTC, AB wrote: I am only guessing, but I think the problem is line 87. Arrays and slices in D contain a length field and thus do not need to be null terminated. The foreach at line 96 iterates on all valid indices and thus in the last iteration you call