Re: opApply seems like it can infer delegate types AND parameters!?

2023-12-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 December 2023 at 23:21:45 UTC, Quirin Schroll wrote: I always thought you had to provide aliases with all 16 combinations of the attributes `@safe`, `@nogc`, `pure`, and `nothrow` for each actually desired instance. But you don’t and **I have no clue why**. Why does it work?

Re: opApply seems like it can infer delegate types AND parameters!?

2023-12-11 Thread Quirin Schroll via Digitalmars-d-learn
On Monday, 11 December 2023 at 23:21:45 UTC, Quirin Schroll wrote: […] 1. Instead of implementing a function `opApply(scope int delegate(...))`, write a function template `opApplyImpl(DG)(scope int delegate(...))` (or whatever name) and let it take the delegate type as a template type

opApply seems like it can infer delegate types AND parameters!?

2023-12-11 Thread Quirin Schroll via Digitalmars-d-learn
In an attempt to come up with an [answer to a post](https://forum.dlang.org/post/dnsuyvnfcszwefsfz...@forum.dlang.org), I found something odd, but useful, that I nonetheless don’t understand. As far as I know – or rather thought I knew – `foreach` loops can infer the types of the “loop

Re: Reading .txt File into String and Matching with RegEx

2023-12-11 Thread BoQsc via Digitalmars-d-learn
Matches function declarations and captures function names from `.d` Source Code file **regexcapture.d** ``` import std.stdio : writeln; import std.regex : matchAll, regex; import std.file : read; void main(){ string input = cast(string)read("sourcecode.d"); foreach(match;

Re: Reading .txt File into String and Matching with RegEx

2023-12-11 Thread BoQsc via Digitalmars-d-learn
On Monday, 11 December 2023 at 05:18:45 UTC, thinkunix wrote: BoQsc via Digitalmars-d-learn wrote: This is something I've searched on the forum and couldn't find exact answer. TLDR: `r"^."` is matching the very first two character in the `input` string. Don't you need two dots to match two