Remove outermost loop parameter.
[official-gcc/graphite-test-results.git] / libstdc++-v3 / include / bits / move.h
bloba137f982bedb4eb7a046734cd5aa19654749867a
1 // Move, forward and identity for C++0x + swap -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
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/>.
25 /** @file move.h
26 * This is an internal header file, included by other library headers.
27 * You should not attempt to use it directly.
30 #ifndef _MOVE_H
31 #define _MOVE_H 1
33 #include <bits/c++config.h>
34 #include <cstddef>
35 #include <bits/concept_check.h>
37 _GLIBCXX_BEGIN_NAMESPACE(std)
39 // Used, in C++03 mode too, by allocators, etc.
40 template<typename _Tp>
41 inline _Tp*
42 __addressof(_Tp& __r)
44 return reinterpret_cast<_Tp*>
45 (&const_cast<char&>(reinterpret_cast<const volatile char&>(__r)));
48 _GLIBCXX_END_NAMESPACE
50 #ifdef __GXX_EXPERIMENTAL_CXX0X__
51 #include <type_traits> // Brings in std::declval too.
53 _GLIBCXX_BEGIN_NAMESPACE(std)
55 /// identity
56 template<typename _Tp>
57 struct identity
59 typedef _Tp type;
62 /// forward (as per N2835)
63 /// Forward lvalues as rvalues.
64 template<typename _Tp>
65 inline typename enable_if<!is_lvalue_reference<_Tp>::value, _Tp&&>::type
66 forward(typename std::identity<_Tp>::type& __t)
67 { return static_cast<_Tp&&>(__t); }
69 /// Forward rvalues as rvalues.
70 template<typename _Tp>
71 inline typename enable_if<!is_lvalue_reference<_Tp>::value, _Tp&&>::type
72 forward(typename std::identity<_Tp>::type&& __t)
73 { return static_cast<_Tp&&>(__t); }
75 // Forward lvalues as lvalues.
76 template<typename _Tp>
77 inline typename enable_if<is_lvalue_reference<_Tp>::value, _Tp>::type
78 forward(typename std::identity<_Tp>::type __t)
79 { return __t; }
81 // Prevent forwarding rvalues as const lvalues.
82 template<typename _Tp>
83 inline typename enable_if<is_lvalue_reference<_Tp>::value, _Tp>::type
84 forward(typename std::remove_reference<_Tp>::type&& __t) = delete;
86 /**
87 * @brief Move a value.
88 * @ingroup mutating_algorithms
89 * @param __t A thing of arbitrary type.
90 * @return Same, moved.
92 template<typename _Tp>
93 inline typename std::remove_reference<_Tp>::type&&
94 move(_Tp&& __t)
95 { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
97 /// declval, defined in <type_traits>.
99 /**
100 * @brief Returns the actual address of the object or function
101 * referenced by r, even in the presence of an overloaded
102 * operator&.
103 * @param __r Reference to an object or function.
104 * @return The actual address.
106 template<typename _Tp>
107 inline _Tp*
108 addressof(_Tp& __r)
109 { return std::__addressof(__r); }
111 _GLIBCXX_END_NAMESPACE
113 #define _GLIBCXX_MOVE(_Tp) std::move(_Tp)
114 #define _GLIBCXX_FORWARD(_Tp, __val) std::forward<_Tp>(__val)
115 #else
116 #define _GLIBCXX_MOVE(_Tp) (_Tp)
117 #define _GLIBCXX_FORWARD(_Tp, __val) (__val)
118 #endif
120 _GLIBCXX_BEGIN_NAMESPACE(std)
123 * @brief Swaps two values.
124 * @ingroup mutating_algorithms
125 * @param __a A thing of arbitrary type.
126 * @param __b Another thing of arbitrary type.
127 * @return Nothing.
129 template<typename _Tp>
130 inline void
131 swap(_Tp& __a, _Tp& __b)
133 // concept requirements
134 __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
136 _Tp __tmp = _GLIBCXX_MOVE(__a);
137 __a = _GLIBCXX_MOVE(__b);
138 __b = _GLIBCXX_MOVE(__tmp);
141 // _GLIBCXX_RESOLVE_LIB_DEFECTS
142 // DR 809. std::swap should be overloaded for array types.
143 template<typename _Tp, size_t _Nm>
144 inline void
145 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
147 for (size_t __n = 0; __n < _Nm; ++__n)
148 swap(__a[__n], __b[__n]);
151 _GLIBCXX_END_NAMESPACE
153 #endif /* _MOVE_H */