Output-Range and char

Mafi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 23 04:17:37 PDT 2017


Hi there,
every time I want to use output-ranges again they seem to be 
broken in a different way (e.g. value/reference semantics). This 
time it is char types and encoding.

How do I make formattedWrite work with a char buffer? I tried the 
following code and it fails with a *static assert*; it is 
itentionally disabled. I suspects it is again something about 
autodecoding but in this case I don't understand it.

https://dpaste.dzfl.pl/c68b3e3529f6

```
import std.format, std.stdio;

void main() {
	char[20] buffer;
	formattedWrite(buffer[], "Long string %s\n", "more more more");
	write(buffer);
}
```

Compilation output:

/opt/compilers/dmd2/include/std/range/primitives.d(351): Error: 
static assert  "Cannot put a char into a char[]."
/opt/compilers/dmd2/include/std/format.d(2647):        
instantiated from here: put!(char[], char)
/opt/compilers/dmd2/include/std/format.d(2297):        
instantiated from here: formatRange!(char[], string, char)
/opt/compilers/dmd2/include/std/format.d(3778):        
instantiated from here: formatValue!(char[], string, char)
/opt/compilers/dmd2/include/std/format.d(460):        
instantiated from here: formatGeneric!(char[], string, char)
/d446/f470.d(5):        instantiated from here: 
formattedWrite!(char[], char, string)



More information about the Digitalmars-d-learn mailing list