On Mon, Jul 17, 2017 at 12:01:48PM -0700, H. S. Teoh via Digitalmars-d-learn 
wrote:
[...]
>       template sumOfLengths(A...)
>               if (A.length > 0)
>       {
>               static if (A.length == 1)
>                       enum sumOfLengths = A[0].length;
>               else
>                       enum sumOfLengths = A[0].length + sumOfLengths!(A[1 .. 
> $]);
>       }
> 
>       T[sumOfLengths!StaticArrays] append(StaticArrays...)(StaticArrays 
> arrays)
>               if (/* insert static array constraints here */)
>       {
>               typeof(return) result = void;
>               size_t offset = 0;
>               foreach (a; arrays)
>               {
>                       result[offset .. offset + a.length] = a[];
>               }
>               return result;
>       }
[...]

Hmm, since we already have sumOfLengths available at compile-time, what
about:

        T[sumOfLengths!StaticArrays] append(StaticArrays...)(StaticArrays 
arrays)
                if (allSatisfy!(isStaticArray, StaticArrays))
        {
                typeof(return) result = void;
                foreach (i, a; 0 .. arrays.length)
                {
                        enum offset = sumOfLengths!(arrays[0 .. i]);
                        result[offset .. offset + a.length] = a[];
                }
                return result;
        }


T

-- 
People say I'm indecisive, but I'm not sure about that. -- YHL, CONLANG

Reply via email to