Re: Create alias of same name in inner scope, bug or feature?

2021-08-13 Thread Tejas via Digitalmars-d-learn
On Saturday, 14 August 2021 at 04:01:31 UTC, Mike Parker wrote: On Saturday, 14 August 2021 at 03:47:05 UTC, Tejas wrote: ```d import std; auto abc(T)(auto ref T a, auto ref T b){ return a+b; } auto def(T)(auto ref T a, auto ref T b){ return a*b; } alias macro_1 = abc; void main()

Re: Create alias of same name in inner scope, bug or feature?

2021-08-13 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 14 August 2021 at 03:47:05 UTC, Tejas wrote: ```d import std; auto abc(T)(auto ref T a, auto ref T b){ return a+b; } auto def(T)(auto ref T a, auto ref T b){ return a*b; } alias macro_1 = abc; void main() { writeln(macro_1(15, 20)); alias macro_1 = def;// is

Create alias of same name in inner scope, bug or feature?

2021-08-13 Thread Tejas via Digitalmars-d-learn
```d import std; auto abc(T)(auto ref T a, auto ref T b){ return a+b; } auto def(T)(auto ref T a, auto ref T b){ return a*b; } alias macro_1 = abc; void main() { writeln(macro_1(15, 20)); alias macro_1 = def;// is this NOT considered variable shadowing?

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Mike Parker via Digitalmars-d-learn
On Friday, 13 August 2021 at 21:36:35 UTC, Ruby The Roobster wrote: Thank you very much. The program runs successfully now. You've got another potential issue you should be aware of. You've name a member of your `Skeleton` as `init`. This may cause issues at some point, as every type in

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Mike Parker via Digitalmars-d-learn
On Friday, 13 August 2021 at 21:10:38 UTC, Steven Schveighoffer wrote: Well, subtracting the length doesn't do much, you aren't actually accessing the array block, you are just changing the reference (which lives in thread-local storage). I kind of feel like the whole entity table thing is

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 13, 2021 at 04:35:54PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 8/13/21 4:23 PM, Marcone wrote: > > > string x = "Hello World!"; > > writeln(x[x.indexOf("e")..x.indexOf("r")]); > > I don't see the usefulness and there are the following problems with > it: > > - Not an

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/13/21 7:23 PM, Marcone wrote: On Friday, 13 August 2021 at 23:08:07 UTC, jfondren wrote: On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something other than an exact

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Marcone via Digitalmars-d-learn
On Friday, 13 August 2021 at 23:21:42 UTC, Ali Çehreli wrote: On 8/13/21 4:08 PM, jfondren wrote: On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something other than an exact

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Ali Çehreli via Digitalmars-d-learn
On 8/13/21 4:23 PM, Marcone wrote: > string x = "Hello World!"; > writeln(x[x.indexOf("e")..x.indexOf("r")]); I don't see the usefulness and there are the following problems with it: - Not an algorithmic complexity issue but it sounds to me like a pessimization to go through the elements in

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Paul Backus via Digitalmars-d-learn
On Friday, 13 August 2021 at 23:23:55 UTC, Marcone wrote: writeln("Hello World!"[x.indexOf("e")..x.indexOf("r")]); indexOf()is just a simple example, not the goal. I want handle literal inside [] like it bellow, but in literal: string x = "Hello World!";

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread jfondren via Digitalmars-d-learn
On Friday, 13 August 2021 at 23:23:55 UTC, Marcone wrote: On Friday, 13 August 2021 at 23:08:07 UTC, jfondren wrote: On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Marcone via Digitalmars-d-learn
On Friday, 13 August 2021 at 23:08:07 UTC, jfondren wrote: On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something other than an exact "lit"[0..this.xx(..)] syntax is fine?

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Ali Çehreli via Digitalmars-d-learn
On 8/13/21 4:08 PM, jfondren wrote: On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something other than an exact "lit"[0..this.xx(..)] syntax is fine? What didn't you like about

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread jfondren via Digitalmars-d-learn
On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something other than an exact "lit"[0..this.xx(..)] syntax is fine? What didn't you like about `"Hello

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 13 August 2021 at 21:10:38 UTC, Steven Schveighoffer wrote: On 8/13/21 3:59 PM, Mike Parker wrote: On Friday, 13 August 2021 at 16:18:06 UTC, Ruby The Roobster wrote: ... ... ... Well, subtracting the length doesn't do much, you aren't actually accessing the array block, you

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Marcone via Digitalmars-d-learn
On Friday, 13 August 2021 at 21:47:22 UTC, Steven Schveighoffer wrote: On 8/13/21 5:05 PM, Marcone wrote: How to extend the string class to return this inside the square bracket the same way opDollar $ returns the length of the string? Thank you.     import std;     void main(){    

Re: I do not understand copy constructors

2021-08-13 Thread Paul Backus via Digitalmars-d-learn
On Friday, 13 August 2021 at 21:34:29 UTC, Steven Schveighoffer wrote: But for constructors it's not the same. Essentially because constructors have different rules for what they can do with their inputs (the inout `this` parameter can be assigned to for the member's first assignment). What

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/13/21 5:05 PM, Marcone wrote: How to extend the string class to return this inside the square bracket the same way opDollar $ returns the length of the string? Thank you.     import std;     void main(){     writeln("Hello World!"[0..this.indexOf("o")]);     } There is no

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 13 August 2021 at 19:59:46 UTC, Mike Parker wrote: You aren't supposed to be manipulating GC-managed memory via class destructors. You can not rely on that memory being valid at the time that it's accessed in the destructor---the object may already have been destroyed.

Re: I do not understand copy constructors

2021-08-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/13/21 4:58 PM, Paul Backus wrote: On Friday, 13 August 2021 at 15:26:15 UTC, Steven Schveighoffer wrote: The issue is that you can't convert const (or immutable or mutable) to inout implicitly, and the member variable is inout inside an inout constructor. Therefore, there's no viable copy

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Marcone via Digitalmars-d-learn
On Friday, 13 August 2021 at 21:14:29 UTC, user1234 wrote: On Friday, 13 August 2021 at 21:05:22 UTC, Marcone wrote: How to extend the string class to return this inside the square bracket the same way opDollar $ returns the length of the string? Thank you. import std; void main(){

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread user1234 via Digitalmars-d-learn
On Friday, 13 August 2021 at 21:05:22 UTC, Marcone wrote: How to extend the string class to return this inside the square bracket the same way opDollar $ returns the length of the string? Thank you. import std; void main(){ writeln("Hello World!"[0..this.indexOf("o")]); }

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/13/21 3:59 PM, Mike Parker wrote: On Friday, 13 August 2021 at 16:18:06 UTC, Ruby The Roobster wrote: Context for this: I am creating a module of my  own, and this is a class contained in the module.  You will notice that after calling this class' constructor anywhere in a Win32 API

How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Marcone via Digitalmars-d-learn
How to extend the string class to return this inside the square bracket the same way opDollar $ returns the length of the string? Thank you. import std; void main(){ writeln("Hello World!"[0..this.indexOf("o")]); }

Re: I do not understand copy constructors

2021-08-13 Thread Paul Backus via Digitalmars-d-learn
On Friday, 13 August 2021 at 15:26:15 UTC, Steven Schveighoffer wrote: The issue is that you can't convert const (or immutable or mutable) to inout implicitly, and the member variable is inout inside an inout constructor. Therefore, there's no viable copy constructor to call for the member,

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Mike Parker via Digitalmars-d-learn
On Friday, 13 August 2021 at 16:18:06 UTC, Ruby The Roobster wrote: Context for this: I am creating a module of my own, and this is a class contained in the module. You will notice that after calling this class' constructor anywhere in a Win32 API program, that the program doesn't close

Re: Anyway to achieve the following

2021-08-13 Thread pilger via Digitalmars-d-learn
On Friday, 13 August 2021 at 19:06:17 UTC, JG wrote: Anyway I hope it is clearer what I mean. Is it possible to do this in d? union S { int x; int a; } void main() { S s= S(1234); writeln(s.a); //displays 1234 s.x = s.x+1; writeln(s.a); //displays 1235 s.a = s.a +1;

Re: Anyway to achieve the following

2021-08-13 Thread JG via Digitalmars-d-learn
On Friday, 13 August 2021 at 17:19:43 UTC, H. S. Teoh wrote: On Fri, Aug 13, 2021 at 05:11:50PM +, Rekel via Digitalmars-d-learn wrote: [...] For anyone more experienced with C, I'm not well known with references but are those semantically similar to the idea of using a type at a

Re: Anyway to achieve the following

2021-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 13, 2021 at 05:11:50PM +, Rekel via Digitalmars-d-learn wrote: [...] > For anyone more experienced with C, I'm not well known with references > but are those semantically similar to the idea of using a type at a > predefined location? References are essentially pointers under the

Re: Anyway to achieve the following

2021-08-13 Thread Rekel via Digitalmars-d-learn
On Friday, 13 August 2021 at 09:10:18 UTC, Tejas wrote: On Friday, 13 August 2021 at 08:25:33 UTC, JG wrote: Suppose one has a pointer p of type T*. Can on declare variable a of type T which is stored in the location pointed to by p? Umm is this what you want? ```d import std.stdio; struct S

Building a unittest executable for a dub Library

2021-08-13 Thread Rekel via Digitalmars-d-learn
I found a this thread about testing libraries: https://forum.dlang.org/post/mailman.1807.1522279261.3374.digitalmars-d-le...@puremagic.com But it's very old, yet I have the same issue today. I want to build a unittest executable for the library I've made, but given I'm trying to use the vscode

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 13 August 2021 at 03:05:22 UTC, Mike Parker wrote: On Friday, 13 August 2021 at 00:30:59 UTC, Ruby The Roobster wrote: When I run the program and close the window, the program still runs in background mode. I don't know why this happens nor how to fix it. Does anybody know

Re: aliasing functions with function arguments as well ??

2021-08-13 Thread james.p.leblanc via Digitalmars-d-learn
On Friday, 13 August 2021 at 15:14:00 UTC, Steven Schveighoffer wrote: There isn't a way to alias it. You can wrap it though, and hope the inliner takes care of the difference: ```d auto foo(T)(T arg) { static if(is(T == int)) return bar(arg, 42.33); else return bar(7, arg); } ```

Re: I do not understand copy constructors

2021-08-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/12/21 12:12 PM, Paul Backus wrote: The reason for this is a bit subtle. Normally, `inout` can convert to `const`, so you might expect that the `const` copy constructor could be used to construct a copy of an `inout` object. However, copy constructors take their arguments by `ref`, and

Re: aliasing functions with function arguments as well ??

2021-08-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/13/21 11:04 AM, james.p.leblanc wrote: Dear All, How does one use 'alias' to incorporate function arguments as well? (I believe this is possible, from some of the examples of aliasSeq, and the traits.Parameters documentation.  However, I was unable to come up with anything that works.)

aliasing functions with function arguments as well ??

2021-08-13 Thread james.p.leblanc via Digitalmars-d-learn
Dear All, How does one use 'alias' to incorporate function arguments as well? (I believe this is possible, from some of the examples of aliasSeq, and the traits.Parameters documentation. However, I was unable to come up with anything that works.) What should replace the question marks

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 13 August 2021 at 03:05:22 UTC, Mike Parker wrote: On Friday, 13 August 2021 at 00:30:59 UTC, Ruby The Roobster wrote: When I run the program and close the window, the program still runs in background mode. I don't know why this happens nor how to fix it. Does anybody know

Re: Help with Win32: PostQuitMessage(0) doesn't post WM_QUIT apparently, because the message loop is not exited.

2021-08-13 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 13 August 2021 at 03:05:22 UTC, Mike Parker wrote: On Friday, 13 August 2021 at 00:30:59 UTC, Ruby The Roobster wrote: When I run the program and close the window, the program still runs in background mode. I don't know why this happens nor how to fix it. Does anybody know

Re: Anyway to achieve the following

2021-08-13 Thread Paul Backus via Digitalmars-d-learn
On Friday, 13 August 2021 at 09:30:25 UTC, Ali Çehreli wrote: (core.lifetime is not on dlang.org at the moment for me but it is under /usr/include/dmd/druntime/import/core on my computer.) It's also on dpldocs.info: https://dpldocs.info/experimental-docs/core.lifetime.html

Re: Anyway to achieve the following

2021-08-13 Thread Ali Çehreli via Digitalmars-d-learn
On 8/13/21 1:25 AM, JG wrote: > Suppose one has a pointer p of type T*. > Can on declare variable a of type T which is stored in the location > pointed to by p? You may be looking for core.lifetime.emplace. (core.lifetime is not on dlang.org at the moment for me but it is under

Re: Anyway to achieve the following

2021-08-13 Thread Tejas via Digitalmars-d-learn
On Friday, 13 August 2021 at 08:25:33 UTC, JG wrote: Suppose one has a pointer p of type T*. Can on declare variable a of type T which is stored in the location pointed to by p? As an example if we have: struct S { int x = 1234; } void main() { S s;

Anyway to achieve the following

2021-08-13 Thread JG via Digitalmars-d-learn
Suppose one has a pointer p of type T*. Can on declare variable a of type T which is stored in the location pointed to by p? As an example if we have: struct S { int x = 1234; } void main() { S s; //unknown construction of a using &(s.x) writeln(a);