Function operator[]

Summary

#include <include/EASTL/deque.h>

(1) reference operator[](size_type n)

(2) const_reference operator[](size_type n) const

Function overload

Synopsis

#include <include/EASTL/deque.h>

reference operator[](size_type n)

Description

No description yet.

Source

Lines 1515-1535 in include/EASTL/deque.h. Line 424 in include/EASTL/deque.h.

template <typename T, typename Allocator, unsigned kDequeSubarraySize>
typename deque<T, Allocator, kDequeSubarraySize>::reference
deque<T, Allocator, kDequeSubarraySize>::operator[](size_type n)
{
    #if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
        if (EASTL_UNLIKELY(n >= (size_type)(mItEnd - mItBegin)))
            EASTL_FAIL_MSG("deque::operator[] -- out of range");
    #elif EASTL_ASSERT_ENABLED
        // We allow taking a reference to deque[0]
        if (EASTL_UNLIKELY((n != 0) && n >= (size_type)(mItEnd - mItBegin)))
            EASTL_FAIL_MSG("deque::operator[] -- out of range");
    #endif
    // See DequeIterator::operator+=() for an explanation of the code below.
    iterator it(mItBegin);
    const difference_type subarrayPosition = (difference_type)((it.mpCurrent - it.mpBegin) + (difference_type)n);
    const difference_type subarrayIndex    = (((16777216 + subarrayPosition) / (difference_type)kDequeSubarraySize)) - (16777216 / (difference_type)kDequeSubarraySize);
    return *(*(it.mpCurrentArrayPtr + subarrayIndex) + (subarrayPosition - (subarrayIndex * (difference_type)kDequeSubarraySize)));
}

Synopsis

#include <include/EASTL/deque.h>

const_reference operator[](size_type n) const

Description

No description yet.

Source

Lines 1538-1558 in include/EASTL/deque.h. Line 425 in include/EASTL/deque.h.

template <typename T, typename Allocator, unsigned kDequeSubarraySize>
typename deque<T, Allocator, kDequeSubarraySize>::const_reference
deque<T, Allocator, kDequeSubarraySize>::operator[](size_type n) const
{
    #if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
        if (EASTL_UNLIKELY(n >= (size_type)(mItEnd - mItBegin)))
            EASTL_FAIL_MSG("deque::operator[] -- out of range");
    #elif EASTL_ASSERT_ENABLED
        // We allow the user to use a reference to deque[0] of an empty container.
        if (EASTL_UNLIKELY((n != 0) && n >= (size_type)(mItEnd - mItBegin)))
            EASTL_FAIL_MSG("deque::operator[] -- out of range");
    #endif
    // See DequeIterator::operator+=() for an explanation of the code below.
    iterator it(mItBegin);
    const difference_type subarrayPosition = (it.mpCurrent - it.mpBegin) + (difference_type)n;
    const difference_type subarrayIndex    = (((16777216 + subarrayPosition) / (difference_type)kDequeSubarraySize)) - (16777216 / (difference_type)kDequeSubarraySize);
    return *(*(it.mpCurrentArrayPtr + subarrayIndex) + (subarrayPosition - (subarrayIndex * (difference_type)kDequeSubarraySize)));
}





Add Discussion as Guest

Log in