| Thread overview | |||||
|---|---|---|---|---|---|
|
December 25, 2013 joiner correct usage | ||||
|---|---|---|---|---|
| ||||
Hello, following code: import std.algorithm : joiner; string joined = joiner(["hello", "world"], " "); Results in: Error: cannot implicitly convert expression (joiner(...)) of type Result to string Any idea how to make this work ? | ||||
December 25, 2013 Re: joiner correct usage | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Dfr | On Wed, Dec 25, 2013 at 06:21:17PM +0000, Dfr wrote: > Hello, following code: > > import std.algorithm : joiner; > string joined = joiner(["hello", "world"], " "); > > Results in: > > Error: cannot implicitly convert expression (joiner(...)) of type > Result to string > > Any idea how to make this work ? joiner returns a range object, not an array. To get an array out of it, do this: import std.array : array; import std.algorithm : joiner; string joined = joiner(["hello", "world"], " ").array; T -- Spaghetti code may be tangly, but lasagna code is just cheesy. | |||
December 25, 2013 Re: joiner correct usage | ||||
|---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Wednesday, 25 December 2013 at 18:41:47 UTC, H. S. Teoh wrote: > > import std.array : array; > import std.algorithm : joiner; > string joined = joiner(["hello", "world"], " ").array; > > > T Ha! > Error: cannot implicitly convert expression (array(joiner(["hello", "world"], " "))) of type dchar[] to string std.conv.to should be used instead: import std.conv : to; string joined = joiner(["hello", "world"], " ").to!string; | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply