VirtualBox

Changeset 97823 in vbox for trunk/include/iprt/cpp


Ignore:
Timestamp:
Dec 16, 2022 12:57:06 PM (2 years ago)
Author:
vboxsync
Message:

IPRT: Added RTCListBase == and != operator support + testcases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/list.h

    r96407 r97823  
    498498        if (RT_LIKELY(this != &other))
    499499        {
    500 
    501500            other.m_guard.enterRead();
    502501            m_guard.enterWrite();
     
    517516        }
    518517        return *this;
     518    }
     519
     520    /**
     521     * Compares if this list's items match the other list.
     522     *
     523     * @returns \c true if both lists contain the same items, \c false if not.
     524     * @param   other   The list to compare this list with.
     525     */
     526    bool operator==(const RTCListBase<T, ITYPE, MT>& other)
     527    {
     528        /* Prevent self comparrison */
     529        if (RT_LIKELY(this == &other))
     530            return true;
     531
     532        other.m_guard.enterRead();
     533        m_guard.enterRead();
     534
     535        bool fEqual = true;
     536        if (other.m_cElements == m_cElements)
     537        {
     538            for (size_t i = 0; i < m_cElements; i++)
     539            {
     540                if (RTCListHelper<T, ITYPE>::at(m_pArray, i) != RTCListHelper<T, ITYPE>::at(other.m_pArray, i))
     541                {
     542                    fEqual = false;
     543                    break;
     544                }
     545            }
     546        }
     547        else
     548            fEqual = false;
     549
     550        m_guard.leaveRead();
     551        other.m_guard.leaveRead();
     552
     553        return fEqual;
     554    }
     555
     556    /**
     557     * Compares if this list's items do not match the other list.
     558     *
     559     * @returns \c true if the lists do not match, \c false if otherwise.
     560     * @param   other   The list to compare this list with.
     561     */
     562    bool operator!=(const RTCListBase<T, ITYPE, MT>& other)
     563    {
     564        return !(*this == other);
    519565    }
    520566
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette