Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Lance Bachmeier via Digitalmars-d-learn
On Friday, 12 April 2024 at 18:36:13 UTC, Chris Piker wrote: On Saturday, 30 March 2024 at 07:11:49 UTC, Mike Parker wrote: Though I appreciate the sentiment, it's much more effective and efficient for people actually using the feature, and who appreciate it, to write up a blog post about it

Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Lance Bachmeier via Digitalmars-d-learn
On Friday, 12 April 2024 at 18:45:21 UTC, Chris Piker wrote: Even though DMD can't compile some C code, that's pretty much a non-issue for me anyway. In my environment the servers are all Linux so "apt-get" (or equivalent) typically provides a pre-compiled dependency. Being able to list a

Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Chris Piker via Digitalmars-d-learn
On Monday, 1 April 2024 at 02:08:20 UTC, Lance Bachmeier wrote: On Saturday, 30 March 2024 at 05:01:32 UTC, harakim wrote: It works well if you only need to work with a header. There are still a few rough edges that get in the way if you're compiling the full C sources (I filed bugs for all

Re: Best way to use large C library in D as of 2024

2024-04-12 Thread Chris Piker via Digitalmars-d-learn
On Saturday, 30 March 2024 at 07:11:49 UTC, Mike Parker wrote: Though I appreciate the sentiment, it's much more effective and efficient for people actually using the feature, and who appreciate it, to write up a blog post about it somewhere and share that on Twitter/Reddit/HN, etc. I would,

Re: Best way to use large C library in D as of 2024

2024-03-31 Thread Lance Bachmeier via Digitalmars-d-learn
sing C from C and I think you should advertise that better! It works well if you only need to work with a header. There are still a few rough edges that get in the way if you're compiling the full C sources (I filed bugs for all of them): - Can't handle va_arg - Can't cast to a pointer of a st

Re: Best way to use large C library in D as of 2024

2024-03-30 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 30 March 2024 at 05:01:32 UTC, harakim wrote: @D Language Foundation - This is a HUGE selling point. I had to use cups the other day and I just copied some code from a d file and linked the library. It was so easy I was suspicious but it worked. Using C from D is pretty much as

Re: Best way to use large C library in D as of 2024

2024-03-29 Thread harakim via Digitalmars-d-learn
On Tuesday, 26 March 2024 at 20:42:00 UTC, Chris Piker wrote: On Tuesday, 26 March 2024 at 20:19:27 UTC, bachmeier wrote: Should be able to just use it, as described here: https://forum.dlang.org/post/qxctappnigkwvaqak...@forum.dlang.org Create a .c file that includes the header files and

Re: Best way to use large C library in D as of 2024

2024-03-26 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 26 March 2024 at 20:42:00 UTC, Chris Piker wrote: On Tuesday, 26 March 2024 at 20:19:27 UTC, bachmeier wrote: Should be able to just use it, as described here: https://forum.dlang.org/post/qxctappnigkwvaqak...@forum.dlang.org Create a .c file that includes the header files and

Re: Best way to use large C library in D as of 2024

2024-03-26 Thread Chris Piker via Digitalmars-d-learn
On Tuesday, 26 March 2024 at 20:19:27 UTC, bachmeier wrote: Should be able to just use it, as described here: https://forum.dlang.org/post/qxctappnigkwvaqak...@forum.dlang.org Create a .c file that includes the header files and then call the functions you need. Wow. **That just worked the

Re: Best way to use large C library in D as of 2024

2024-03-26 Thread bachmeier via Digitalmars-d-learn
against pre-compiled code. What is the best way, as of 2024 to use this library with D, in particular dmd? ImportC doesn't seem like the go-to option since the C source does not need to be complied. I've seen some forum post indicating that manually generated D wrappers are no longer needed

Best way to use large C library in D as of 2024

2024-03-26 Thread Chris Piker via Digitalmars-d-learn
Hi D I have a C library I use for work, it's maintained by an external organization that puts it through a very through test framework. Though source code is supplied, the intended use is to include the header files and link against pre-compiled code. What is the best way, as of 2024

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-17 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 16 March 2024 at 20:34:57 UTC, Inkrementator wrote: Nice. Btw I vaguely remember you also wrote about how and why to reduce the usage string mixins, with some real example of alternative techniques you used go to the main page: http://dpldocs.info/this-week-in-d/Blog.html and

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-16 Thread Inkrementator via Digitalmars-d-learn
On Saturday, 16 March 2024 at 13:09:13 UTC, Adam D Ruppe wrote: On Thursday, 14 March 2024 at 23:19:37 UTC, Inkrementator wrote: @(__traits(getAttributes, thingYouWantToForward)) void yourNewThing() {} Thanks, that should solve my problem.

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-16 Thread Inkrementator via Digitalmars-d-learn
On Friday, 15 March 2024 at 19:13:38 UTC, cc wrote: This is trivially easy if your types are visible at module level, and mixin is a fine tool for the job. It doesn't work quite so well with [Voldemort types](https://wiki.dlang.org/Voldemort_types). I used the following lines to make it work

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 14 March 2024 at 23:19:37 UTC, Inkrementator wrote: * Is UDA propagation possible without string mixins? @(__traits(getAttributes, thingYouWantToForward)) void yourNewThing() {} * Are template mixins vulnerable to name collisions?

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-15 Thread cc via Digitalmars-d-learn
On Thursday, 14 March 2024 at 23:19:37 UTC, Inkrementator wrote: I am trying to derive a struct from another. I want to modify each field such that type of it goes from some T to Nullable!T, preserving all fieldnames and UDAs. This is trivially easy if your types are visible at module level,

Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-14 Thread Inkrementator via Digitalmars-d-learn
are involved, I can't simply take an alias anymore. The one workaround I found is to make my introspective struct part of a template mixin, this way it can access all symbols of the callsite and can use all the symbols. Is this the recommended way to do it? Generating a string mixin directly would

Re: What's the proper way to add a local file dependence to dub?

2024-01-06 Thread Jim Balter via Digitalmars-d-learn
On Monday, 12 March 2018 at 10:20:20 UTC, Seb wrote: On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote: then copy it to sources folder? let's say I have a small library folder at C:\mylibrary\D where I want to use dir.d from it. How do I add that file dependence to dub? But I do not want

Re: Is there a way to tell LDC2 to only check the syntax of the source file?

2023-12-06 Thread realhet via Digitalmars-d-learn
On Wednesday, 6 December 2023 at 11:53:09 UTC, realhet wrote: Hello, I've found another trick: - prepend "version(none):" in front of the source. - ignore the optional "Error: declaration expected, not `module`" message - Take seriously all the other errors, those are only syntax errors,

Is there a way to tell LDC2 to only check the syntax of the source file?

2023-12-06 Thread realhet via Digitalmars-d-learn
inied__` I know it started to do the semantic analysis, but I wonder if there is a prettier way to do this... ``` __undefinied__ _;void removeCard(Card card) { if(card.shortName !in cardMap) return; /+More code here, also the syntax could be broken. I wan't to detect exactly that.+/ } ```

Re: Does exists some way to define a implementation for a symbol?

2023-11-14 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 13:43:03 UTC, Hipreme wrote: Right now, I've been implementing classes separately, and I need a dummy symbol. The best world is not even having a symbol but having only its implementation, for example, I would like being able to do that: ```d void

Re: is there a way to use sumtype in `switch/case` (with multiple statements)? or how can I get the `tag` and `storage`?

2023-10-07 Thread mw via Digitalmars-d-learn
On Saturday, 7 October 2023 at 19:30:23 UTC, mw wrote: On Saturday, 7 October 2023 at 19:25:51 UTC, mw wrote: Or how can I get the `tag` and `storage` myself? https://github.com/dlang/phobos/blob/a3f22129dd2a134338ca02b79ff0de242d7f016e/std/sumtype.d#L310 If I add this line to the above

Re: is there a way to use sumtype in `switch/case` (with multiple statements)? or how can I get the `tag` and `storage`?

2023-10-07 Thread mw via Digitalmars-d-learn
On Saturday, 7 October 2023 at 19:25:51 UTC, mw wrote: Or how can I get the `tag` and `storage` myself? https://github.com/dlang/phobos/blob/a3f22129dd2a134338ca02b79ff0de242d7f016e/std/sumtype.d#L310 If I add this line to the above func `isF`: ``` writeln(t.tag); ``` it won't compile:

is there a way to use sumtype in `switch/case` (with multiple statements)? or how can I get the `tag` and `storage`?

2023-10-07 Thread mw via Digitalmars-d-learn
https://dlang.org/library/std/sumtype.html seems right now the `match!(...)` template only generate a delegate, e.g. suppose the following (silly) code: ``` bool isF(Temperature t) { while (true) { t.match!( (Fahrenheit f) {return true;}, (_) {return false;} // I want to

Whats the best way to spawn an external process with vibe and process its stdout and stderr

2023-10-07 Thread christian.koestlin via Digitalmars-d-learn
Recently I wanted to wrap a small d program around an external process and stream its stdout/stderr to the original stdout/stderr of the d program (no other output while the external process is running). I first tried to implement this with vibe's fibers, but after failing first try, I

Simple way to get Source Line Table of a compiled module.

2023-07-23 Thread realhet via Digitalmars-d-learn
Hi, I'm using LDC2 64bit on Windows. If I ask it to generate a .map file, I can locate the function. But how can I access the Line-code information? Do I need to generate a huge .pdb file with lots of other information (and also I have to understand it and extract the lines), or is there a

Re: Best way to use C library

2023-05-24 Thread Maximilian Naderer via Digitalmars-d-learn
On Monday, 22 May 2023 at 22:22:50 UTC, Theo wrote: On Friday, 19 May 2023 at 18:31:45 UTC, Maximilian Naderer wrote: .. I’m hope somebody could give me some insights. Thank you ! Kind regards from Austria Max DConf Online '22 - Translating C to D (Dennis Korpel)

Re: Best way to convert between GBK/GB18030 to utf8 ?

2023-05-23 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 23 May 2023 at 02:58:21 UTC, John Xu wrote: What is the best way to convert a GBK/GB18030 file contents, i.e. read via: std.stdio.read(gbkFile).to!string , to utf8 encoding ? https://github.com/lytsing/gbk-utf8/blob/master/utf8.c Here, it is C, but porting this to D is easy

Re: Best way to convert between GBK/GB18030 to utf8 ?

2023-05-23 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 23 May 2023 at 02:58:21 UTC, John Xu wrote: What is the best way to convert a GBK/GB18030 file contents, i.e. read via: std.stdio.read(gbkFile).to!string , to utf8 encoding ? I don't think we have any implementation of that encoding yet. If you decide to make your own, don't

Best way to convert between GBK/GB18030 to utf8 ?

2023-05-22 Thread John Xu via Digitalmars-d-learn
What is the best way to convert a GBK/GB18030 file contents, i.e. read via: std.stdio.read(gbkFile).to!string , to utf8 encoding ?

Re: Best way to use C library

2023-05-22 Thread Theo via Digitalmars-d-learn
On Friday, 19 May 2023 at 18:31:45 UTC, Maximilian Naderer wrote: .. I’m hope somebody could give me some insights. Thank you ! Kind regards from Austria Max DConf Online '22 - Translating C to D (Dennis Korpel) https://www.youtube.com/watch?v=654rSPaIA0o

Re: Best way to use C library

2023-05-22 Thread Guillaume Piolat via Digitalmars-d-learn
On Friday, 19 May 2023 at 18:31:45 UTC, Maximilian Naderer wrote: Hello guys, So what’s currently the best way to use a big C library? Let’s assume something like cglm assimp glfw - Some big libraries are translated, for example https://code.dlang.org/packages/glfw-d was created with both

Re: Best way to use C library

2023-05-19 Thread user456 via Digitalmars-d-learn
On Friday, 19 May 2023 at 18:31:45 UTC, Maximilian Naderer wrote: Hello guys, So what’s currently the best way to use a big C library? Let’s assume something like cglm assimp glfw ImportC doesn’t really work for such huge libraries, I’ll investigate further. Deimos is outdated

Re: Best way to use C library

2023-05-19 Thread jmh530 via Digitalmars-d-learn
On Friday, 19 May 2023 at 18:31:45 UTC, Maximilian Naderer wrote: Hello guys, So what’s currently the best way to use a big C library? Let’s assume something like cglm assimp glfw ImportC doesn’t really work for such huge libraries, I’ll investigate further. Deimos is outdated

Best way to use C library

2023-05-19 Thread Maximilian Naderer via Digitalmars-d-learn
Hello guys, So what’s currently the best way to use a big C library? Let’s assume something like cglm assimp glfw ImportC doesn’t really work for such huge libraries, I’ll investigate further. Deimos is outdated or there are no bindings. I know that there is a dub package for glfw which

Re: Proper way to handle "alias this" deprecation for classes

2023-05-17 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 17 May 2023 at 08:00:17 UTC, Dom DiSc wrote: If you want auto-conversion, you should be more explicit: ```d float opCast() { } ``` because if you return "auto" it is not the highest-prio fit and therefore not chosen. If you have multiple choices, you still don't need to use

Re: Proper way to handle "alias this" deprecation for classes

2023-05-17 Thread Dom DiSc via Digitalmars-d-learn
On Friday, 12 May 2023 at 15:00:48 UTC, Salih Dincer wrote: ```d struct Fraction { int num, den; this(int n, int d) { num = n; den = d; } // Cast Expression : convert float value of fraction auto opCast(T :

Re: Proper way to handle "alias this" deprecation for classes

2023-05-12 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 7 May 2023 at 21:04:05 UTC, Inkrementator wrote: Open question to everybody: What you're opinion on using opCast for this? Since it's a type conversion, it seems fitting to me. Can't converting without explicitly specifying in D is a big shortcoming in my opinion. There is such a

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
ality we gloss over low-level details that will make a big difference in the outcome of the computation in the corner cases. The whole rvalue/lvalue business is really more a way of conveying to the compiler what exactly must happen, rather than directly corresponding to any actual feature in the under

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Chris Piker via Digitalmars-d-learn
On Wednesday, 10 May 2023 at 20:25:48 UTC, H. S. Teoh wrote: On Wed, May 10, 2023 at 07:56:10PM +, Chris Piker via Digitalmars-d-learn wrote: [...] I also suffer from left/right confusion, and always have to pause to think about which is the right(!) word before uttering it. Oh, I though

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
. "Right" in my head > always means "correct". > > My daughter hates it when I'm telling her which way to turn the car > since I've said the wrong direction so many times. :) I also suffer from left/right confusion, and always have to pause to think about which is

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Chris Piker via Digitalmars-d-learn
with the terms lvalue and rvalue is much more basic, and is just a personal one that only affects probably 0.1% of people. I just can't keep left vs. right straight in real life. "Right" in my head always means "correct". My daughter hates it when I'm telling her which way to turn

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 10, 2023 at 03:24:48PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > It's off topic, but I forget why managing memory for rvalues* was > pushed onto the programmer and not handled by the compiler. I'm sure > there is a good reason but it does seem like a symmetry breaking

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Chris Piker via Digitalmars-d-learn
On Wednesday, 10 May 2023 at 14:42:50 UTC, Inkrementator wrote: On Sunday, 7 May 2023 at 21:12:22 UTC, Chris Piker wrote: https://gist.github.com/run-dlang/9b7aec72710b1108fc8277789776962a Thanks for posting that. Reading over the code I'm reminded that I never cared whether something was

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 7 May 2023 at 21:12:22 UTC, Chris Piker wrote: On the other hand, your first suggestion of using opCast() does seem like a reasonable choice to me. Can you provide a short code snippet using opCast to achieve the same result? I've never used it, and particularly I know that I

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/23 13:44, Chris Piker wrote: > to fix the problem I > just delete the alias this line from dpq2, see what unit tests and app > code it breaks, then fix each of those. Yes but I neglected the lvalue/rvalue issue. In some cases the code won't compile if the return type of the newly

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Chris Piker via Digitalmars-d-learn
On Sunday, 7 May 2023 at 21:04:05 UTC, Inkrementator wrote: On Sunday, 7 May 2023 at 18:19:04 UTC, Ali Çehreli wrote: alias this is for implicit type conversions, which can be achieved explicitly as well. Open question to everybody: What you're opinion on using opCast for this? Since it's a

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 7 May 2023 at 18:19:04 UTC, Ali Çehreli wrote: alias this is for implicit type conversions, which can be achieved explicitly as well. Open question to everybody: What you're opinion on using opCast for this? Since it's a type conversion, it seems fitting to me. And another

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Chris Piker via Digitalmars-d-learn
On Sunday, 7 May 2023 at 18:19:04 UTC, Ali Çehreli wrote: auto main() { auto c = new C(); // The same type conversion is now explicit: foo(c.asIntPtr); } Hi Ali Ah, very clear explanation, thanks! So basically to fix the problem I just delete the alias this line from dpq2, see

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/23 10:55, Chris Piker wrote: > According to dmd 2.103, alias this is > deprecated for classes, so I'd like to correct the problem. alias this is for implicit type conversions, which can be achieved explicitly as well. Given the following old code: class C { int* result; alias

Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Chris Piker via Digitalmars-d-learn
Hi D One of the dependencies for my project has a class that makes use of the `alias x this` construct. According to dmd 2.103, alias this is deprecated for classes, so I'd like to correct the problem. Is there a specific paragraph or two that I can read to find out what is the

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

2023-03-22 Thread zjh via Digitalmars-d-learn
On Wednesday, 22 March 2023 at 15:23:42 UTC, Kagamin wrote: https://dlang.org/phobos/std_stdio.html#rawWrite It's really amazing, it succeeded. Thank you! ```cpp auto b="test.txt";//gbk void[]d=read(b); stdout.rawWrite(d); ```

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

2023-03-22 Thread Kagamin via Digitalmars-d-learn
https://dlang.org/phobos/std_stdio.html#rawWrite

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

2023-03-15 Thread Elfstone via Digitalmars-d-learn
On Wednesday, 15 March 2023 at 19:22:32 UTC, Paul Backus wrote: On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote: [...] Currently the best workaround for this is to define `Vector` as a `struct` with `alias this` instead of as an `alias`: ```d struct Matrix(S, size_t M, size_t N)

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

2023-03-15 Thread Paul Backus via Digitalmars-d-learn
the param to be `Vector`? But that's simply the current state: it looks like DIP1023 isn't going anywhere, and I'm not a compiler expert. Note that I had to repeat `Matrix!(S, N, 1)` to for both `Vector` and `isVector`. Is there a way around this?! Currently the best workaround

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

2023-03-15 Thread Elfstone via Digitalmars-d-learn
isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t N); // the "correct" way and how much I like to REPEAT myself! void foo(U)(Vector!(U, 3) a) { } void bar(U)(U a) if (isVector!U) { } void main() { import std.stdio; Vector!(float, 3) v; foo(v); // Error: none of the

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

2023-03-14 Thread ionkare via Digitalmars-d-learn
); // the "correct" way and how much I like to REPEAT myself! void foo(U)(Vector!(U, 3) a) { } void bar(U)(U a) if (isVector!U) { } void main() { import std.stdio; Vector!(float, 3) v; foo(v); // Error: none of the overloads of template `app.doSomething` are callable usin

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.

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 REP

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.

DMD: what's the proper way to get a list of symbols from a Module object?

2023-03-13 Thread ryuukk_ via Digitalmars-d-learn
Hello, I am playing a little bit with DMD to get familiar with it (just to get a basic overview of it) I'm trying to come up with a proof of concept for https://github.com/dlang/DIPs/blob/master/DIPs/DIP1044.md ```D enum Tester { KNOWN = 1, WITHAUTO = 2 } void func(Tester a,

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

2023-03-13 Thread zjh via Digitalmars-d-learn
On Monday, 13 March 2023 at 15:50:37 UTC, Steven Schveighoffer wrote: What is required is an addition to the `std.encoding` module, to allow such an encoding. Thank you for your information.

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

2023-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/12/23 8:32 PM, zjh wrote: On Sunday, 12 March 2023 at 20:03:23 UTC, 0xEAB wrote: ... Thank you for your reply, but is there any way to output `gbk` code to the console? What is required is an addition to the `std.encoding` module, to allow such an encoding. Encodings are simply

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

2023-03-12 Thread zjh via Digitalmars-d-learn
On Sunday, 12 March 2023 at 20:03:23 UTC, 0xEAB wrote: ... Thank you for your reply, but is there any way to output `gbk` code to the console?

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

2023-03-12 Thread 0xEAB via Digitalmars-d-learn
On Sunday, 12 March 2023 at 00:54:53 UTC, zjh wrote: On Saturday, 11 March 2023 at 19:56:09 UTC, 0xEAB wrote: If you desire to use other encodings, how about using ubyte + ubyte[]? There is no example. To read binary data from a file and dump it into another, you do: ```d import std.file

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

2023-03-11 Thread zjh via Digitalmars-d-learn
On Saturday, 11 March 2023 at 19:56:09 UTC, 0xEAB wrote: If you desire to use other encodings, how about using ubyte + ubyte[]? There is no example. An example should be added in an obvious position. I tried for a long time, but couldn't output `gbk`, and I finally gave up.

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

2023-03-11 Thread 0xEAB via Digitalmars-d-learn
On Friday, 10 March 2023 at 07:16:32 UTC, zjh wrote: `D language` is too unfriendly for Chinese users! You can't even write `gbk` files. D’s char + string types are Unicode. To quote the tour, “In D, *all* strings are Unicode strings”. If you desire to use other encodings, how about using

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

2023-03-09 Thread zjh via Digitalmars-d-learn
On Friday, 10 March 2023 at 06:19:38 UTC, zjh wrote: `D language` is too unfriendly for Chinese users! You can't even write `gbk` files.

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

2023-03-09 Thread zjh via Digitalmars-d-learn
On Friday, 10 March 2023 at 02:48:43 UTC, John Xu wrote: ```d module chinese; import std.stdio : writeln; import std.conv; import std.windows.charset; int main(string[] argv) { auto s1 = "中文";//utf8 字符串 writeln("word:"~ s1); //乱的 writeln("word:" ~

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

2023-03-09 Thread John Xu via Digitalmars-d-learn
I found this: https://github.com/meatatt/exCode/blob/master/source/excode/package.d There is mention of unicode/GBK conversion, maybe it could be helpful Thanks for quick answers. Now I found I can read both UTF8 and UTF-16LE chinese file: string txt =

Re: Is there a way to get the name of the current function?

2023-03-07 Thread rempas via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:28:41 UTC, ryuukk_ wrote: ``` import std.stdio; void main() { writeln("file:", __FILE__); writeln("function is: ", __FUNCTION__); writeln("function is: ", __PRETTY_FUNCTION__ ); } $ dmd -run tester.d file:tester.d function is:

Re: Is there a way to get the name of the current function?

2023-03-07 Thread rempas via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:19:22 UTC, JG wrote: Yes, see here: https://dlang.org/spec/expression.html#specialkeywords OMG, so that's when they are located! I was trying to search the spec and find them in different pages but had no luck! Thanks a lot for the help, have a great day!

Re: Is there a way to get the name of the current function?

2023-03-07 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:11:49 UTC, rempas wrote: For example, in the given code: ```d void my_function() { import std.stdio; writeln("The name of the function is: ", ); } ``` Is there something to put in the place of `` to get the name of the function? ``` import std.stdio;

Re: Is there a way to get the name of the current function?

2023-03-07 Thread JG via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:11:49 UTC, rempas wrote: For example, in the given code: ```d void my_function() { import std.stdio; writeln("The name of the function is: ", ); } ``` Is there something to put in the place of `` to get the name of the function? Yes, see here:

Is there a way to get the name of the current function?

2023-03-07 Thread rempas via Digitalmars-d-learn
For example, in the given code: ```d void my_function() { import std.stdio; writeln("The name of the function is: ", ); } ``` Is there something to put in the place of `` to get the name of the function?

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

2023-03-06 Thread ryuukk_ via Digitalmars-d-learn
(also known as LATIN-1), ISO-8859-2 (LATIN-2), WINDOWS-1250, WINDOWS-1251 and WINDOWS-1252." Then what is best way to read GBK/GB18030 contents ? Even GBK/GB18030 file names ? I found this: https://github.com/meatatt/exCode/blob/master/source/excode/package.d There is mention of u

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

2023-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
, ISO-8859-2 (LATIN-2), WINDOWS-1250, WINDOWS-1251 and WINDOWS-1252." It appears that encoding is not supported. There is a scant mention of it, in the BOM detection. But I don't think there's any mechanism to encode/decode it. Then what is best way to read GBK/GB18030 contents ? Even G

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

2023-03-06 Thread John Xu via Digitalmars-d-learn
-1250, WINDOWS-1251 and WINDOWS-1252." Then what is best way to read GBK/GB18030 contents ? Even GBK/GB18030 file names ?

Re: Simplest way to convert an array into a set

2023-02-13 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 13 February 2023 at 18:04:40 UTC, Matt wrote: Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be... Where did you find out that there is no set() in the D programming language? **Simple exampl

Re: Simplest way to convert an array into a set

2023-02-13 Thread ProtectAndHide via Digitalmars-d-learn
On Monday, 13 February 2023 at 18:04:40 UTC, Matt wrote: Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be. I was convinced I'd seen a "unique" method somewhere, but I've looked throu

Re: Simplest way to convert an array into a set

2023-02-13 Thread H. S. Teoh via Digitalmars-d-learn
ng nicer (see below). > but I was wondering what the quickest way to remove duplicates from an > array would be. I was convinced I'd seen a "unique" method somewhere, > but I've looked through the documentation for std.array, std.algorithm > AND std.range, and I've either missed i

Re: Simplest way to convert an array into a set

2023-02-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.02.23 19:04, Matt wrote: Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be. I was convinced I'd seen a "unique" method somewhere, but I've looked through the documentation for std.

Re: Simplest way to convert an array into a set

2023-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/23 1:04 PM, Matt wrote: Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be. I was convinced I'd seen a "unique" method somewhere, but I've looked through the documentation for std.

Simplest way to convert an array into a set

2023-02-13 Thread Matt via Digitalmars-d-learn
Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be. I was convinced I'd seen a "unique" method somewhere, but I've looked through the documentation for std.array, std.algorithm AND std.range, an

Re: Is there a way to get a template’s parameters and constraints?

2023-01-22 Thread Adam Ross Walker via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? Apologies, I missed the key part of your question. But I think the above can be adapted if you were so inclined.

Re: Is there a way to get a template’s parameters and constraints?

2023-01-22 Thread Adam Ross Walker via Digitalmars-d-learn
There is a way but it's horrible. You can take the `.stringof` and parse the result. I knocked this up for something but it's not well tested and there are probably templates that it handles incorrectly. I'm not claiming this is any good, I just happened to have it. ```d enum

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: For what I want, `constraintsOf` may expect every template parameter to be a type and to have a constraint. If I'm not mistaken, the following will help: https://dlang.org/phobos/std_range_primitives.html SDB@79=

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? No, reflection over templates is very limited.

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
For what I want, `constraintsOf` may expect every template parameter to be a type and to have a constraint. No, there is no way to introspect anything about a template's details until its instantiated. -Steve

Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Quirin Schroll via Digitalmars-d-learn
Is there a trait (or a combination of traits) that gives me the constraints of a template? Example: ```D void f(T1 : long, T2 : const(char)[])(T x) { } template constraintsOf(alias templ) { /*Magic here*/ } alias constraints = constraintsOf!f; // tuple(long, const(char)[]) ``` At the moment, I

Re: Is there a way to enforce UFCS?

2023-01-06 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 6 January 2023 at 15:31:09 UTC, Salih Dincer wrote: If you don't want to get the above output you should use the previous example. But don't forget to connect alias and opCall. For example, you can use @property in version 2.0.83 without all the fanfare. I forgot one thing: if

Re: Is there a way to enforce UFCS?

2023-01-06 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 5 January 2023 at 23:05:17 UTC, thebluepandabear wrote: them or remove them. I agree, forbidding function call syntax would be a great usecase for `@property`. It will probably never get implemented though. In older versions, it worked when printing values ​​with writeln.

Re: Is there a way to enforce UFCS?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
them or remove them. I agree, forbidding function call syntax would be a great usecase for `@property`. It will probably never get implemented though.

Re: Is there a way to enforce UFCS?

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
push it through the deprecation process... ... OR come up with a DIP that implements @property in a sane, fully worked out way, not the half-hearted, incomplete, leaky implementation that it is today. // In my own code, I've stopped bothering with @property for the most part. Parenthes

Re: Is there a way to enforce UFCS?

2023-01-05 Thread Dom DiSc via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: ```d class Foo { int bar; void setBar(Foo foo, int value) { foo.bar = value; } } void main() { foo.setBar(100); // Not UFCS - just method call to the class foo.setBar = 100; // Not UFCS - simply a setter function call

Re: Is there a way to enforce UFCS?

2023-01-04 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo

Re: Is there a way to enforce UFCS?

2023-01-04 Thread bauss via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo, int value) { foo.bar = value; } void main

Re: Is there a way to enforce UFCS?

2023-01-03 Thread Ali Çehreli via Digitalmars-d-learn
> d.name("poodle"); I don't see a problem with that. :) > I am disappointed that `@property` does not Many people are disappointed that @property is pretty much useless. > is there a way to enforce D gives us the tools to do that but it's not trivial. The function can retu

Is there a way to enforce UFCS?

2023-01-03 Thread thebluepandabear via Digitalmars-d-learn
ve that it would add to its usefulness. Sometimes throughout my codebase I get confused and write properties in non-UFCS syntax, which bugs me a bit. My question is: is there a way to enforce UFCS-syntax?

Proper way to override (swap) runtime and phobos. [feature request?]

2022-11-23 Thread AnimusPEXUS via Digitalmars-d-learn
for development purposes. is there are correct way to somehow (partially or complete) override druntime and phobos? or, maybe, some code injection/patching mechanisms during compilation of own code.

  1   2   3   4   5   6   7   8   9   10   >