Question about OutputRange and std.range: put

Uranuz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 16 04:11:11 PST 2016


Hello to forum readers!
I have a question about using OutputRange and std.range: put. I 
have the following code snippet to illustrate my question:

import std.range, std.stdio, std.string;

void main()
{
	string greating = "Hello, "	;
	string username = "Bob";
	
	put(greating, username);
	put(greating, "!");
	
	writeln(greating);
}

It doesn't compile. It says following:

Compilation output:
/opt/compilers/dmd2/include/std/range/primitives.d(335): Error: 
static assert  "Cannot put a string into a string."
/d52/f530.d(8):        instantiated from here: put!(string, 
string)

Documentation about std.range.put says that one of code snippets, 
where *put* applies is when second argument is array of elements 
(If I understand it correctly with my knowledge of English). 
Especially the following line is there in doc for usage scenario:

r.doPut([ e ]);	R specifically accepts an E[].

Can I put range or array f elements as second argument of put or 
it works only at per element basis? I think writing multiple 
items at a time should be more effective but maybe it's not 
supported for OutputRange? Could someone explain?


More information about the Digitalmars-d-learn mailing list