Re: Why does sum not work in static arrays?

2020-10-11 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Oct 11, 2020 at 01:26:13PM +, Alaindevos via Digitalmars-d-learn wrote: > Sidenote, sort also not works with static arrays. Just slice it with []. T -- I think the conspiracy theorists are out to get us...

Re: Why does sum not work in static arrays?

2020-10-11 Thread Alaindevos via Digitalmars-d-learn
Sidenote, sort also not works with static arrays.

Re: Why does sum not work in static arrays?

2020-10-10 Thread mw via Digitalmars-d-learn
gorithm.iteration.sum(R, E)(R r, E seed) if (isInputRange!R && !isInfinite!R && is(typeof(seed = seed + r.front))) So a dynamic array works just fine. In fact, if I uncomment the line in question the program compiles and outputs the correct value (for a2). Why does "sum" not work

Re: Why does choose not work here

2019-08-02 Thread berni via Digitalmars-d-learn
On Thursday, 1 August 2019 at 21:26:10 UTC, Matt wrote: Anyone have any other thoughts? I tried to simplify your example a little bit: import std.stdio; import std.range; import std.algorithm; auto myFilter(R1, R2)(R1 a, R2 b) { return a.filter!(c => c==b.front); } struct A { int[]

Re: Why does choose not work here

2019-08-01 Thread Matt via Digitalmars-d-learn
On Thursday, 1 August 2019 at 21:12:51 UTC, ag0aep6g wrote: `choose`'s parameters aren't lazy. So the second argument is evaluated even when `previous is null`. That means `intervalRange` is called on a null `previous`. And that fails, of course, because `intervalRange` can't access `starts`

Re: Why does choose not work here

2019-08-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.08.19 22:23, Matt wrote: Version 4 does not work when PairedA.previous is null. I'd love to understand why. [...] auto myFilter(R1, R2)(R1 a, R2 b) { import std.algorithm : filter, canFind; return a.filter!(c => b.canFind(c)); } struct A { uint[] starts, stops;

Why does choose not work here

2019-08-01 Thread Matt via Digitalmars-d-learn
I'm having some trouble with a "Program exited with code -1073741819" error in some code I'm writing and I would appreciate any help/insight. The problem stems from some incompatibility between the Phobos function "choose" and the template function "myFilter" which returns a range. The code

Re: Why does not UFCS work for method defined inside unittest block?

2018-08-01 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 31 July 2018 at 08:42:28 UTC, Simen Kjærås wrote: From https://dlang.org/spec/function.html#pseudo-member: "A free function can be called with a syntax that looks as if the function were a member function of its first parameter type." [...] Thanks a lot Simen :)

Re: Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 31 July 2018 at 08:28:01 UTC, Ky-Anh Huynh wrote: Hi, Can I define a new quick function to use inside a unittest block? I have the following code: [code] auto foo(string[] sta) { return sta; } auto bar(string[] sta) { return sta; } auto h(string[] sta) { return

Re: Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Ky-Anh Huynh via Digitalmars-d-learn
dmd version that I'm using: $ dmd --version DMD64 D Compiler v2.081.1-dirty Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved written by Walter Bright

Why does not UFCS work for method defined inside unittest block?

2018-07-31 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Can I define a new quick function to use inside a unittest block? I have the following code: [code] auto foo(string[] sta) { return sta; } auto bar(string[] sta) { return sta; } auto h(string[] sta) { return sta.foo.bar; } unittest { import std.format; auto f = (string[] sta)

Re: Why does this not work?

2016-01-01 Thread israel via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:00:41 UTC, TheDGuy wrote: writeln("Which number should i guess?"); string input = readln(); int i = to!int(input); You fell for the C# syntax like me... According to Ahli. You have to use the old C way of doing it with readf.

Re: Why does this not work?

2016-01-01 Thread Tobi G. via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:00:41 UTC, TheDGuy wrote: writeln("Which number should i guess?"); string input = readln(); int i = to!int(input); The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping the

Re: Why does this not work?

2016-01-01 Thread Tobi G. via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:20:26 UTC, Tobi G. wrote: The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping the newline off import std.string; int i = to!int(input.strip); Sorry my bad english.. i wrote solution but meant

Re: Why does this not work?

2016-01-01 Thread bachmeier via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:47:20 UTC, TheDGuy wrote: On Friday, 1 January 2016 at 14:29:34 UTC, Tobi G. wrote: On Friday, 1 January 2016 at 14:20:26 UTC, Tobi G. wrote: The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping

Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
writeln("Which number should i guess?"); string input = readln(); int i = to!int(input);

Re: Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:29:34 UTC, Tobi G. wrote: On Friday, 1 January 2016 at 14:20:26 UTC, Tobi G. wrote: The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping the newline off import std.string; int i =

Re: Why does this not work?

2016-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 January 2016 at 15:06:53 UTC, bachmeier wrote: I've battled with a few times, not having any idea what was going on. I now almost automatically use strip when it's not working. This is one of the most frequently asked questions by new users.. I added a tip to my new docs:

Re: Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Friday, 1 January 2016 at 15:16:36 UTC, Adam D. Ruppe wrote: On Friday, 1 January 2016 at 15:06:53 UTC, bachmeier wrote: I've battled with a few times, not having any idea what was going on. I now almost automatically use strip when it's not working. This is one of the most frequently

Re: Why does this not work?

2016-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 January 2016 at 17:00:23 UTC, TheDGuy wrote: If i had known that blog existed. I think your example at the end of the page explains the problem really well. Thanks! I just wrote that example in response to this thread :P (the overall thing there is something i started last week

Re: Why does this not work?

2016-01-01 Thread bachmeier via Digitalmars-d-learn
On Friday, 1 January 2016 at 15:16:36 UTC, Adam D. Ruppe wrote: On Friday, 1 January 2016 at 15:06:53 UTC, bachmeier wrote: I've battled with a few times, not having any idea what was going on. I now almost automatically use strip when it's not working. This is one of the most frequently

Re: Why does sum not work in static arrays?

2015-12-06 Thread cym13 via Digitalmars-d-learn
ge!R && !isInfinite!R && is(typeof(seed = seed + r.front))) So a dynamic array works just fine. In fact, if I uncomment the line in question the program compiles and outputs the correct value (for a2). Why does "sum" not work on static arrays? Regards So that

Re: Why does sum not work in static arrays?

2015-12-06 Thread drug via Digitalmars-d-learn
& is(typeof(seed = seed + r.front))) So a dynamic array works just fine. In fact, if I uncomment the line in question the program compiles and outputs the correct value (for a2). Why does "sum" not work on static arrays? Regards Because static array aren't ranges, but dynamic ones are

Why does sum not work in static arrays?

2015-12-06 Thread Tim K. via Digitalmars-d-learn
seed + r.front))) So a dynamic array works just fine. In fact, if I uncomment the line in question the program compiles and outputs the correct value (for a2). Why does "sum" not work on static arrays? Regards

Re: Why does sum not work in static arrays?

2015-12-06 Thread Tim K. via Digitalmars-d-learn
On Sunday, 6 December 2015 at 12:27:49 UTC, cym13 wrote: A static array is a value type so it is passed by value to functions. Oh, right, I totally forgot about that. Thank you for reminding me. And yes, I was not planning on doing that. I just have a local fixed-size array that I wanted to

Why does this not work?

2014-09-17 Thread Shachar via Digitalmars-d-learn
void func( int c ) { ubyte a; a = cast(ubyte)c + cast(ubyte)c; } dmd v2.065 complains about: test.d(5): Error: cannot implicitly convert expression (cast(int)cast(ubyte)c + cast(int)cast(ubyte)c) of type int to ubyte As far as I can tell, adding two values of the same type should

Re: Why does this not work?

2014-09-17 Thread flamencofantasy via Digitalmars-d-learn
the result of ubyte + ubyte is int I believe. Try; void func( int c ) { ubyte a; a = cast(ubyte)(cast(ubyte)c + cast(ubyte)c); }

Re: Why does this not work?

2014-09-17 Thread ketmar via Digitalmars-d-learn
On Wed, 17 Sep 2014 13:20:13 + Shachar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: From http://dlang.org/type, under Usual Arithmetic Conversions: 4. Else the integer promotions are done on each operand, followed by: 1. If both are the same type, no more

Re: Why does this not work?

2014-09-17 Thread Shachar Shemesh via Digitalmars-d-learn
On 17/09/14 16:32, ketmar via Digitalmars-d-learn wrote: On Wed, 17 Sep 2014 13:20:13 + Shachar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: From http://dlang.org/type, under Usual Arithmetic Conversions: 4. Else the integer promotions are done on each operand,

Re: Why does this not work?

2014-09-17 Thread flamencofantasy via Digitalmars-d-learn
Because of overflow. On Wednesday, 17 September 2014 at 13:36:42 UTC, Shachar Shemesh wrote: On 17/09/14 16:32, ketmar via Digitalmars-d-learn wrote: On Wed, 17 Sep 2014 13:20:13 + Shachar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: From http://dlang.org/type,

Re: Why does this not work?

2014-09-17 Thread ketmar via Digitalmars-d-learn
On Wed, 17 Sep 2014 16:36:41 +0300 Shachar Shemesh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I don't understand. Why is this behavior preferrable to the one outlined by the specs? 'cause C does exactly this. there is no reason to confuse people with C background by

Re: Why does this not work?

2014-09-17 Thread flamencofantasy via Digitalmars-d-learn
http://www.drdobbs.com/tools/value-range-propagation/229300211

Re: Why does this not work?

2014-09-17 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 September 2014 at 13:20:15 UTC, Shachar wrote: On Wednesday, 17 September 2014 at 13:03:05 UTC, flamencofantasy wrote: the result of ubyte + ubyte is int I believe. Try; void func( int c ) { ubyte a; a = cast(ubyte)(cast(ubyte)c + cast(ubyte)c); } From

Why does toUTF16z only work with UTF8 encoding?

2011-05-08 Thread Andrej Mitrovic
toUTF16 can take a char[], wchar[] or dchar[]. But toUTF16z can only take a char[]. Why? I'm storing some text as dchar[] internally and have to pass it to WinAPI Unicode functions which expect null-terminated UTF16 strings. But toUTF16z only works with char[] for some reason.

Re: Why does toUTF16z only work with UTF8 encoding?

2011-05-08 Thread Andrej Mitrovic
I guess this should do it: const(wchar)* toUTF16z(in dchar[] s) { return (toUTF16(s) ~ \000).ptr; }