diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
tree | 13f237c02db4d1894ab06884d1b739344766bede /test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp | |
parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
download | src-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.tar.gz src-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.zip |
Vendor import of libc++ trunk r256633:vendor/libc++/r256633
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=292928
svn path=/vendor/libc++/r256633/; revision=292930; tag=vendor/libc++/r256633
Diffstat (limited to 'test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp')
-rw-r--r-- | test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp index aa020dab47c7..b661a78de8db 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp @@ -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 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 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, ""); + } } |