[Issue 14998] Cannot put a char into a char[]

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Dec 1 06:47:53 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14998

bb.temp at gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bb.temp at gmx.com

--- Comment #2 from bb.temp at gmx.com ---
(In reply to schneider.cedric from comment #0)
> Following code does not compile:
> 
> int main()
> {
>      import std.stdio;
>      import std.range;
>      char[] c;
>      c ~= 'a';
>      c ~= 'b';
>      c.put('c');
>      writeln(c);
>      return 0;
> }
> 
> The error is:
> 
> C:\dmd\src\phobos\std\range.d(9,9): Error: static assert  "Cannot put a
> char into a char[]." (Test)

What did you expect as result ? put() is ***poorly designed***. The ddoc says
itself that "well, depending on the input and the output...". 

There is no constraint in put() and it uses internal checks such as "static if
(is(template!Stuff))" that automatically fail to report the right error line if
the error comes from another template such as the private "putChar()".

So in short:
- look at the result when using another type.
- tell if it's worth implementing it for char in char[]
- close.

--


More information about the Digitalmars-d-bugs mailing list