'pp' for D?
monarch_dodra
monarchdodra at gmail.com
Sun Sep 29 22:55:13 PDT 2013
On Monday, 30 September 2013 at 04:20:32 UTC, Ali Çehreli wrote:
> On 09/29/2013 03:38 PM, linkrope wrote:
>> On Sunday, 29 September 2013 at 18:14:03 UTC, monarch_dodra
>> wrote:
>>> On Sunday, 29 September 2013 at 14:31:15 UTC, linkrope wrote:
>>>> As a workaround, I put the value into an array to make use
>>>> of the
>>>> "undocumented" function formatElement:
>>>>
>>>> "%(%s%)".format([value])
>>>
>>> That seems excessive. What happened to format(`"%s"`, s) or
>>> format("\"%s\"", s) or text('"', s, '"')?
>>
>> Of course, this works well when I know that the value is of
>> type string.
>>
>> But I have a template and I want to print the representation
>> of (T value):
>> "hello" (with quotes) or just 42 (without)
>>
>> Phobos does this for array elements, but it seems that there's
>> nothing
>> like 'repr'?
>
> I don't know a Phobos function either but the following should
> work:
>
> [SNIP]
> static if (isSomeString!T) {
This should also take into acount enums, as they get their own
printing.
It should either use std.conv's private "isExactSomeString", or
use:
static if (isSomeString!T && !is(T == enum)
More information about the Digitalmars-d-learn
mailing list