Re: AA and struct with const member

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 02:33:08 UTC, frame wrote: On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov wrote: Because opIndexAssign cannot distinguish at compile time between initialization and assignment: ```d Stuff[Key] aa; aa[key] = Stuff(args); // ostensibly,

Re: AA and struct with const member

2021-12-28 Thread frame via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov wrote: Because opIndexAssign cannot distinguish at compile time between initialization and assignment: ```d Stuff[Key] aa; aa[key] = Stuff(args); // ostensibly, initialization aa[key] = otherStuff; // assignment to existing

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:30:30 UTC, Ali Çehreli wrote: On 12/28/21 2:06 PM, Steven Schveighoffer wrote:    void print_num(int mul)(int num) { Wasn't there a way of telling whether an 'auto ref' parameter is copied or not? void print_num()(int num, auto ref int mul) { // ? }

Re: AA and struct with const member

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:46:16 UTC, frame wrote: On Tuesday, 28 December 2021 at 10:02:13 UTC, tsbockman wrote: // Should be a compile-time error, because it might reassign: test[key] = S(value); This might be a typo in your example but why should it be a compile-time error,

Re: opCast + dtor error

2021-12-28 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 18:27:36 UTC, vit wrote: Hi, why this code doesn't compile? ```d struct Foo{ bool opCast(T : bool)()const{ assert(0); } ~this(){} } struct Bar{ const Foo foo; } void main(){ } ``` Error: template instance `opCast!(Foo)` does not

Re: AA and struct with const member

2021-12-28 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 10:02:13 UTC, tsbockman wrote: // Should be a compile-time error, because it might reassign: test[key] = S(value); This might be a typo in your example but why should it be a compile-time error, it cannot know if the key already exists in compile time on

Re: AA and struct with const member

2021-12-28 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 14:48:24 UTC, Era Scarecrow wrote: Probably better to make data private vs making it const. I tend to use const far more as input arguments to help denote it won't change references and less for elements in a struct. That or make it a class? I'm not sure.

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Ali Çehreli via Digitalmars-d-learn
On 12/28/21 2:06 PM, Steven Schveighoffer wrote:    void print_num(int mul)(int num) { Wasn't there a way of telling whether an 'auto ref' parameter is copied or not? void print_num()(int num, auto ref int mul) { // ? } And that would indicate that the argument was an rvalue? I

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread max haughton via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 21:19:29 UTC, rempas wrote: I would like to know if that's possible. Actually I would like to do something like the following: ``` extern (C) void main() { void print_num(int num, comp_time_type int mul) { static if (is(mul == ten)) { printf("%d\n",

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/28/21 4:19 PM, rempas wrote: Here: ``` extern (C) void main() {   void print_num(int mul)(int num) {     static if (is(mul == ten)) {   printf("%d\n", num * 10);     } else static if (is(mul == three)) {   printf("%d\n", num * 3);     } else {   printf("%d\n", num);   

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 21:19:29 UTC, rempas wrote: I would like to know if that's possible. Actually I would like to do something like the following: ``` extern (C) void main() { void print_num(int num, comp_time_type int mul) { static if (is(mul == ten)) { printf("%d\n",

Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread rempas via Digitalmars-d-learn
I would like to know if that's possible. Actually I would like to do something like the following: ``` extern (C) void main() { void print_num(int num, comp_time_type int mul) { static if (is(mul == ten)) { printf("%d\n", num * 10); } else static if (is(mul == three)) {

Re: Starting and managing threads

2021-12-28 Thread Bagomot via Digitalmars-d-learn
Thanks! It works. Perhaps there will still be difficulties, I will write here.

opCast + dtor error

2021-12-28 Thread vit via Digitalmars-d-learn
Hi, why this code doesn't compile? ```d struct Foo{ bool opCast(T : bool)()const{ assert(0); } ~this(){} } struct Bar{ const Foo foo; } void main(){ } ``` Error: template instance `opCast!(Foo)` does not match template declaration `opCast(T : bool)()`

Re: Starting and managing threads

2021-12-28 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 16:29:05 UTC, Bagomot wrote: I can't do it according to your example, my Watcher list fills up at runtime. Yes, it's possible to do it at runtime as well(it already _was_ happening at runtime), although I'll be using a `cast` for convenience now. ```d

Re: Starting and managing threads

2021-12-28 Thread Bagomot via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 15:42:04 UTC, Tejas wrote: On Tuesday, 28 December 2021 at 14:19:46 UTC, Bagomot wrote: On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote: On 12/27/21 1:33 AM, Bagomot wrote: > separate thread, without blocking the main one. I think you can use

Re: Starting and managing threads

2021-12-28 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 14:19:46 UTC, Bagomot wrote: On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote: On 12/27/21 1:33 AM, Bagomot wrote: > separate thread, without blocking the main one. I think you can use std.concurrency there. I have a chapter here:

Re: How to print unicode characters (no library)?

2021-12-28 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 14:53:57 UTC, rempas wrote: On Tuesday, 28 December 2021 at 12:56:11 UTC, Adam D Ruppe wrote: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html and that's not quite full either. it really is a mess from hell Still less complicated and organized

Re: How to print unicode characters (no library)?

2021-12-28 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 13:04:26 UTC, Adam D Ruppe wrote: What is your library? You might be able to just use my terminal.d too My library will be "libd" it will be like "libc" but better and cooler! And it will be native to D! And of course it will not depend on "libc" and it

Re: How to print unicode characters (no library)?

2021-12-28 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 12:56:11 UTC, Adam D Ruppe wrote: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html and that's not quite full either. it really is a mess from hell Still less complicated and organized than my life...

Re: AA and struct with const member

2021-12-28 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 07:51:04 UTC, frame wrote: On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: Success! So i summarize, either work with a pointer, or drop the const... Of course casting the const away was the first thing I did but I think this is not

Re: Starting and managing threads

2021-12-28 Thread Bagomot via Digitalmars-d-learn
On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote: On 12/27/21 1:33 AM, Bagomot wrote: > separate thread, without blocking the main one. I think you can use std.concurrency there. I have a chapter here: http://ddili.org/ders/d.en/concurrency.html Look for 'struct Exit' to

Re: How to print unicode characters (no library)?

2021-12-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 06:51:52 UTC, rempas wrote: That's pretty nice. In this case is even better because at least for now, I will not work on Windows by myself because making the library work on Linux is a bit of a challenge itself. What is your library? You might be able to just

Re: How to print unicode characters (no library)?

2021-12-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 07:03:25 UTC, rempas wrote: I already knew about some of this "escape codes" but I full list of them will come in handy ;) https://invisible-island.net/xterm/ctlseqs/ctlseqs.html and that's not quite full either. it really is a mess from hell

Re: How to print unicode characters (no library)?

2021-12-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 06:46:57 UTC, ag0aep6g wrote: It's actually just the first byte that tells you how many are in the sequence. The continuation bytes don't have redundancies for that. Right, but they do have that high bit set and next bit clear so you can tell you're in the

Re: How to print unicode characters (no library)?

2021-12-28 Thread Patrick Schluter via Digitalmars-d-learn
On Monday, 27 December 2021 at 07:12:24 UTC, rempas wrote: I don't understand that. Based on your calculations, the results should have been different. Also how are the numbers fixed? Like you said the amount of bytes of each encoding is not always standard for every character. Even if they

Re: AA and struct with const member

2021-12-28 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 07:54:56 UTC, frame wrote: On Tuesday, 28 December 2021 at 06:38:03 UTC, Tejas wrote: The workaround is okay, but I think we should file a bug report for this. This is very ~~stupid~~ undesirable behaviour I agree. I'll just wait if somebody can explain why