Swap front for char[] input ranges

RazvanN via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 19 02:41:46 PST 2016


Hi,

I have a function which accepts 2 input Ranges and swaps the 
first element in Range1 with the first element in Range2. The 
swapping code looks something like this :

      static if (is(typeof(swap(r1.front, r2.front))))
      {
          swap(r1.front, r2.front);
      }
      else
      {
          auto t1 = moveFront(r1), t2 = moveFront(r2);
          auto tmp1 = r1.front;
          auto tmp2 = r2.front;
          r1.front = move(t2);
          r2.front = move(t1);
      }

This code works for most cases, except when 2 char[] are passed.
In that case, the compilation fails with error messages which 
state
that r1.front and r2.front are not Lvalues. So, my question is:
how can I swap the 2 elements since in the case of char[] input 
ranges
the front property does not return a reference?



More information about the Digitalmars-d-learn mailing list