[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: std::swap replacement?
From:       Thiago Macieira <thiago.macieira () kdemail ! net>
Date:       2005-01-27 22:39:40
Message-ID: 200501272039.40790.thiago.macieira () kdemail ! net
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Esben Mose Hansen wrote:
>Can I do something like this in QTL for QValueList<T>?

Yes

>If not, does QT or KDE provide a swap template like the one below?
>
>template<typename T>
>void swap(T& lhs, T& rhs) {
>   T tmp(lhs);
>   lhs=rhs;
>   rhs=tmp;
>}

That's more or less STL's definition of swap:

  template<typename _Tp>
    inline void
    swap(_Tp& __a, _Tp& __b)
    {
      // concept requirements
      __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)

      const _Tp __tmp = __a;
      __a = __b;
      __b = __tmp;
    }

Since QTL's containers are implicitly shared, the operation is O(1) in CPU 
time and memory.

-- 
  Thiago Macieira  -  thiago (AT) macieira (DOT) info
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

2. Tó cennan his weorc gearu, ymbe se circolwyrde, wearð se cægbord and se 
leohtspeccabord, and þa mýs cómon lator. On þone dæg, he hine reste.

[Attachment #5 (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic