Re: Is it possible to do this with a template?

2021-12-17 Thread Mitacha via Digitalmars-d-learn
On Friday, 17 December 2021 at 07:52:18 UTC, rempas wrote: I want to use an expression and put it in place inside the `if` parentheses. The expression is: `is(typeof(val) == type)`. I want to use a template called "is_same" that will take the value and a type to place them to the respective

Re: Counting number of regular expressions matches

2021-04-09 Thread Mitacha via Digitalmars-d-learn
On Friday, 9 April 2021 at 15:01:58 UTC, Alain De Vos wrote: I've got, import std.regex: regex,matchAll; ... string regfiltertext="\\b"~entryfilter.getText()~"\\b"; auto reg = regex(regfiltertext); auto result = name.strip("_").matchAll(reg); int t=0; foreach (c; result) t+=1; This make t the

Re: fold on empty range

2021-02-17 Thread Mitacha via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 11:38:45 UTC, Rumbu wrote: On Wednesday, 17 February 2021 at 10:15:10 UTC, Mitacha wrote: it'll use empty string as first element in range. BTW perheps you could use `joinner` instead of this `fold` to join values with ",". Thanks for that. I thought to

Re: fold on empty range

2021-02-17 Thread Mitacha via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 09:21:47 UTC, Rumbu wrote: In the expression below: return matchAll(content, keywordsPattern) .map!(a => a.hit.stripLeft("[").strip("]")) .fold!((a, b) => a ~ "," ~ b) .splitter(',') .map!(a => a.stripLeft("\"

Re: How to specify which parameters a function that is received as an argument should receive?

2020-10-13 Thread Mitacha via Digitalmars-d-learn
On Tuesday, 13 October 2020 at 09:02:04 UTC, Marcone wrote: How to specify which parameters a function that is received as an argument should receive? Example: import std; void myfun(int n){ writeln(n); } void test(lazy void delegate() fun) // how specify that "fun" may receive int ?

Re: Range checked assignment

2020-09-08 Thread Mitacha via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 14:18:14 UTC, Cecil Ward wrote: What I would like to do is (in pseudo-code) : declare_var my_var : int range 0..7; // i.e. 0 <= val <= 7; my_var = 6; // ok my_var = 8; // bang ! static assert fail or assert fail at runtime my_var = 6;

Re: Uploading coverage to Codecov doesn't work

2020-07-14 Thread Mitacha via Digitalmars-d-learn
On Saturday, 11 July 2020 at 09:43:39 UTC, Basile B. wrote: On Wednesday, 8 July 2020 at 15:55:58 UTC, Mitacha wrote: [...] It's broken for me too, on gitlab,... --- GitLab CI detected. project root: . --> token set from env Yaml found at: ./.codecov.yml ==> Running gcov in .

Uploading coverage to Codecov doesn't work

2020-07-08 Thread Mitacha via Digitalmars-d-learn
Hello there, I've been trying to setup bitbucket pipelines to submit coverage to codecov, but with no luck. I use `dub run -b unittest-cov` and it generates .lst files correctly, then `bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN` is called, but all I get is: ``` ==> Bitbucket

How to copy const object?

2020-02-27 Thread Mitacha via Digitalmars-d-learn
I've a const struct object and I'd like to make a mutable copy of it. Struct definition contains string and an array of structs. ``` struct A { string a; B[] b; } struct B { string a; string b; } ``` As far as I can tell copy constructor isn't generated for struct `A` because

Re: How to iterate over range two items at a time

2020-02-16 Thread Mitacha via Digitalmars-d-learn
On Monday, 17 February 2020 at 05:04:02 UTC, Adnan wrote: What is the equivalent of Rust's chunks_exact()[1] method in D? I want to iterate over a spitted string two chunks at a time. [1] https://doc.rust-lang.org/beta/std/primitive.slice.html#method.chunks_exact It sounds similar to

Re: Type Inference and Try Blocks

2020-01-21 Thread Mitacha via Digitalmars-d-learn
On Monday, 20 January 2020 at 23:16:07 UTC, Henry Claesson wrote: This isn't a D-specific "problem", but there may be D-specific solutions. I have a function `doSomething()` that returns a Voldemort type, and this same function also throws. So, there's this: try { auto foo =

Re: ddox build locally failed

2019-10-26 Thread Mitacha via Digitalmars-d-learn
On Saturday, 26 October 2019 at 16:39:19 UTC, berni44 wrote: I tried to build ddox documentation locally with the command (in dlang.org): make -j3 -f posix.mak apidocs-prerelease After a while I get the message "Linking..." followed by a call of dmd with lots of parameters, among them

Using output-range overloads of SysTime.toISO{Ext}String with formatting code

2019-07-09 Thread Mitacha via Digitalmars-d-learn
On Monday, 8 July 2019 at 12:53:18 UTC, Digital Mars wrote: 08.07.2019 13:38, Joseph Rushton Wakeling пишет: [...] Sorry that my answer wasn't thoughtful. I guess that there is no way to have `writeln` automatically use the output range overload instead of allocating one. You need somehow

Few questions about staticMap

2019-02-26 Thread Mitacha via Digitalmars-d-learn
Hi everyone, I checked, just out of curiosity, what is staticMap's implementation. It's implemented using recursive, this made me think if there is way to use static foreach instead. I came out with following solution: https://run.dlang.io/is/qvgJaw I checked time it took compiler to