[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: swap in stdlib?
From: |
Paul Pluzhnikov |
Subject: |
Re: swap in stdlib? |
Date: |
Sun, 26 Feb 2006 17:14:39 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
schuelaw@gmail.com writes:
> Is a swap function part of "standard c++"?
Yes (as part of STL): section 25.2.2 Swap:
template<class T> void swap(T& a, T& b);
Requires: Type T is Assignable (23.1).
Effects: Exchanges values stored in two locations.
> If not, where can I read
Info on STL swap:
http://www.sgi.com/tech/stl/swap.html
> about the implementation of this particular swap in this particular
> compiler?
I don't know where you can read about this implementation, but you
can read the implementation itself (there isn't much to it :)
// gcc-3.4.3/include/c++/3.4.3/bits/stl_algobase.h
/**
* @brief Swaps two values.
* @param a A thing of arbitrary type.
* @param b Another thing of arbitrary type.
* @return Nothing.
*
* This is the simple classic generic implementation. It will work on
* any type which has a copy constructor and an assignment operator.
*/
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;
}
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
- swap in stdlib?, schuelaw, 2006/02/28
- Re: swap in stdlib?,
Paul Pluzhnikov <=