chaining chain Result and underlying object of chain

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 14 08:01:51 PDT 2015


On Monday, 14 September 2015 at 14:31:33 UTC, anonymous wrote:
> On Monday 14 September 2015 16:17, Laeeth Isharc wrote:
>
>> chain doesn't seem to compile if I try and chain a chain of 
>> two strings and another string.
>> 
>> what should I use instead?
>
> Please show code, always.
>
> A simple test works for me:
>
> ----
> import std.algorithm: equal;
> import std.range: chain;
> void main()
> {
>     auto chain1 = chain("foo", "bar");
>     auto chain2 = chain(chain1, "baz");
>     assert(equal(chain2, "foobarbaz"));
> }
> ----

Sorry - was exhausted yesterday when I had the code there, or 
would have posted.  I was trying to use the same variable eg

       auto chain1 = chain("foo", "bar");
       chain1 = chain(chain1, "baz");

Realized that in this case it was much simpler just to use the 
delegate version of toString and sink (which I had forgotten 
about).  But I wondered what to do in other cases.  It may be 
that the type of chain1 and chain2 don't mix.


More information about the Digitalmars-d-learn mailing list