evenChunks on a string - hasLength constraint fails?

2023-03-14 Thread amarillion via Digitalmars-d-learn
Hey I'm trying to split a string down the middle. I thought the function std.range.evenChunks would be perfect for this: ``` #!/usr/bin/env -S rdmd -I.. import std.range; void main() { string line = "abcdef"; auto parts = evenChunks(line, 2); assert(parts == ["abc", "

Re: Best way to read/write Chinese (GBK/GB18030) files?

2023-03-14 Thread Kagamin via Digitalmars-d-learn
On Monday, 13 March 2023 at 00:32:07 UTC, zjh wrote: Thank you for your reply, but is there any way to output `gbk` code to the console? I guess if your console is in gbk encoding, you can just write bytes with stdout.write.

Better way to compromise on the lack of template alias resolution stuff?

2023-03-14 Thread Elfstone via Digitalmars-d-learn
```D struct Matrix(S, size_t M, size_t N) { } alias Vector(S, size_t N) = Matrix!(S, N, 1); enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it doesn't work enum isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t N); // the "correct" way and how much I like to REPEAT myself!

Re: Best way to read/write Chinese (GBK/GB18030) files?

2023-03-14 Thread zjh via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 09:20:54 UTC, Kagamin wrote: I guess if your console is in gbk encoding, you can just write bytes with stdout.write. Thank you for your reply, but only display bytes, not gbk text.

Re: Better way to compromise on the lack of template alias resolution stuff?

2023-03-14 Thread ionkare via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote: ```D struct Matrix(S, size_t M, size_t N) { } alias Vector(S, size_t N) = Matrix!(S, N, 1); enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it doesn't work enum isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t N);

Re: #define-like behavior

2023-03-14 Thread Jeremy via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 06:20:29 UTC, Mike Parker wrote: On Tuesday, 14 March 2023 at 05:47:35 UTC, Jeremy wrote: [...] Manifest constants in D have a similar effect as #defined values, e.g.: [...] Thanks a lot!

Re: evenChunks on a string - hasLength constraint fails?

2023-03-14 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 08:21:00 UTC, amarillion wrote: I'm trying to understand why this doesn't work. I don't really understand the error. If I interpret this correctly, it's missing a length attribute on a string, but shouldn't length be there? By default, D's standard library treats

Re: @nogc and Phobos

2023-03-14 Thread bomat via Digitalmars-d-learn
Thanks a lot for taking the time and replying in that much detail! On Saturday, 11 March 2023 at 21:07:18 UTC, H. S. Teoh wrote: I also came from a C/C++ background. The GC turned me off D for a long time, until one day I decided to just give it a try to see if it was all as bad as people made

Re: @nogc and Phobos

2023-03-14 Thread bomat via Digitalmars-d-learn
On Saturday, 11 March 2023 at 22:14:36 UTC, rempas wrote: The `foreach` will cover your needs like you said but ironically enough, I like and use the original `for` loop. Thanks for your reply as well, rempas... I guess I covered most things in my earlier reply, but on the `for` loop: Coming f

Re: Better way to compromise on the lack of template alias resolution stuff?

2023-03-14 Thread Elfstone via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 17:57:38 UTC, ionkare wrote: On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote: ```D struct Matrix(S, size_t M, size_t N) { } alias Vector(S, size_t N) = Matrix!(S, N, 1); enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it doesn't work enum is