std.string.format results in run-time exception

kenji hara k.hara.pg at gmail.com
Sat Jun 30 11:19:30 PDT 2012


std.string.format uses std.format.doFormat, and it is based on RTTI.
On the other hand, writeln/writefln uses std.format.formattedWrite and
formatValue, they are based on Compile Time Reflection.
So the results are different.

In 2.060head, std.string.xformat is added, and it works as like writefln.
https://github.com/D-Programming-Language/phobos/blob/master/std/string.d#L2611

Bye.

Kenji Hara

2012/7/1 d coder <dlang.coder at gmail.com>:
> Greetings
>
> std.string.format throws runtime exception for BigInt and for BitArray types
> even though writefln works fine. The run-time error says
> std.format.FormatException at std/format.d(4744): Can't convert
> std.bigint.BigInt to string: "string toString()" not defined
>
> Here is a small test case.
>
> Regards
> - Puneet
>
> void main()
> {
>   import std.stdio;
>   import std.string;
>   import std.bigint;
>   import std.bitmanip;
>
>   BigInt aa = 100;
>
>   BitArray bb;
>   bb.init([true, false]);
>
>   writefln("%x", aa);
>   writefln("%x", bb);
>   writeln(format("%x", aa));
>   writeln(format("%x", bb));
> }
>


More information about the Digitalmars-d mailing list