How about appender.put() with var args?
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Thu Apr 16 00:17:28 PDT 2015
On Wednesday, 15 April 2015 at 20:59:25 UTC, Steven Schveighoffer
wrote:
> On 4/15/15 4:51 PM, Messenger wrote:
>> On Wednesday, 15 April 2015 at 19:09:42 UTC, Márcio Martins
>> wrote:
>>> Hi!
>>>
>>> I use Appender a lot, and find it ugly to write this all the
>>> time to
>>> efficiently construct strings:
>>>
>>> app.put("foo");
>>> app.put(var);
>>> app.put("bar");
>>>
>>
>> Sidetracking a bit, but when I started using Appender I was
>> surprised to
>> see that put didn't return a reference to the Appender itself.
>> Had it
>> done so, you could have chained your put calls very nicely.
>>
>> app.put("foo")
>> .put(var)
>> .put("bar")
>> .put(more)
>> .put("stuff");
>>
>> You can naturally write a small wrapper function that does
>> this for you,
>> but it still strikes me as odd. Sadly I imagine changing the
>> return type
>> would make the function signature mangle differently, breaking
>> ABI
>> compatibility.
>
> with(app)
> {
> put(var);
> put("bar");
> put(more);
> put("stuff");
> }
>
> -Steve
With all the excitement about chaining and ufcs, the with
statement is often overlooked.
More information about the Digitalmars-d
mailing list