1 // Move, forward and identity for C++0x + swap -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
26 * This is an internal header file, included by other library headers.
27 * You should not attempt to use it directly.
33 #include <bits/c++config.h>
35 #include <bits/concept_check.h>
37 #ifdef __GXX_EXPERIMENTAL_CXX0X__
38 #include <type_traits>
40 _GLIBCXX_BEGIN_NAMESPACE(std)
42 // 20.2.2, forward/move
43 template<typename _Tp>
49 template<typename _Tp>
51 forward(typename std::identity<_Tp>::type&& __t)
54 template<typename _Tp>
55 inline typename std::remove_reference<_Tp>::type&&
59 _GLIBCXX_END_NAMESPACE
61 #define _GLIBCXX_MOVE(_Tp) std::move(_Tp)
63 #define _GLIBCXX_MOVE(_Tp) (_Tp)
66 _GLIBCXX_BEGIN_NAMESPACE(std)
69 * @brief Swaps two values.
70 * @param a A thing of arbitrary type.
71 * @param b Another thing of arbitrary type.
74 template<typename _Tp>
76 swap(_Tp& __a, _Tp& __b)
78 // concept requirements
79 __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
81 _Tp __tmp = _GLIBCXX_MOVE(__a);
82 __a = _GLIBCXX_MOVE(__b);
83 __b = _GLIBCXX_MOVE(__tmp);
86 // _GLIBCXX_RESOLVE_LIB_DEFECTS
87 // DR 809. std::swap should be overloaded for array types.
88 template<typename _Tp, size_t _Nm>
90 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
92 for (size_t __n = 0; __n < _Nm; ++__n)
93 swap(__a[__n], __b[__n]);
96 _GLIBCXX_END_NAMESPACE