PAGED bool insertAt()

in rtl/inc/karray.h [263:299]


    PAGED bool insertAt(const iterator &destination, const const_iterator &start, const const_iterator &end)
    {
        if (end._i < start._i || destination._a != this)
            RtlFailFast(FAST_FAIL_INVALID_ARG);
        if (end._i == start._i)
            return true;

        const size_t countToInsert = end._i - start._i;

        size_t countToGrow;
        if (!NT_SUCCESS(RtlSIZETAdd(m_numElements, countToInsert, reinterpret_cast<SIZE_T*>(&countToGrow))))
            return false;

        if (!grow(countToGrow))
            return false;

        moveElements((ULONG)destination._i, (ULONG)(destination._i+countToInsert), (ULONG)(m_numElements - destination._i));

        if constexpr(__is_trivially_copyable(T))
        {
            memcpy(_p + destination._i, wistd::addressof((*start._a)[start._i]), countToInsert * sizeof(T));
        }
        else
        {
            const_iterator readCursor(start);
            iterator writeCursor(destination);
            while (readCursor != end)
            {
                new(wistd::addressof(_p[writeCursor._i])) T(wistd::move((*readCursor._a)[readCursor._i]));
                writeCursor++;
                readCursor++;
            }
        }

        m_numElements += static_cast<ULONG>(countToInsert);
        return true;
    }