LWG 1191
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@119545 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
86ed8aefb2
commit
cd2254b454
@ -83,6 +83,10 @@ template <size_t _Ip, class ..._Tp>
|
||||
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 @@ template <size_t _Ip, class _T1, class _T2>
|
||||
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 @@ template <size_t _Ip, class _Tp, size_t _Size>
|
||||
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 {};
|
||||
|
@ -94,6 +94,7 @@ template <class T, size_t N> struct tuple_size<array<T, N>>;
|
||||
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 @@ get(const array<_Tp, _Size>& __a)
|
||||
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
|
||||
|
@ -88,6 +88,7 @@ template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
|
||||
// 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 @@ class _LIBCPP_VISIBLE tuple
|
||||
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 @@ get(const tuple<_Tp...>& __t)
|
||||
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>
|
||||
|
@ -100,6 +100,10 @@ template<size_t I, class T1, class T2>
|
||||
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 @@ struct __get_pair<0>
|
||||
_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 @@ struct __get_pair<1>
|
||||
_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 @@ get(const pair<_T1, _T2>& __p)
|
||||
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
|
||||
|
29
test/containers/sequences/array/array.tuple/get_rv.pass.cpp
Normal file
29
test/containers/sequences/array/array.tuple/get_rv.pass.cpp
Normal file
@ -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
|
||||
}
|
30
test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp
Normal file
30
test/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp
Normal file
@ -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);
|
||||
}
|
||||
}
|
32
test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp
Normal file
32
test/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user