Re: Why is "delete" unsafe?

2020-09-23 Thread Elronnd via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 04:15:51 UTC, mw wrote: What do you mean by saying "it's definitely not safe" here? I mean: if I'm careful and know what I'm doing, e.g. remove all the reference to any part of the `object` before call core.memory.GC.free(object), is there still any inherit

Re: Why private methods cant be virtual?

2020-09-23 Thread ShadoLight via Digitalmars-d-learn
On Tuesday, 22 September 2020 at 11:39:31 UTC, Daniel Kozak wrote: On Tue, Sep 22, 2020 at 1:30 PM ShadoLight via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: This is not really "overriding", it is more akin to "overloading" No it is not overloading, overloading is w

Re: Building LDC runtime for a microcontroller

2020-09-23 Thread Dylan Graham via Digitalmars-d-learn
On Friday, 18 September 2020 at 07:44:50 UTC, Dylan Graham wrote: On Monday, 7 September 2020 at 19:12:59 UTC, aberba wrote: On Monday, 7 September 2020 at 16:18:00 UTC, IGotD- wrote: On Monday, 7 September 2020 at 15:23:28 UTC, Severin Teona wrote: [...] Use betterC, which is much better su

Re: Building LDC runtime for a microcontroller

2020-09-23 Thread Denis Feklushkin via Digitalmars-d-learn
Wow, I have just received a link to this topic from my colleague. Here is also another thread about druntime for MCUs: https://forum.dlang.org/post/cwtkntyjhrwvpahfk...@forum.dlang.org

Re: Building LDC runtime for a microcontroller

2020-09-23 Thread Dylan Graham via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 10:02:58 UTC, Dylan Graham wrote: On Friday, 18 September 2020 at 07:44:50 UTC, Dylan Graham wrote: On Monday, 7 September 2020 at 19:12:59 UTC, aberba wrote: On Monday, 7 September 2020 at 16:18:00 UTC, IGotD- wrote: On Monday, 7 September 2020 at 15:23:28 UT

Re: Escape this in pure members

2020-09-23 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 00:06:38 UTC, DlangUser38 wrote: Hmm, why would `b` have longer lifetime? Isn't the lifetime of `b` throughout `bar`? The following analysis might be wrong but I think that `scope` as a **member** function attribute is not supposed to be used as that is not

Re: Escape this in pure members

2020-09-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.09.20 02:06, DlangUser38 wrote: The following analysis might be wrong but I think that `scope` as a **member** function attribute is not supposed to be used as that is not even documented. It's documented here: https://dlang.org/spec/memory-safe-d.html#scope-return-params Quote: "[`scop

Re: Timeout around function call

2020-09-23 Thread drathier via Digitalmars-d-learn
On Tuesday, 22 September 2020 at 21:55:51 UTC, Imperatorn wrote: On Tuesday, 22 September 2020 at 09:32:13 UTC, drathier wrote: What's the obvious way to put a timeout around a function call? I'm thinking a 5 or 30 second timeout, and I'm expecting it to pretty much never time out. You have s

Is it possible to "overload" based on visibility?

2020-09-23 Thread 60rntogo via Digitalmars-d-learn
There are really two questions here, one that I intended to ask and one that came out while I was trying to figure out the answer. Consider this simple code: --- module foo; struct Foo { private int _x; int x() const { return _x; } } --- If I have an instance of Foo outside of th

How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
I have some similar functions: void register(C: IFoo)() { _insert!C(); } void register(C)() if (behavesLikeFoo!C) { _insert!C(); } There are more overloads with parameters so I want to merge them void register(C, ARGS...)(ARGS args) if (behavesLikeFoo!C || isInstanceOf!(C, IFoo)) { _in

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:37:45 UTC, wjoe wrote: I have some similar functions: void register(C: IFoo)() { _insert!C(); } void register(C)() if (behavesLikeFoo!C) { _insert!C(); } There are more overloads with parameters so I want to merge them void register(C, ARGS...)(ARGS a

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread H. S. Teoh via Digitalmars-d-learn
Try this: interface I {} class C : I {} class D {} struct S {} pragma(msg, is(C : I)); // true pragma(msg, is(D : I)); // false pragma(msg, is(S : I)); // false So probably what you want is something like this: void register(C, ARG

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:50:28 UTC, H. S. Teoh wrote: Try this: interface I {} class C : I {} class D {} struct S {} pragma(msg, is(C : I)); // true pragma(msg, is(D : I)); // false pragma(msg, is(S : I)); // false So probabl

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:49:28 UTC, data pulverizer wrote: On Wednesday, 23 September 2020 at 18:37:45 UTC, wjoe wrote: [...] A class at compile time is it's own static type, OOP polymorphism is a runtime feature not compile time. You have to write your own traits for specific o

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:56:33 UTC, wjoe wrote: It doesn't occur to me that the compiler doesn't know at compile time that interface IFoo{} class Foo: IFoo {} class Foo implements interface IFoo. Didn't think that the compiler didn't know but wasn't aware that you could use t

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 23, 2020 at 07:08:47PM +, data pulverizer via Digitalmars-d-learn wrote: > On Wednesday, 23 September 2020 at 18:56:33 UTC, wjoe wrote: > > > > It doesn't occur to me that the compiler doesn't know at compile > > time that > > > > interface IFoo{} > > class Foo: IFoo {} > > > >

Re: Is it possible to "overload" based on visibility?

2020-09-23 Thread aliak via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:38:53 UTC, 60rntogo wrote: There are really two questions here, one that I intended to ask and one that came out while I was trying to figure out the answer. Consider this simple code: [...] Yeah, you can make a property setter: private void x(int newVa

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:08:47 UTC, data pulverizer wrote: On Wednesday, 23 September 2020 at 18:56:33 UTC, wjoe wrote: [...] Didn't think that the compiler didn't know but wasn't aware that you could use that information to statically dispatch. My mistake, I'll shut up now! A

Re: Is it possible to "overload" based on visibility?

2020-09-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/23/20 2:38 PM, 60rntogo wrote: So my questions are: 1. Can I achieve my original goal of being able to refer to _x by one name, so that I have read only access from outside the module and read/write access from inside? I would guess no. You have to use different names. 2. Is the behavi

Re: Is it possible to "overload" based on visibility?

2020-09-23 Thread aliak via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:27:13 UTC, Steven Schveighoffer wrote: This is a bug in the language. 🤯😆

Re: Is it possible to "overload" based on visibility?

2020-09-23 Thread 60rntogo via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:26:43 UTC, aliak wrote: Yeah, you can make a property setter: private void x(int newValue) { _x = newValue } I'm aware of this, but it does not achieve what I asked for. It only allows me to assign to _x, it doesn't give me a reference to x, so I cannot

Re: How to implement fastcall ?

2020-09-23 Thread Denis Feklushkin via Digitalmars-d-learn
On Monday, 21 September 2020 at 11:14:06 UTC, Виталий Фадеев wrote: How to implement fastcall ? ( stdcall is calling convention for pass function arguments via registers ) Hypothesis: it is possible what LLVM + Link Time Optimization does by this way.

Re: How to implement fastcall ?

2020-09-23 Thread kinke via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:50:13 UTC, Denis Feklushkin wrote: On Monday, 21 September 2020 at 11:14:06 UTC, Виталий Фадеев wrote: How to implement fastcall ? ( stdcall is calling convention for pass function arguments via registers ) Hypothesis: it is possible what LLVM + Link Time

Re: Timeout around function call

2020-09-23 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 17:33:50 UTC, drathier wrote: On Tuesday, 22 September 2020 at 21:55:51 UTC, Imperatorn wrote: [...] Blocking is perfectly fine. I'm wondering if I need things to be shared now or something? Not used to programming with threads. Adding a shared modifier rec

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:16:13 UTC, H. S. Teoh wrote: Of course the compiler knows. And of course it can use this information for static dispatch. That's why D is so awesome at metaprogramming. ;-) What the compiler *doesn't* know is whether a variable of some supertype of Foo

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:27:13 UTC, wjoe wrote: Appologies if you took offense. Your replies are very much appreciated. No offense taken.

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 20:19:04 UTC, data pulverizer wrote: This has prompted me to write a data structure that I thought would be impossible until now. [...SNIP...] Here is the function with the correct template constraint: ``` auto makeChain(Args...)(Args args) if(Args.length > 2

Re: Timeout around function call

2020-09-23 Thread Ali Çehreli via Digitalmars-d-learn
On 9/23/20 1:19 PM, Imperatorn wrote: > No. You should not share anything. Personally I would just send a > message to request termination or use the solution provided with timeout. std.concurrency does not allow "mutable thread-local data"; so one needs to cast to shared (assuming copying is n

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 20:19:04 UTC, data pulverizer wrote: This has prompted me to write a data structure that I thought would be impossible until now False alarm: ``` writeln("typeof(x.next): ", typeof(x.next).stringof); ``` gives: ``` typeof(x.next): const(Node) ``` Oh wel

Re: Timeout around function call

2020-09-23 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 20:44:51 UTC, Ali Çehreli wrote: On 9/23/20 1:19 PM, Imperatorn wrote: > [...] send a > [...] with timeout. [...] Sorry, I can't see the problem. Could you be more specific about what you want to achieve?

Re: Timeout around function call

2020-09-23 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 20:54:51 UTC, Imperatorn wrote: On Wednesday, 23 September 2020 at 20:44:51 UTC, Ali Çehreli wrote: On 9/23/20 1:19 PM, Imperatorn wrote: > [...] send a > [...] with timeout. [...] Sorry, I can't see the problem. Could you be more specific about what you w

Re: Why is "delete" unsafe?

2020-09-23 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 04:15:51 UTC, mw wrote: On Saturday, 27 October 2012 at 01:08:12 UTC, Jonathan M Davis wrote: Yes. But using core.memory.GC.free is unsafe for the same reasons that delete is. It's just that it's a druntime function instead of a part of the language, so it's l

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread Otávio Augusto via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:37:45 UTC, wjoe wrote: I have some similar functions: void register(C: IFoo)() { _insert!C(); } void register(C)() if (behavesLikeFoo!C) { _insert!C(); } There are more overloads with parameters so I want to merge them void register(C, ARGS...)(ARGS a