How about appender.put() with var args?

Vladimir Panteleev via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 16 18:32:11 PDT 2015


On Wednesday, 15 April 2015 at 20:44:07 UTC, Ali Çehreli wrote:
> On 04/15/2015 12:09 PM, "=?UTF-8?B?Ik3DoXJjaW8=?= Martins\" 
> <marcioapm at gmail.com>\"" 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");
>>
>> How about this instead?
>>
>> app.put("foo", var, "bar");
>
> Agreed.
>
> If a different name like putAll() is acceptable:
>
> void putAll(A, T...)(A a, T items)
> {
>     foreach (item; items){
>         a.put(item);
>     }
> }
>
> // ...
>
>     app.putAll("foo", var, "bar");

A hypothetical variadic put method would have the advantage over 
this in that it could could calculate the total length and 
preallocate for all arguments in one go.


More information about the Digitalmars-d mailing list