Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/21 3:52 PM, Sebastiaan Koppe wrote: On Wednesday, 7 July 2021 at 13:30:28 UTC, Steven Schveighoffer wrote: On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the spli

Re: to compose or hack?

2021-07-07 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 19:52:30 UTC, Sebastiaan Koppe wrote: Just lift each item in a range then: ```d import std; auto foo(string s, string sp, string j) @nogc { return s.splitter(sp).map!(i => only(i)).joiner(only(j)); } ``` Code golf: `map!(i => only(i))` can be shortened to `m

Re: Template arg deduction

2021-07-07 Thread vit via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 19:14:52 UTC, Kevin Bailey wrote: I'm trying to use some fairly simple template argument deduction, but maybe I'm not getting the syntax correct. C++ doesn't event blink at something like this, but D is giving me: temptest.d(18): Error: template temptest.func canno

Re: to compose or hack?

2021-07-07 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 13:30:28 UTC, Steven Schveighoffer wrote: On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the splits are, insert a string to go between the e

Re: Template arg deduction

2021-07-07 Thread Tejas via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 19:14:52 UTC, Kevin Bailey wrote: I'm trying to use some fairly simple template argument deduction, but maybe I'm not getting the syntax correct. C++ doesn't event blink at something like this, but D is giving me: temptest.d(18): Error: template temptest.func canno

Re: Template arg deduction

2021-07-07 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 19:14:52 UTC, Kevin Bailey wrote: I'm trying to use some fairly simple template argument deduction, but maybe I'm not getting the syntax correct. C++ doesn't event blink at something like this, but D is giving me: temptest.d(18): Error: template temptest.func canno

Re: Template arg deduction

2021-07-07 Thread Ali Çehreli via Digitalmars-d-learn
On 7/7/21 12:14 PM, Kevin Bailey wrote: > fairly simple template argument deduction It's not the simplest but it is still complicated. :) > I guess D can't crack open a type like that? There are other ways of achieving the same thing the simplest of which is probably the following: void fun

Template arg deduction

2021-07-07 Thread Kevin Bailey via Digitalmars-d-learn
I'm trying to use some fairly simple template argument deduction, but maybe I'm not getting the syntax correct. C++ doesn't event blink at something like this, but D is giving me: temptest.d(18): Error: template temptest.func cannot deduce function from argument types !()(bar), candidates are:

Re: array inside a class + alias this + filter -> clears the array.

2021-07-07 Thread realhet via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 17:10:01 UTC, Paul Backus wrote: On Wednesday, 7 July 2021 at 16:20:29 UTC, realhet wrote: int[] opIndex() { return array; } Thx, I didn't know about this type of opSlice override. It works nicely. Now I have these choices: - write [] everywhere to access

Re: array inside a class + alias this + filter -> clears the array.

2021-07-07 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 16:20:29 UTC, realhet wrote: Hi, I wanted to make a container class that exposes its elements using a simple "alias this", but getting weird errors: I test with the std.algorithm.filter template function. 1. when I use "alias this" on a function that returns a sl

array inside a class + alias this + filter -> clears the array.

2021-07-07 Thread realhet via Digitalmars-d-learn
Hi, I wanted to make a container class that exposes its elements using a simple "alias this", but getting weird errors: I test with the std.algorithm.filter template function. 1. when I use "alias this" on a function that returns a slice, making the internal array unreachable, filter just ca

Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread MoonlightSentinel via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 10:27:47 UTC, notna wrote: On Windows: [...] Nice and helpful Error messages is on the top of our desires list, right? It's hard to give proper error backtraces without debug information (-g). Anyways, I can reproduce the error when compiling with `-m32` (the def

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully). With

Re: Find a char among string (string.findAmong.char)

2021-07-07 Thread rassoc via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 12:22:11 UTC, BoQsc wrote: I think nested foreach loops are more readable. ``` import std; void main() { alias alphabet = letters; char[26] letters = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', '

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/6/21 11:42 PM, Jon Degenhardt wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: This is pretty minimal, but does what I want it to do. Is it ready for inclusion in Phobos? Not by a longshot! A truly generic interleave would properly forward everything else that

Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread notna via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 11:54:39 UTC, z wrote: On 64 bits you don't even get a stack trace or description. Sad, i know. If you want better i could recommend you to compile with `-g` and hook up a debugger, then just let it run and it should triger a breakpoint on 0xC009(access violati

Re: Find a char among string (string.findAmong.char)

2021-07-07 Thread BoQsc via Digitalmars-d-learn
I think nested foreach loops are more readable. ``` import std; void main() { alias alphabet = letters; char[26] letters = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',

Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread notna via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 12:07:26 UTC, rikki cattermole wrote: With ldc you can turn on address sanitizer which will give you that information (and a LOT more!) without a debugger (but you still need -g). http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html compil

Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread rikki cattermole via Digitalmars-d-learn
On 07/07/2021 11:54 PM, z wrote: On Wednesday, 7 July 2021 at 10:27:47 UTC, notna wrote: On Windows: ``` ::> dmd curl_get.d ::> .\curl_get.exe object.Error@(0): Access Violation 0x0283CA66 0x0041DE8D 0x004023A2 0x00402308 0x00414D33 0x00414CAD 0x00414B48 0x0040D41F 0x00402363

Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread z via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 10:27:47 UTC, notna wrote: On Windows: ``` ::> dmd curl_get.d ::> .\curl_get.exe object.Error@(0): Access Violation 0x0283CA66 0x0041DE8D 0x004023A2 0x00402308 0x00414D33 0x00414CAD 0x00414B48 0x0040D41F 0x00402363 0x74B96359 in BaseThreadInitThunk 0

Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread notna via Digitalmars-d-learn
On Monday, 5 July 2021 at 15:08:45 UTC, MoonlightSentinel wrote: On Monday, 5 July 2021 at 14:57:20 UTC, BoQsc wrote: Let's say I can't store information into files. Is it possible to download a file into an array. Yes, use [`get`](https://dlang.org/phobos/std_net_curl.html#.get): ```d impo

Re: to compose or hack?

2021-07-07 Thread rassoc via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully). Without considering the more general c