Re: ImportC std support

2021-12-11 Thread ManKey via Digitalmars-d-learn
On Saturday, 11 December 2021 at 22:28:16 UTC, forkit wrote: On Saturday, 11 December 2021 at 21:42:49 UTC, ManKey wrote: umm... the site has search function you know ;-) Dude, you see, it doesn't say anything about it. It says a little about the extension, but there is no direct answer. This

unit test broken [DUB bug?]

2021-12-11 Thread Chris Katko via Digitalmars-d-learn
Running 64-bit Linux ``` dmd --version DMD64 D Compiler v2.098.0-beta.2 dub --version DUB version 1.27.0-beta.2, built on Sep 7 2021 ``` the following code 'compiles' in one project. ```d unittest { gasdindgaslkdgansklnasgdlknaglkgansklsdg; } void main(){} // compiles, links, and 'runs unit

Re: Why code failed to compile for foo2?

2021-12-11 Thread apz28 via Digitalmars-d-learn
On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only for unsigned type and the parameter value can be altered in body hence Unqual. If not Unqual, must declare a

Re: I need some help for my DCV update

2021-12-11 Thread 9il via Digitalmars-d-learn
On Saturday, 27 November 2021 at 12:16:39 UTC, Ferhat Kurtulmuş wrote: On Saturday, 27 November 2021 at 11:35:21 UTC, Salih Dincer wrote: I also found similar errors but couldn't solve them. I think it has to do with mir.slice.kind. Exactly Kind Topology... I won't use parallel for it as a

Re: Why code failed to compile for foo2?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 23:44:59 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 23:17:17 UTC, Stanislav Blinov wrote: ? No. If it was unsatisfied constraint, the error would've shown that. And if you try to instantiate it, you'll see it is an unsatisfied constraint anyway.

Re: Why code failed to compile for foo2?

2021-12-11 Thread Adam Ruppe via Digitalmars-d-learn
On Saturday, 11 December 2021 at 23:17:17 UTC, Stanislav Blinov wrote: ? No. If it was unsatisfied constraint, the error would've shown that. And if you try to instantiate it, you'll see it is an unsatisfied constraint anyway. There's two layers of failure here. Using Unqual there is pretty

Re: Why code failed to compile for foo2?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 22:59:52 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 22:50:45 UTC, apz28 wrote: void foo2(T)(Unqual!T x) if(isUnsigned!T) {} This means it treats foo2 as if it doesn't exist unless T is unsigned... onlineapp.d(15): Error: template

Re: Why code failed to compile for foo2?

2021-12-11 Thread Adam Ruppe via Digitalmars-d-learn
On Saturday, 11 December 2021 at 22:50:45 UTC, apz28 wrote: void foo2(T)(Unqual!T x) if(isUnsigned!T) {} This means it treats foo2 as if it doesn't exist unless T is unsigned... onlineapp.d(15): Error: template `onlineapp.foo2` cannot deduce function from argument types `!()(int)`

Why code failed to compile for foo2?

2021-12-11 Thread apz28 via Digitalmars-d-learn
void foo1(ubyte x) {} void foo1(ushort x) {} void foo1(uint x) {} void foo1(ulong x) {} import std.traits : isUnsigned, Unqual; void foo2(T)(Unqual!T x) if(isUnsigned!T) {} void main() { import std.math; int s = 1; foo1(abs(s)); foo2(abs(s)); //failed?

Re: ImportC std support

2021-12-11 Thread forkit via Digitalmars-d-learn
On Saturday, 11 December 2021 at 21:42:49 UTC, ManKey wrote: What implementations of the C standard library does importC support? umm... the site has search function you know ;-) https://dlang.org/spec/importc.html

ImportC std support

2021-12-11 Thread ManKey via Digitalmars-d-learn
What implementations of the C standard library does importC support?

Re: Wouldn't the compiler be smart with this shadowing variable?

2021-12-11 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 11 December 2021 at 20:22:13 UTC, frame wrote: ```d // iteration works, but scope behind does nothing for({int i=0; j=0;} i<10; ++i, {++i; ++j;} ){} // endless loop for({int i=0; j=0;} i<10; {++i; ++j;} ){} ``` Not sure if bug or feature but it is inconsistent for me and thus a

Re: Wouldn't the compiler be smart with this shadowing variable?

2021-12-11 Thread frame via Digitalmars-d-learn
On Saturday, 11 December 2021 at 15:15:06 UTC, Matheus wrote: I'm just a bit intrigued by your last sentence. Is there anything evil this may result or anything that I should be aware of? Besides it looks like an error, you may think that it just introduces a scope which can be referenced

Re: How to loop through characters of a string in D language?

2021-12-11 Thread russhy via Digitalmars-d-learn
On Saturday, 11 December 2021 at 18:51:12 UTC, Rumbu wrote: On Saturday, 11 December 2021 at 14:42:53 UTC, russhy wrote: Here is mine - 0 allocations - configurable - let's you use it how you wish - fast You know that this is already in phobos? ``` "abc;def;ghi".splitter(';').joiner

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Rumbu via Digitalmars-d-learn
On Saturday, 11 December 2021 at 14:42:53 UTC, russhy wrote: Here is mine - 0 allocations - configurable - let's you use it how you wish - fast You know that this is already in phobos? ``` "abc;def;ghi".splitter(';').joiner ```

Re: Wouldn't the compiler be smart with this shadowing variable?

2021-12-11 Thread Matheus via Digitalmars-d-learn
On Saturday, 11 December 2021 at 01:02:36 UTC, frame wrote: ... You probably want this: ```d int j; for({int i=0; j=0;} i<10; ++i){} ``` Beware, this syntax comes directly from hell Well this works! :) I'm just a bit intrigued by your last sentence. Is there anything evil this may result

Re: Wouldn't the compiler be smart with this shadowing variable?

2021-12-11 Thread Matheus via Digitalmars-d-learn
On Friday, 10 December 2021 at 21:55:17 UTC, Siarhei Siamashka wrote: ... 2. reuse the existing "j" variable. Yes. But only one of them is a correct description of what actually happens when the compiler processes this code. So it's a good thing that the compiler is smart enough to

Re: How to loop through characters of a string in D language?

2021-12-11 Thread russhy via Digitalmars-d-learn
Here is mine - 0 allocations - configurable - let's you use it how you wish - fast ```D import std; void main() { string a = "abc;def;ab"; writeln("a => ", a); foreach(item; split(a, ';')) writeln("\t", item); string b = "abc;def ;ab"; writeln("a => ",

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 11 December 2021 at 09:40:47 UTC, Stanislav Blinov wrote: On Saturday, 11 December 2021 at 09:34:17 UTC, Ola Fosheim Grøstad wrote: void donttrythisathome(string s, char stripchar) @trusted { import core.stdc.stdlib; char* begin = cast(char*)alloca(s.length); A

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 09:34:17 UTC, Ola Fosheim Grøstad wrote: void donttrythisathome(string s, char stripchar) @trusted { import core.stdc.stdlib; char* begin = cast(char*)alloca(s.length); A function with that name, and calling alloca to boot, cannot be @trusted ;)

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 11 December 2021 at 09:34:17 UTC, Ola Fosheim Grøstad wrote: @system Shouldn't be there. Residual leftovers… (I don't want to confuse newbies!)

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 11 December 2021 at 08:46:32 UTC, forkit wrote: On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim Grøstad wrote: Using libraries can trigger hidden allocations. ok. fine. no unnecessary, hidden allocations then. // -- module test; import

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 11 December 2021 at 09:26:06 UTC, Stanislav Blinov wrote: What you're showing is... indeed, don't do this, but I fail to see what that has to do with my suggestion, or the original code. You worry too much, just have fun with differing ways of expressing the same thing.

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 10 December 2021 at 23:53:47 UTC, Ola Fosheim Grøstad wrote: ```d char[] dontdothis(string s, int i=0, int skip=0){ if (s.length == i) return new char[](i - skip); if (s[i] == ';') return dontdothis(s, i+1, skip+1); auto r = dontdothis(s, i+1, skip); r[i-skip] =

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 11 December 2021 at 08:46:32 UTC, forkit wrote: On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim Grøstad wrote: Using libraries can trigger hidden allocations. ok. fine. no unnecessary, hidden allocations then. // -- module test; import

Re: How to loop through characters of a string in D language?

2021-12-11 Thread forkit via Digitalmars-d-learn
On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim Grøstad wrote: Using libraries can trigger hidden allocations. ok. fine. no unnecessary, hidden allocations then. // -- module test; import core.stdc.stdio : putchar; nothrow @nogc void main() { string str =

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 10 December 2021 at 18:47:53 UTC, Stanislav Blinov wrote: Threshold could be relative for short strings and absolute for long ones. Makes little sense reallocating if you only waste a couple bytes, but makes perfect sense if you've just removed pages and pages of semicolons ;)

Re: How to loop through characters of a string in D language?

2021-12-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 11 December 2021 at 00:39:15 UTC, forkit wrote: On Friday, 10 December 2021 at 22:35:58 UTC, Arjan wrote: "abc;def;ghi".tr(";", "", "d" ); I don't think we have enough ways of doing the same thing yet... so here's one more.. "abc;def;ghi".substitute(";", ""); Using