[libcxx] r255941 - [libcxx] LWG2485: get() should be overloaded for const tuple&&. Patch from K-Ballo.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 17 16:36:56 PST 2015
Author: ericwf
Date: Thu Dec 17 18:36:55 2015
New Revision: 255941
URL: http://llvm.org/viewvc/llvm-project?rev=255941&view=rev
Log:
[libcxx] LWG2485: get() should be overloaded for const tuple&&. Patch from K-Ballo.
Review: http://reviews.llvm.org/D14839
Added:
libcxx/trunk/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.pass.cpp
libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp
Modified:
libcxx/trunk/include/__tuple
libcxx/trunk/include/array
libcxx/trunk/include/tuple
libcxx/trunk/include/utility
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp
libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp
libcxx/trunk/www/cxx1z_status.html
Modified: libcxx/trunk/include/__tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tuple?rev=255941&r1=255940&r2=255941&view=diff
==============================================================================
--- libcxx/trunk/include/__tuple (original)
+++ libcxx/trunk/include/__tuple Thu Dec 17 18:36:55 2015
@@ -86,6 +86,11 @@ template <size_t _Ip, class ..._Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, tuple<_Tp...> >::type&&
get(tuple<_Tp...>&&) _NOEXCEPT;
+
+template <size_t _Ip, class ..._Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
+get(const tuple<_Tp...>&&) _NOEXCEPT;
#endif
// pair specializations
@@ -109,6 +114,11 @@ template <size_t _Ip, class _T1, class _
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
get(pair<_T1, _T2>&&) _NOEXCEPT;
+
+template <size_t _Ip, class _T1, class _T2>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
+get(const pair<_T1, _T2>&&) _NOEXCEPT;
#endif
// array specializations
@@ -132,6 +142,11 @@ template <size_t _Ip, class _Tp, size_t
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp&&
get(array<_Tp, _Size>&&) _NOEXCEPT;
+
+template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+const _Tp&&
+get(const array<_Tp, _Size>&&) _NOEXCEPT;
#endif
#if !defined(_LIBCPP_HAS_NO_VARIADICS)
Modified: libcxx/trunk/include/array
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/array?rev=255941&r1=255940&r2=255941&view=diff
==============================================================================
--- libcxx/trunk/include/array (original)
+++ libcxx/trunk/include/array Thu Dec 17 18:36:55 2015
@@ -95,6 +95,7 @@ template <size_t I, class T, size_t N> s
template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
+template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
} // std
@@ -324,6 +325,15 @@ get(array<_Tp, _Size>&& __a) _NOEXCEPT
return _VSTD::move(__a.__elems_[_Ip]);
}
+template <size_t _Ip, class _Tp, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+const _Tp&&
+get(const array<_Tp, _Size>&& __a) _NOEXCEPT
+{
+ static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
+ return _VSTD::move(__a.__elems_[_Ip]);
+}
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_END_NAMESPACE_STD
Modified: libcxx/trunk/include/tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/tuple?rev=255941&r1=255940&r2=255941&view=diff
==============================================================================
--- libcxx/trunk/include/tuple (original)
+++ libcxx/trunk/include/tuple Thu Dec 17 18:36:55 2015
@@ -95,6 +95,9 @@ template <size_t I, class... T>
template <size_t I, class... T>
typename tuple_element<I, tuple<T...>>::type&&
get(tuple<T...>&&) noexcept; // constexpr in C++14
+template <size_t I, class... T>
+ const typename tuple_element<I, tuple<T...>>::type&&
+ get(const tuple<T...>&&) noexcept; // constexpr in C++14
template <class T1, class... T>
constexpr T1& get(tuple<T...>&) noexcept; // C++14
@@ -102,6 +105,8 @@ template <class T1, class... T>
constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
template <class T1, class... T>
constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
+template <class T1, class... T>
+ constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
// 20.4.1.6, relational operators:
template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
@@ -507,6 +512,8 @@ class _LIBCPP_TYPE_VIS_ONLY tuple
const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
+ template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
+ const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
public:
template <bool _Dummy = true, class = typename enable_if<
@@ -766,6 +773,16 @@ get(tuple<_Tp...>&& __t) _NOEXCEPT
static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
}
+template <size_t _Ip, class ..._Tp>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
+get(const tuple<_Tp...>&& __t) _NOEXCEPT
+{
+ typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
+ return static_cast<const type&&>(
+ static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
+}
+
#if _LIBCPP_STD_VER > 11
// get by type
template <typename _T1, size_t _Idx, typename... _Args>
@@ -821,6 +838,13 @@ constexpr _T1&& get(tuple<_Args...>&& __
{
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
}
+
+template <class _T1, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
+{
+ return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
+}
#endif
Modified: libcxx/trunk/include/utility
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=255941&r1=255940&r2=255941&view=diff
==============================================================================
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Thu Dec 17 18:36:55 2015
@@ -120,15 +120,34 @@ template<size_t I, class T1, class T2>
typename tuple_element<I, pair<T1, T2> >::type&&
get(pair<T1, T2>&&) noexcept; // constexpr in C++14
+template<size_t I, class T1, class T2>
+ const typename tuple_element<I, pair<T1, T2> >::type&&
+ get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
+
template<class T1, class T2>
constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
-template<size_t I, class T1, class T2>
+template<class T1, class T2>
constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
-template<size_t I, class T1, class T2>
+template<class T1, class T2>
constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
+template<class T1, class T2>
+ constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
+
+template<class T1, class T2>
+ constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
+
+template<class T1, class T2>
+ constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
+
+template<class T1, class T2>
+ constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
+
+template<class T1, class T2>
+ constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
+
// C++14
template<class T, T... I>
@@ -560,6 +579,12 @@ struct __get_pair<0>
_T1&&
get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
+ template <class _T1, class _T2>
+ static
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+ const _T1&&
+ get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
};
@@ -586,6 +611,12 @@ struct __get_pair<1>
_T2&&
get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
+ template <class _T1, class _T2>
+ static
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+ const _T2&&
+ get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
};
@@ -615,6 +646,14 @@ get(pair<_T1, _T2>&& __p) _NOEXCEPT
return __get_pair<_Ip>::get(_VSTD::move(__p));
}
+template <size_t _Ip, class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
+get(const pair<_T1, _T2>&& __p) _NOEXCEPT
+{
+ return __get_pair<_Ip>::get(_VSTD::move(__p));
+}
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if _LIBCPP_STD_VER > 11
@@ -641,6 +680,13 @@ constexpr _T1 && get(pair<_T1, _T2>&& __
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
+constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
+{
+ return __get_pair<0>::get(_VSTD::move(__p));
+}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
{
return __get_pair<1>::get(__p);
@@ -659,6 +705,13 @@ constexpr _T1 && get(pair<_T2, _T1>&& __
{
return __get_pair<1>::get(_VSTD::move(__p));
}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
+{
+ return __get_pair<1>::get(_VSTD::move(__p));
+}
#endif
Added: libcxx/trunk/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp?rev=255941&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp (added)
+++ libcxx/trunk/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp Thu Dec 17 18:36:55 2015
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// 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> const T&& get(const array<T, N>&& a);
+
+// UNSUPPORTED: c++98, c++03
+
+#include <array>
+#include <memory>
+#include <type_traits>
+#include <utility>
+#include <cassert>
+
+#include "test_macros.h"
+
+// std::array is explicitly allowed to be initialized with A a = { init-list };.
+// Disable the missing braces warning for this reason.
+#include "disable_missing_braces_warning.h"
+
+int main()
+{
+
+ {
+ typedef std::unique_ptr<double> T;
+ typedef std::array<T, 1> C;
+ const C c = {std::unique_ptr<double>(new double(3.5))};
+ static_assert(std::is_same<const T&&, decltype(std::get<0>(std::move(c)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(c))), "");
+ const T&& t = std::get<0>(std::move(c));
+ assert(*t == 3.5);
+ }
+
+#if TEST_STD_VER > 11
+ {
+ typedef double T;
+ typedef std::array<T, 3> C;
+ constexpr const C c = {1, 2, 3.5};
+ static_assert(std::get<0>(std::move(c)) == 1, "");
+ static_assert(std::get<1>(std::move(c)) == 2, "");
+ static_assert(std::get<2>(std::move(c)) == 3.5, "");
+ }
+#endif
+}
Added: libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp?rev=255941&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp (added)
+++ libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.fail.cpp Thu Dec 17 18:36:55 2015
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+// const typename tuple_element<I, tuple<Types...> >::type&&
+// get(const tuple<Types...>&& t);
+
+// UNSUPPORTED: c++98, c++03
+
+#include <tuple>
+
+template <class T> void cref(T const&) {};
+template <class T> void cref(T const&&) = delete;
+
+std::tuple<int> const tup4() { return std::make_tuple(4); }
+
+int main()
+{
+ // LWG2485: tuple should not open a hole in the type system, get() should
+ // imitate [expr.ref]'s rules for accessing data members
+ {
+ cref(std::get<0>(tup4())); // expected-error {{call to deleted function 'cref'}}
+ }
+}
Added: libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.pass.cpp?rev=255941&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const_rv.pass.cpp Thu Dec 17 18:36:55 2015
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+// const typename tuple_element<I, tuple<Types...> >::type&&
+// get(const tuple<Types...>&& t);
+
+// UNSUPPORTED: c++98, c++03
+
+#include <tuple>
+#include <utility>
+#include <string>
+#include <type_traits>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::tuple<int> T;
+ const T t(3);
+ static_assert(std::is_same<const int&&, decltype(std::get<0>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(t))), "");
+ const int&& i = std::get<0>(std::move(t));
+ assert(i == 3);
+ }
+
+ {
+ typedef std::tuple<std::string, int> T;
+ const T t("high", 5);
+ static_assert(std::is_same<const std::string&&, decltype(std::get<0>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(t))), "");
+ static_assert(std::is_same<const int&&, decltype(std::get<1>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<1>(std::move(t))), "");
+ const std::string&& s = std::get<0>(std::move(t));
+ const int&& i = std::get<1>(std::move(t));
+ assert(s == "high");
+ assert(i == 5);
+ }
+
+ {
+ int x = 42;
+ int const y = 43;
+ std::tuple<int&, int const&> const p(x, y);
+ static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(p))), "");
+ static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<1>(std::move(p))), "");
+ }
+
+ {
+ int x = 42;
+ int const y = 43;
+ std::tuple<int&&, int const&&> const p(std::move(x), std::move(y));
+ static_assert(std::is_same<int&&, decltype(std::get<0>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(p))), "");
+ static_assert(std::is_same<int const&&, decltype(std::get<1>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<1>(std::move(p))), "");
+ }
+
+#if TEST_STD_VER > 11
+ {
+ typedef std::tuple<double, int> T;
+ constexpr const T t(2.718, 5);
+ static_assert(std::get<0>(std::move(t)) == 2.718, "");
+ static_assert(std::get<1>(std::move(t)) == 5, "");
+ }
+#endif
+}
Modified: libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp?rev=255941&r1=255940&r2=255941&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp Thu Dec 17 18:36:55 2015
@@ -10,30 +10,31 @@
// UNSUPPORTED: c++98, c++03, c++11
#include <tuple>
+#include <utility>
#include <string>
#include <complex>
+#include <type_traits>
#include <cassert>
int main()
{
-#if _LIBCPP_STD_VER > 11
typedef std::complex<float> cf;
{
auto t1 = std::tuple<int, std::string, cf> { 42, "Hi", { 1,2 }};
- assert ( std::get<int>(t1) == 42 ); // find at the beginning
+ assert ( std::get<int>(t1) == 42 ); // find at the beginning
assert ( std::get<std::string>(t1) == "Hi" ); // find in the middle
assert ( std::get<cf>(t1).real() == 1 ); // find at the end
assert ( std::get<cf>(t1).imag() == 2 );
}
-
+
{
auto t2 = std::tuple<int, std::string, int, cf> { 42, "Hi", 23, { 1,2 }};
// get<int> would fail!
assert ( std::get<std::string>(t2) == "Hi" );
assert (( std::get<cf>(t2) == cf{ 1,2 } ));
}
-
+
{
constexpr std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 };
static_assert ( std::get<int>(p5) == 1, "" );
@@ -53,8 +54,40 @@ int main()
std::tuple<upint> t(upint(new int(4)));
upint p = std::get<upint>(std::move(t)); // get rvalue
assert(*p == 4);
- assert(std::get<0>(t) == nullptr); // has been moved from
+ assert(std::get<upint>(t) == nullptr); // has been moved from
+ }
+
+ {
+ typedef std::unique_ptr<int> upint;
+ const std::tuple<upint> t(upint(new int(4)));
+ const upint&& p = std::get<upint>(std::move(t)); // get const rvalue
+ assert(*p == 4);
+ assert(std::get<upint>(t) != nullptr);
}
-#endif
+ {
+ int x = 42;
+ int tuple y = 43;
+ std::tuple<int&, int const&> const t(x, y);
+ static_assert(std::is_same<int&, decltype(std::get<int&>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<int&>(std::move(t))), "");
+ static_assert(std::is_same<int const&, decltype(std::get<int const&>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<int const&>(std::move(t))), "");
+ }
+
+ {
+ int x = 42;
+ int tuple y = 43;
+ std::tuple<int&&, int const&&> const t(std::move(x), std::move(y));
+ static_assert(std::is_same<int&&, decltype(std::get<int&&>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<int&&>(std::move(t))), "");
+ static_assert(std::is_same<int const&&, decltype(std::get<int const&&>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<int const&&>(std::move(t))), "");
+ }
+
+ {
+ constexpr const std::tuple<int, const int, double, double> t { 1, 2, 3.4, 5.6 };
+ static_assert(std::get<int>(std::move(t)) == 1, "");
+ static_assert(std::get<const int>(std::move(t)) == 2, "");
+ }
}
Added: libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp?rev=255941&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp Thu Dec 17 18:36:55 2015
@@ -0,0 +1,66 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+// const typename tuple_element<I, std::pair<T1, T2> >::type&&
+// get(const pair<T1, T2>&&);
+
+// UNSUPPORTED: c++98, c++03
+
+#include <utility>
+#include <memory>
+#include <type_traits>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main()
+{
+ {
+ typedef std::pair<std::unique_ptr<int>, short> P;
+ const P p(std::unique_ptr<int>(new int(3)), 4);
+ static_assert(std::is_same<const std::unique_ptr<int>&&, decltype(std::get<0>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(p))), "");
+ const std::unique_ptr<int>&& ptr = std::get<0>(std::move(p));
+ assert(*ptr == 3);
+ }
+
+ {
+ int x = 42;
+ int const y = 43;
+ std::pair<int&, int const&> const p(x, y);
+ static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(p))), "");
+ static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<1>(std::move(p))), "");
+ }
+
+ {
+ int x = 42;
+ int const y = 43;
+ std::pair<int&&, int const&&> const p(std::move(x), std::move(y));
+ static_assert(std::is_same<int&&, decltype(std::get<0>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<0>(std::move(p))), "");
+ static_assert(std::is_same<int const&&, decltype(std::get<1>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<1>(std::move(p))), "");
+ }
+
+#if TEST_STD_VER > 11
+ {
+ typedef std::pair<int, short> P;
+ constexpr const P p1(3, 4);
+ static_assert(std::get<0>(std::move(p1)) == 3, "");
+ static_assert(std::get<1>(std::move(p1)) == 4, "");
+ }
+#endif
+}
Modified: libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp?rev=255941&r1=255940&r2=255941&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp Thu Dec 17 18:36:55 2015
@@ -7,15 +7,17 @@
//
//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11
+
#include <utility>
#include <string>
+#include <type_traits>
#include <complex>
#include <cassert>
int main()
{
-#if _LIBCPP_STD_VER > 11
typedef std::complex<float> cf;
{
auto t1 = std::make_pair<int, cf> ( 42, { 1,2 } );
@@ -23,7 +25,7 @@ int main()
assert ( std::get<cf>(t1).real() == 1 );
assert ( std::get<cf>(t1).imag() == 2 );
}
-
+
{
const std::pair<int, const int> p1 { 1, 2 };
const int &i1 = std::get<int>(p1);
@@ -35,10 +37,48 @@ int main()
{
typedef std::unique_ptr<int> upint;
std::pair<upint, int> t(upint(new int(4)), 42);
- upint p = std::get<0>(std::move(t)); // get rvalue
+ upint p = std::get<upint>(std::move(t)); // get rvalue
+ assert(*p == 4);
+ assert(std::get<upint>(t) == nullptr); // has been moved from
+ }
+
+ {
+ typedef std::unique_ptr<int> upint;
+ const std::pair<upint, int> t(upint(new int(4)), 42);
+ static_assert(std::is_same<const upint&&, decltype(std::get<upint>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<upint>(std::move(t))), "");
+ static_assert(std::is_same<const int&&, decltype(std::get<int>(std::move(t)))>::value, "");
+ static_assert(noexcept(std::get<int>(std::move(t))), "");
+ auto&& p = std::get<upint>(std::move(t)); // get const rvalue
+ auto&& i = std::get<int>(std::move(t)); // get const rvalue
assert(*p == 4);
- assert(std::get<0>(t) == nullptr); // has been moved from
+ assert(i == 42);
+ assert(std::get<upint>(t) != nullptr);
}
-#endif
+ {
+ int x = 42;
+ int const y = 43;
+ std::pair<int&, int const&> const p(x, y);
+ static_assert(std::is_same<int&, decltype(std::get<int&>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<int&>(std::move(p))), "");
+ static_assert(std::is_same<int const&, decltype(std::get<int const&>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<int const&>(std::move(p))), "");
+ }
+
+ {
+ int x = 42;
+ int const y = 43;
+ std::pair<int&&, int const&&> const p(std::move(x), std::move(y));
+ static_assert(std::is_same<int&&, decltype(std::get<int&&>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<int&&>(std::move(p))), "");
+ static_assert(std::is_same<int const&&, decltype(std::get<int const&&>(std::move(p)))>::value, "");
+ static_assert(noexcept(std::get<int const&&>(std::move(p))), "");
+ }
+
+ {
+ constexpr const std::pair<int, const int> p { 1, 2 };
+ static_assert(std::get<int>(std::move(p)) == 1, "");
+ static_assert(std::get<const int>(std::move(p)) == 2, "");
+ }
}
Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=255941&r1=255940&r2=255941&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Thu Dec 17 18:36:55 2015
@@ -179,7 +179,7 @@
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2477">2477</a></td><td>Inconsistency of wordings in <tt>std::vector::erase()</tt> and <tt>std::deque::erase()</tt></td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2483">2483</a></td><td><tt>throw_with_nested()</tt> should use <tt>is_final</tt></td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2484">2484</a></td><td><tt>rethrow_if_nested()</tt> is doubly unimplementable</td><td>Kona</td><td>Complete</td></tr>
- <tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2485">2485</a></td><td><tt>get()</tt> should be overloaded for <tt>const tuple&&</tt></td><td>Kona</td><td></td></tr>
+ <tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2485">2485</a></td><td><tt>get()</tt> should be overloaded for <tt>const tuple&&</tt></td><td>Kona</td><td>Completed</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2486">2486</a></td><td><tt>mem_fn()</tt> should be required to use perfect forwarding</td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2487">2487</a></td><td><tt>bind()</tt> should be <tt>const</tt>-overloaded, not <i>cv</i>-overloaded</td><td>Kona</td><td>Complete</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2489">2489</a></td><td><tt>mem_fn()</tt> should be <tt>noexcept</tt></td><td>Kona</td><td>Complete</td></tr>
More information about the cfe-commits
mailing list