blob: 425fcb69e23c82147c3fa50a127ea804367c9d11 [file] [log] [blame]
Brian Silverman5c0bf772013-02-28 16:44:44 -08001// Move, forward and identity for C++0x + swap -*- C++ -*-
2
3// Copyright (C) 2007, 2008, 2009 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.
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
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/>.
24
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.
28 */
29
30#ifndef _MOVE_H
31#define _MOVE_H 1
32
33#include "aos/crio/type_traits/type_traits"
34
35namespace std {
36
37 /// identity
38 template<typename _Tp>
39 struct identity
40 {
41 typedef _Tp type;
42 };
43
44 /// forward (as per N2835)
45 /// Forward lvalues as rvalues.
46 template<typename _Tp>
47 inline typename enable_if<!is_lvalue_reference<_Tp>::value, _Tp&&>::type
48 forward(typename std::identity<_Tp>::type& __t)
49 { return static_cast<_Tp&&>(__t); }
50
51 /// Forward rvalues as rvalues.
52 template<typename _Tp>
53 inline typename enable_if<!is_lvalue_reference<_Tp>::value, _Tp&&>::type
54 forward(typename std::identity<_Tp>::type&& __t)
55 { return static_cast<_Tp&&>(__t); }
56
57 // Forward lvalues as lvalues.
58 template<typename _Tp>
59 inline typename enable_if<is_lvalue_reference<_Tp>::value, _Tp>::type
60 forward(typename std::identity<_Tp>::type __t)
61 { return __t; }
62
63 // Prevent forwarding rvalues as const lvalues.
64 template<typename _Tp>
65 inline typename enable_if<is_lvalue_reference<_Tp>::value, _Tp>::type
66 forward(typename std::remove_reference<_Tp>::type&& __t) = delete;
67
68 /**
69 * @brief Move a value.
70 * @ingroup mutating_algorithms
71 * @param __t A thing of arbitrary type.
72 * @return Same, moved.
73 */
74 template<typename _Tp>
75 inline typename std::remove_reference<_Tp>::type&&
76 move(_Tp&& __t)
77 { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
78
79 /// declval, from type_traits.
80
81#define _GLIBCXX_MOVE(_Tp) std::move(_Tp)
82#define _GLIBCXX_FORWARD(_Tp, __val) std::forward<_Tp>(__val)
83
84#if 0
85 /**
86 * @brief Swaps two values.
87 * @ingroup mutating_algorithms
88 * @param __a A thing of arbitrary type.
89 * @param __b Another thing of arbitrary type.
90 * @return Nothing.
91 */
92 template<typename _Tp>
93 inline void
94 swap(_Tp& __a, _Tp& __b)
95 {
96 // concept requirements
97 __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
98
99 _Tp __tmp = _GLIBCXX_MOVE(__a);
100 __a = _GLIBCXX_MOVE(__b);
101 __b = _GLIBCXX_MOVE(__tmp);
102 }
103
104 // _GLIBCXX_RESOLVE_LIB_DEFECTS
105 // DR 809. std::swap should be overloaded for array types.
106 template<typename _Tp, size_t _Nm>
107 inline void
108 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
109 {
110 for (size_t __n = 0; __n < _Nm; ++__n)
111 swap(__a[__n], __b[__n]);
112 }
113#endif
114
115} // namespace std
116
117#endif /* _MOVE_H */