How to get a range from std.container.array for use with std.format.sformat?

Steven Schveighoffer schveiguy at yahoo.com
Wed Jan 31 18:47:47 UTC 2018


On 1/30/18 2:19 PM, cc wrote:
> Still doesn't work without the cast it seems..
> 
>      auto rng = str[];
>      rng.sformat!"%s:%s"("some", "string");
>      // Error: template std.format.sformat cannot deduce function from 
> argument types !("%s:%s")(RangeT!(Array!char), string, string)

I misunderstood what you were trying to do. I thought you were just 
trying to get a valid range, missed the requirement that the range works 
with sformat (obviously from the subject! sorry).

Indeed, there isn't a way to extract an actual char[] from Array (and 
this is intentional).

But as Seb says, you can use formattedWrite:

auto rng = str[];
rng.formattedWrite("%s:%s", "some", "string");

-Steve


More information about the Digitalmars-d-learn mailing list