Re: Fake IFTI-compatible struct constructors

2021-05-01 Thread Chad Joan via Digitalmars-d-learn
On Saturday, 1 May 2021 at 23:21:33 UTC, Basile B. wrote: On Saturday, 1 May 2021 at 21:57:54 UTC, Chad Joan wrote: ... Rather, this setup doesn't work at all, because IFTI doesn't seem to work on function-templates with alias parameters. Yes your observation is correct. That should work but

Fake IFTI-compatible struct constructors

2021-05-01 Thread Chad Joan via Digitalmars-d-learn
I came up with a couple techniques for making it seem like templated structs deduce their template parameters from constructor invocations. These are given further down in the post. This has been a profitable exercise. However, the techniques I came up with have some drawbacks. Thus, I have

Re: safety and auto vectorization

2020-08-03 Thread Chad Joan via Digitalmars-d-learn
On Sunday, 2 August 2020 at 17:31:45 UTC, Bruce Carneal wrote: import std; void f0(int[] a, int[] b, int[] dst) @safe { dst[] = a[] + b[]; } void f1(int[] a, int[] b, int[] dst) @trusted { const minLen = min(a.length, b.length, dst.length); dst[0..minLen] = a[0..minLen] +

Re: D on lm32-CPU: string argument on stack instead of register

2020-08-01 Thread Chad Joan via Digitalmars-d-learn
On Saturday, 1 August 2020 at 08:58:03 UTC, Michael Reese wrote: [...] So the compiler knows how to use r1 and r2 for arguments. I checked again in the lm32 manual (https://www.latticesemi.com/view_document?document_id=52077), and it says: "As illustrated in Table 3 on page 8, the first

Re: D on lm32-CPU: string argument on stack instead of register

2020-07-31 Thread Chad Joan via Digitalmars-d-learn
On Friday, 31 July 2020 at 10:22:20 UTC, Michael Reese wrote: Hi all, at work we put embedded lm32 soft-core CPUs in FPGAs and write the firmware in C. At home I enjoy writing small projects in D from time to time, but I don't consider myself a D expert. Now, I'm trying to run some toy

Re: Why does stringof not like functions with arguments?

2020-07-31 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 10 August 2017 at 14:51:22 UTC, Meta wrote: On Wednesday, 9 August 2017 at 01:39:07 UTC, Jason Brady wrote: Why does the following code error out with: app.d(12,10): Error: function app.FunctionWithArguments (uint i) is not callable using argument types () Code: import

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 09:58:25 UTC, Jonathan M Davis wrote: For two types to be compared, they must be the the same type - or they must be implicitly convertible to the same type, in which case, they're converted to that type and then compared. So, as far as D's design of

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 13:23:15 UTC, Adam D. Ruppe wrote: On Thursday, 27 September 2018 at 05:04:09 UTC, Chad Joan wrote: As above, I think this might be a very clean and effective solution for a different class of use-cases :) I'll keep it in mind though. Yeah. And I did make

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 14:23:48 UTC, Steven Schveighoffer wrote: On 9/27/18 10:20 AM, Steven Schveighoffer wrote: typeid sometimes gives you a more derived type than TypeInfo. Including for classes and structs. In the past, .classinfo gave you a different thing than typeid(obj),

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 13:16:58 UTC, Adam D. Ruppe wrote: On Thursday, 27 September 2018 at 05:18:14 UTC, Chad Joan wrote: How does this work? The language reference states that typeid(Type) returns "an instance of class TypeInfo corresponding to Type".

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 18:37:27 UTC, Chad Joan wrote: I will probably end up going with the latter suggestion and have Extended use the Root's T. That would probably make sense for what I'm doing. In my case, the T allows the caller to configure what kind of output the thing

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 08:56:22 UTC, Alex wrote: On Wednesday, 26 September 2018 at 20:41:38 UTC, Chad Joan wrote: class Root(T) { T x; } class Extended(T) : Root!T { T y; } Sorry for a technical aside, but would this be something for you?

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 08:19:41 UTC, Jonathan M Davis wrote: On Thursday, September 27, 2018 1:41:23 AM MDT Chad Joan via Digitalmars-d- learn wrote: On Thursday, 27 September 2018 at 05:12:06 UTC, Jonathan M Davis This is also reminding me of how it's always bugged me

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-27 Thread Chad Joan via Digitalmars-d-learn
On Thursday, 27 September 2018 at 05:12:06 UTC, Jonathan M Davis wrote: On Wednesday, September 26, 2018 10:20:58 PM MDT Chad Joan via Digitalmars- d-learn wrote: ... That's interesting! Thanks for mentioning. If you don't mind, what are the complaints regarding Object? Or can you link me

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-26 Thread Chad Joan via Digitalmars-d-learn
On Wednesday, 26 September 2018 at 21:25:07 UTC, Steven Schveighoffer wrote: ... Object.factory is a really old poorly supported type of reflection. I would not depend on it for anything. Roger that. Will avoid :) You are better off using your own registration system. As far as choosing

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-26 Thread Chad Joan via Digitalmars-d-learn
On Wednesday, 26 September 2018 at 21:24:07 UTC, Adam D. Ruppe wrote: On Wednesday, 26 September 2018 at 20:41:38 UTC, Chad Joan wrote: I'm implementing a deep-copy method for a tree of templated class instances. As part of this, I need some way to copy each node. [...] that isn't already

Re: Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-26 Thread Chad Joan via Digitalmars-d-learn
On Wednesday, 26 September 2018 at 23:32:36 UTC, Jonathan M Davis wrote: On Wednesday, September 26, 2018 3:24:07 PM MDT Adam D. Ruppe via Digitalmars-d-learn wrote: Object.factory kinda sux and I'd actually like to remove it (among other people). There's no plan to actually do that, but

Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

2018-09-26 Thread Chad Joan via Digitalmars-d-learn
Hi all, I'm implementing a deep-copy method for a tree of templated class instances. As part of this, I need some way to copy each node. I want to avoid code that does things like casting objects into byte arrays and then copying raw bytes; I want all operations to be memory safe things

Re: Best way to manage non-memory resources in current D, ex: database handles.

2017-03-08 Thread Chad Joan via Digitalmars-d-learn
Awesome, thank you! On Thursday, 9 March 2017 at 00:47:48 UTC, Adam D. Ruppe wrote: Now, if you forget to scope(exit), it is OK, the garbage collector WILL get around to it eventually, and it is legal to work with C handles and functions from a destructor. It is only illegal to call D's

How do I get names of regex captures during iteration? Populate AAs with captures?

2017-02-28 Thread Chad Joan via Digitalmars-d-learn
Is there a way to get the name of a named capture when iterating over captures from a regular expression match? I've looked at the std.regex code and it seems like "no" to my eyes, but I wonder if others here have... a way. My original problem is this: I need to populate an associative

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 23:30:52 UTC, Chad Joan wrote: On Tuesday, 21 February 2017 at 22:43:15 UTC, H. S. Teoh wrote: Parsing strings at program startup is ugly and slow. What about parsing at compile-time with CTFE into an array literal and transforming that into an AA at startup,

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 22:43:15 UTC, H. S. Teoh wrote: Parsing strings at program startup is ugly and slow. What about parsing at compile-time with CTFE into an array literal and transforming that into an AA at startup, which should be a lot faster? // Warning: untested

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 22:26:01 UTC, Chad Joan wrote: On Tuesday, 21 February 2017 at 21:58:07 UTC, Stefan Koch wrote: On Tuesday, 21 February 2017 at 21:53:23 UTC, Chad Joan wrote: Hello all, I'm trying to make this work: [...] You cannot create AA's at ctfe and carry them over

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 21:58:07 UTC, Stefan Koch wrote: On Tuesday, 21 February 2017 at 21:53:23 UTC, Chad Joan wrote: Hello all, I'm trying to make this work: [...] You cannot create AA's at ctfe and carry them over to runtime use. You'd have to use a costum dictionary-type. I

How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Chad Joan via Digitalmars-d-learn
Hello all, I'm trying to make this work: --- pure string[string] parseTwoColumnCsv(string inputCsv) { import std.csv; import std.typecons; string[string] result; foreach ( record; csvReader!(Tuple!(string,string))(inputCsv) )