]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/move.h
*: Use headername alias to associate private includes to public includes.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / move.h
CommitLineData
e14e932b 1// Move, forward and identity for C++0x + swap -*- C++ -*-
1476e59c 2
882b3d5c 3// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
1476e59c
PC
4//
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
1476e59c
PC
9// any later version.
10
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.
15
748086b7
JJ
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.
19
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/>.
1476e59c 24
f910786b 25/** @file bits/move.h
1476e59c 26 * This is an internal header file, included by other library headers.
f910786b 27 * Do not attempt to use it directly. @headername{utility}
1476e59c
PC
28 */
29
caa8b3c6
PC
30#ifndef _MOVE_H
31#define _MOVE_H 1
1476e59c 32
e14e932b
PC
33#include <bits/c++config.h>
34#include <bits/concept_check.h>
35
882b3d5c
PC
36_GLIBCXX_BEGIN_NAMESPACE(std)
37
38 // Used, in C++03 mode too, by allocators, etc.
39 template<typename _Tp>
40 inline _Tp*
41 __addressof(_Tp& __r)
42 {
43 return reinterpret_cast<_Tp*>
44 (&const_cast<char&>(reinterpret_cast<const volatile char&>(__r)));
45 }
46
47_GLIBCXX_END_NAMESPACE
48
1476e59c 49#ifdef __GXX_EXPERIMENTAL_CXX0X__
7274deff 50#include <type_traits> // Brings in std::declval too.
1476e59c
PC
51
52_GLIBCXX_BEGIN_NAMESPACE(std)
5f1fd346 53
ad269884 54 /// forward (as per N3143)
4c7aaebf 55 template<typename _Tp>
ad269884
PC
56 inline _Tp&&
57 forward(typename std::remove_reference<_Tp>::type& __t)
4c7aaebf
PC
58 { return static_cast<_Tp&&>(__t); }
59
4c7aaebf 60 template<typename _Tp>
ad269884
PC
61 inline _Tp&&
62 forward(typename std::remove_reference<_Tp>::type&& __t)
63 {
64 static_assert(!std::is_lvalue_reference<_Tp>::value, "template argument"
65 " substituting _Tp is an lvalue reference type");
66 return static_cast<_Tp&&>(__t);
67 }
e7f1930f 68
fd9380a6
BK
69 /**
70 * @brief Move a value.
71 * @ingroup mutating_algorithms
72 * @param __t A thing of arbitrary type.
73 * @return Same, moved.
74 */
1476e59c
PC
75 template<typename _Tp>
76 inline typename std::remove_reference<_Tp>::type&&
77 move(_Tp&& __t)
e7f1930f 78 { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
1476e59c 79
5ab3a5af 80 /// declval, from type_traits.
7274deff 81
882b3d5c
PC
82 /**
83 * @brief Returns the actual address of the object or function
84 * referenced by r, even in the presence of an overloaded
85 * operator&.
86 * @param __r Reference to an object or function.
87 * @return The actual address.
88 */
89 template<typename _Tp>
90 inline _Tp*
91 addressof(_Tp& __r)
92 { return std::__addressof(__r); }
93
1476e59c
PC
94_GLIBCXX_END_NAMESPACE
95
5f1fd346 96#define _GLIBCXX_MOVE(__val) std::move(__val)
55dd8445 97#define _GLIBCXX_FORWARD(_Tp, __val) std::forward<_Tp>(__val)
d98f312c 98#else
5f1fd346 99#define _GLIBCXX_MOVE(__val) (__val)
55dd8445 100#define _GLIBCXX_FORWARD(_Tp, __val) (__val)
1476e59c
PC
101#endif
102
e14e932b
PC
103_GLIBCXX_BEGIN_NAMESPACE(std)
104
105 /**
106 * @brief Swaps two values.
fd9380a6
BK
107 * @ingroup mutating_algorithms
108 * @param __a A thing of arbitrary type.
109 * @param __b Another thing of arbitrary type.
e14e932b
PC
110 * @return Nothing.
111 */
112 template<typename _Tp>
113 inline void
114 swap(_Tp& __a, _Tp& __b)
115 {
116 // concept requirements
117 __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
118
119 _Tp __tmp = _GLIBCXX_MOVE(__a);
120 __a = _GLIBCXX_MOVE(__b);
121 __b = _GLIBCXX_MOVE(__tmp);
122 }
123
caa8b3c6
PC
124 // _GLIBCXX_RESOLVE_LIB_DEFECTS
125 // DR 809. std::swap should be overloaded for array types.
126 template<typename _Tp, size_t _Nm>
127 inline void
128 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
129 {
130 for (size_t __n = 0; __n < _Nm; ++__n)
131 swap(__a[__n], __b[__n]);
132 }
133
e14e932b
PC
134_GLIBCXX_END_NAMESPACE
135
caa8b3c6 136#endif /* _MOVE_H */