Re: Template pattern delegate?

2020-10-25 Thread frame via Digitalmars-d-learn
On Sunday, 25 October 2020 at 12:02:10 UTC, Ali Çehreli wrote: On 10/25/20 4:30 AM, frame wrote: Is there a possibility to write templated code / custom trait pattern with usage like a delegate? I have a try-catch block with different types and don't want to repeat myself in every method

Re: Unexpected behaviour using remove on char[]

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 12:29 PM, IGotD- wrote: What I discovered is that remove doesn't really remove size number of bytes but also removed entire multibyte characters and consider that one step. The result was of course that I got out of bounds exceptions as it went past the end. This is the infamous

Unexpected behaviour using remove on char[]

2020-10-25 Thread IGotD- via Digitalmars-d-learn
I have a part in my code that use remove buffer.remove(tuple(0, size)); with char[] buffer What I discovered is that remove doesn't really remove size number of bytes but also removed entire multibyte characters and consider that one step. The result was of course that I got out of bounds

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread Jack via Digitalmars-d-learn
On Friday, 23 October 2020 at 16:42:00 UTC, data pulverizer wrote: Hi all, the `import` function allows a file to be read at compile time, which opens up great opportunities for (mostly binary) file IO, where data types can be coded into files - the user doesn't need to know data types ahead

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread Jack via Digitalmars-d-learn
On Sunday, 25 October 2020 at 12:16:36 UTC, Jacob Carlborg wrote: On 2020-10-23 18:42, data pulverizer wrote: For me it's not make-or-break, it just something very useful and I think has clear use case. Please let me know if there are aspects or alternatives I am missing. You could always

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 25 October 2020 at 12:16:36 UTC, Jacob Carlborg wrote: On 2020-10-23 18:42, data pulverizer wrote: You could always have the build tool split up the file in multiple smaller files and read one of the smaller files with the import expression. Thanks. My current solution is to have

Re: Two ways of receiving arrays on the C ABI

2020-10-25 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-10-20 02:16, Ali Çehreli wrote: Everything works at least on Linux. Is this kosher, or am I using some internal knowledge? Yes, you're using some internal knowledge. You cannot assume it works on any other platform or architecture. In theory, the D compiler could choose to change

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-10-23 18:42, data pulverizer wrote: For me it's not make-or-break, it just something very useful and I think has clear use case. Please let me know if there are aspects or alternatives I am missing. You could always have the build tool split up the file in multiple smaller files and

Re: Template pattern delegate?

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 4:30 AM, frame wrote: Is there a possibility to write templated code / custom trait pattern with usage like a delegate? I have a try-catch block with different types and don't want to repeat myself in every method again. It's always the same, just what's tried changes, eg.:

Re: toStringz lifetime

2020-10-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 October 2020 at 10:03:44 UTC, Ali Çehreli wrote: Is it really safe? Imagine a multi-threaded environment where another D function is executed that triggers a GC collection right before the printf. Does the GC see that local variable 'name' that is on the C side? What I don't

Template pattern delegate?

2020-10-25 Thread frame via Digitalmars-d-learn
Is there a possibility to write templated code / custom trait pattern with usage like a delegate? I have a try-catch block with different types and don't want to repeat myself in every method again. It's always the same, just what's tried changes, eg.: pseudo code: template myStuff(mixin

Re: toStringz lifetime

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 3:19 AM, rikki cattermole wrote: On 25/10/2020 11:03 PM, Ali Çehreli wrote: Does the GC see that local variable 'name' that is on the C side? What I don't know is whether the GC is aware only of the stack frames of D functions or the entire thread, which would include the C

Re: toStringz lifetime

2020-10-25 Thread rikki cattermole via Digitalmars-d-learn
On 25/10/2020 11:03 PM, Ali Çehreli wrote: Does the GC see that local variable 'name' that is on the C side? What I don't know is whether the GC is aware only of the stack frames of D functions or the entire thread, which would include the C caller's 'name'. The thread stack frame that is

toStringz lifetime

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
toStringz documentation is clear on why, when, and how to extend the lifetime of a D string: https://dlang.org/phobos/std_string.html#.toStringz Assume foo is a D library function that passes a "string" result to e.g. C: extern(C) void foo(ref const(char) * name) { name =

Re: Help on asdf json module

2020-10-25 Thread 9il via Digitalmars-d-learn
On Sunday, 25 October 2020 at 06:05:27 UTC, Vino wrote: Hi All, Currently we are testing various json module such as "std.json, std_data_json, vibe.data.json and asdf", the below code works perfectely while use "std_data_json or vibe.data.json" but not working as expected when we use

Re: Help on asdf json module

2020-10-25 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Sunday, 25 October 2020 at 06:05:27 UTC, Vino wrote: Hi All, Currently we are testing various json module such as "std.json, std_data_json, vibe.data.json and asdf", the below code works perfectely while use "std_data_json or vibe.data.json" but not working as expected when we use

Re: Help on asdf json module

2020-10-25 Thread ikod via Digitalmars-d-learn
On Sunday, 25 October 2020 at 06:05:27 UTC, Vino wrote: Hi All, Currently we are testing various json module such as "std.json, std_data_json, vibe.data.json and asdf", the below code works perfectely while use "std_data_json or vibe.data.json" but not working as expected when we use

Help on asdf json module

2020-10-25 Thread Vino via Digitalmars-d-learn
Hi All, Currently we are testing various json module such as "std.json, std_data_json, vibe.data.json and asdf", the below code works perfectely while use "std_data_json or vibe.data.json" but not working as expected when we use "asdf" and throwing the below error, hence request your

Re: mysql-native Help required

2020-10-25 Thread Vino via Digitalmars-d-learn
On Friday, 23 October 2020 at 20:28:40 UTC, aberba wrote: On Thursday, 22 October 2020 at 18:43:40 UTC, Steven Schveighoffer wrote: [...] Was about to say that. Part of why I think some people hate OOP...due to misuse. All my MySQL projects have this getConnection() function. Hi All,