[cfe-commits] [libcxx] r119545 - in /libcxx/trunk: include/__tuple include/array include/tuple include/utility test/containers/sequences/array/array.tuple/get_rv.pass.cpp test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp
Howard Hinnant
hhinnant at apple.com
Wed Nov 17 11:52:17 PST 2010
Author: hhinnant
Date: Wed Nov 17 13:52:17 2010
New Revision: 119545
URL: http://llvm.org/viewvc/llvm-project?rev=119545&view=rev
Log:
LWG 1191
Added:
libcxx/trunk/test/containers/sequences/array/array.tuple/get_rv.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp
libcxx/trunk/test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp
Modified:
libcxx/trunk/include/__tuple
libcxx/trunk/include/array
libcxx/trunk/include/tuple
libcxx/trunk/include/utility
Modified: libcxx/trunk/include/__tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tuple?rev=119545&r1=119544&r2=119545&view=diff
==============================================================================
--- libcxx/trunk/include/__tuple (original)
+++ libcxx/trunk/include/__tuple Wed Nov 17 13:52:17 2010
@@ -83,6 +83,10 @@
const typename tuple_element<_Ip, tuple<_Tp...>>::type&
get(const tuple<_Tp...>&);
+template <size_t _Ip, class ..._Tp>
+typename tuple_element<_Ip, tuple<_Tp...>>::type&&
+get(tuple<_Tp...>&&);
+
template <size_t _Ip, class _T1, class _T2>
typename tuple_element<_Ip, pair<_T1, _T2> >::type&
get(pair<_T1, _T2>&);
@@ -91,6 +95,10 @@
const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
get(const pair<_T1, _T2>&);
+template <size_t _Ip, class _T1, class _T2>
+typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
+get(pair<_T1, _T2>&&);
+
template <size_t _Ip, class _Tp, size_t _Size>
_Tp&
get(array<_Tp, _Size>&);
@@ -99,6 +107,10 @@
const _Tp&
get(const array<_Tp, _Size>&);
+template <size_t _Ip, class _Tp, size_t _Size>
+_Tp&&
+get(array<_Tp, _Size>&&);
+
// __make_tuple_indices
template <size_t...> struct __tuple_indices {};
Modified: libcxx/trunk/include/array
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/array?rev=119545&r1=119544&r2=119545&view=diff
==============================================================================
--- libcxx/trunk/include/array (original)
+++ libcxx/trunk/include/array Wed Nov 17 13:52:17 2010
@@ -94,6 +94,7 @@
template <int I, class T, size_t N> struct tuple_element<I, array<T, N>>;
template <int I, class T, size_t N> T& get(array<T, N>&);
template <int I, class T, size_t N> const T& get(const array<T, N>&);
+template <int I, class T, size_t N> T&& get(array<T, N>&&);
} // std
@@ -295,6 +296,18 @@
return __a[_Ip];
}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY inline
+_Tp&&
+get(array<_Tp, _Size>&& __a)
+{
+ return _STD::move(__a[_Ip]);
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_ARRAY
Modified: libcxx/trunk/include/tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/tuple?rev=119545&r1=119544&r2=119545&view=diff
==============================================================================
--- libcxx/trunk/include/tuple (original)
+++ libcxx/trunk/include/tuple Wed Nov 17 13:52:17 2010
@@ -88,6 +88,7 @@
// 20.4.1.5, element access:
template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type& get(tuple<T...>&);
template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type const& get(const tuple<T...>&);
+template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type&& get(tuple<T...>&&);
// 20.4.1.6, relational operators:
template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&);
@@ -430,6 +431,8 @@
typename tuple_element<_Jp, tuple<_Up...>>::type& get(tuple<_Up...>&);
template <size_t _Jp, class ..._Up> friend
const typename tuple_element<_Jp, tuple<_Up...>>::type& get(const tuple<_Up...>&);
+ template <size_t _Jp, class ..._Up> friend
+ typename tuple_element<_Jp, tuple<_Up...>>::type&& get(tuple<_Up...>&&);
public:
_LIBCPP_INLINE_VISIBILITY
@@ -583,6 +586,15 @@
return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
}
+template <size_t _Ip, class ..._Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename tuple_element<_Ip, tuple<_Tp...>>::type&&
+get(tuple<_Tp...>&& __t)
+{
+ typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
+ return static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get();
+}
+
// tie
template <class ..._Tp>
Modified: libcxx/trunk/include/utility
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=119545&r1=119544&r2=119545&view=diff
==============================================================================
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Wed Nov 17 13:52:17 2010
@@ -100,6 +100,10 @@
const typename const tuple_element<I, std::pair<T1, T2> >::type&
get(const std::pair<T1, T2>&);
+template<size_t I, class T1, class T2>
+ typename tuple_element<I, std::pair<T1, T2> >::type&&
+ get(std::pair<T1, T2>&&);
+
} // std
*/
@@ -425,6 +429,16 @@
_LIBCPP_INLINE_VISIBILITY
const _T1&
get(const pair<_T1, _T2>& __p) {return __p.first;}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ template <class _T1, class _T2>
+ static
+ _LIBCPP_INLINE_VISIBILITY
+ _T1&&
+ get(pair<_T1, _T2>&& __p) {return _STD::forward<_T1>(__p.first);}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
};
template <>
@@ -441,6 +455,16 @@
_LIBCPP_INLINE_VISIBILITY
const _T2&
get(const pair<_T1, _T2>& __p) {return __p.second;}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ template <class _T1, class _T2>
+ static
+ _LIBCPP_INLINE_VISIBILITY
+ _T2&&
+ get(pair<_T1, _T2>&& __p) {return _STD::forward<_T2>(__p.second);}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
};
template <size_t _Ip, class _T1, class _T2>
@@ -459,6 +483,18 @@
return __get_pair<_Ip>::get(__p);
}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <size_t _Ip, class _T1, class _T2>
+_LIBCPP_INLINE_VISIBILITY inline
+typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
+get(pair<_T1, _T2>&& __p)
+{
+ return __get_pair<_Ip>::get(_STD::move(__p));
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
#endif // _LIBCPP_HAS_NO_VARIADICS
_LIBCPP_END_NAMESPACE_STD
Added: libcxx/trunk/test/containers/sequences/array/array.tuple/get_rv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/array/array.tuple/get_rv.pass.cpp?rev=119545&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/array/array.tuple/get_rv.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/array/array.tuple/get_rv.pass.cpp Wed Nov 17 13:52:17 2010
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <array>
+
+// template <size_t I, class T, size_t N> T&& get(array<T, N>&& a);
+
+#include <array>
+#include <memory>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef std::unique_ptr<double> T;
+ typedef std::array<T, 1> C;
+ C c = {std::unique_ptr<double>(new double(3.5))};
+ T t = std::get<0>(std::move(c));
+ assert(*t == 3.5);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
Added: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp?rev=119545&view=auto
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp (added)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp Wed Nov 17 13:52:17 2010
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <tuple>
+
+// template <class... Types> class tuple;
+
+// template <size_t I, class... Types>
+// typename tuple_element<I, tuple<Types...> >::type&&
+// get(tuple<Types...>&& t);
+
+#include <tuple>
+#include <memory>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::tuple<std::unique_ptr<int> > T;
+ T t(std::unique_ptr<int>(new int(3)));
+ std::unique_ptr<int> p = std::get<0>(std::move(t));
+ assert(*p == 3);
+ }
+}
Added: libcxx/trunk/test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp?rev=119545&view=auto
==============================================================================
--- libcxx/trunk/test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp (added)
+++ libcxx/trunk/test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp Wed Nov 17 13:52:17 2010
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <utility>
+
+// template <class T1, class T2> struct pair
+
+// template<size_t I, class T1, class T2>
+// typename tuple_element<I, std::pair<T1, T2> >::type&&
+// get(pair<T1, T2>&&);
+
+#include <utility>
+#include <memory>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef std::pair<std::unique_ptr<int>, short> P;
+ P p(std::unique_ptr<int>(new int(3)), 4);
+ std::unique_ptr<int> ptr = std::get<0>(std::move(p));
+ assert(*ptr == 3);
+ }
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
More information about the cfe-commits
mailing list