cannot implicitly convert char[] to string
I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message: runnable/test23.d(1219): Error: cannot implicitly convert expression (format(s = %s, s)) of type char[] to string The line which fails is `p = std.string.format(s = %s, s);` I don't understand why I can't convert a char[] to string.
Re: Compare types with `static if` in template function.
On Wednesday, 29 July 2015 at 17:52:45 UTC, Ali Çehreli wrote: On 07/29/2015 10:48 AM, vladde wrote: static if(is(typeof(c) == dchar) || is(typeof(c) == char)) { slots[xy.y][xy.x].character = c; } else if(is(typeof(c) == fg)) I don't know whether it is the reason here but you fell for one of the D traps. :( Most definitely, you want an 'else static if' there. Otherwise, for the fg case, what ends up in your code to be compiled is this: if(is(typeof(c) == fg)) Ali Apparently, if I only check for a character the code compiles without the need of static if. if(is(typeof(c) == dchar) || is(typeof(c) == char)){ slots[xy.y][xy.x].character = c; } //Compiles and works as expected
Re: Compare types with `static if` in template function.
On Wednesday, 29 July 2015 at 18:04:48 UTC, vladde wrote: Apparently, if I only check for a character the code compiles without the need of static if. if(is(typeof(c) == dchar) || is(typeof(c) == char)){ slots[xy.y][xy.x].character = c; } //Compiles and works as expected And changing all if statements to static if still does not compile.
Compare types with `static if` in template function.
I want to have a template function where I can throw in some stuff in the parameters, then run foreach+static ifs and check what type the current is. From my project clayers[1], I've taken out some parts. (Note the current code does not compile.) This is what I have so far: struct XY {size_t x, y;} alias fg = colorize.fg; //[2] [...] void changeSlot(C...)(XY xy, C changes){ foreach(c; changes){ static if(is(typeof(c) == dchar) || is(typeof(c) == char)) { slots[xy.y][xy.x].character = c; } else if(is(typeof(c) == fg)) { slots[xy.y][xy.x].fg = C; } } } [...] changeSlot(XY(10, 15), fg.red); For this demonstation I've chosen to only check for `char` and `fg`, but it's intended to check for multiple different types. (See [1]) Now when I try to compile, I get Error: more than one argument for construction of int for checking against fg. HOWEVER, the code functions properly when checking the type for characters. From what I understand, my thinking works, but checking with `fg` is causing some crux-flux. `fg` is created from a template, please take a look at [2]. What am I doing wrong when I check for the type of `fg`? TL;DR: Is there a way to check the type of `fg` with an static if? [1] = https://github.com/vladdeSV/clayers/blob/change-slot/source/clayers.d#L323 [2] = https://github.com/yamadapc/d-colorize/blob/master/source/colorize/colors.d#L37
Re: Compare types with `static if` in template function.
On Wednesday, 29 July 2015 at 18:14:11 UTC, Ali Çehreli wrote: else if(is(typeof(c) == fg)) { // slots[xy.y][xy.x].fg = C; } The error occurs when the commented line is run. The full code can be viewed at https://github.com/vladdeSV/clayers/blob/change-slot/source/clayers.d
Re: Multi-dimensional fixed arrays
I am pretty surprised, as the following code gives errors. void main(){ int [1][2] foo; foo[0][0] = 1; foo[0][1] = 2; foo[1][0] = 3; foo[1][1] = 4; } Those errors are: app.d(5): Error: array index 1 is out of bounds foo[0][0 .. 1] app.d(7): Error: array index 1 is out of bounds foo[1][0 .. 1] Could anyone more experienced than me explain why this is, and why not it's the other way around?
Re: Multi-dimensional fixed arrays
Oh, seems I should learn to refresh the page :)