From e99520c72e2906fea3c9ff39d4a46384cdf205f1 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 13 Jul 2013 02:54:05 +0000 Subject: Implement n3584 - Addressing Tuples by Type llvm-svn: 186237 --- .../tuple.tuple/tuple.elem/tuple.by.type.pass.cpp | 52 ++++++++++++++++++++++ .../tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp | 25 +++++++++++ .../tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp | 25 +++++++++++ .../tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp | 25 +++++++++++ .../tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp | 25 +++++++++++ .../pairs/pair.astuple/pairs.by.type.pass.cpp | 44 ++++++++++++++++++ .../pairs/pair.astuple/pairs.by.type1.fail.cpp | 24 ++++++++++ .../pairs/pair.astuple/pairs.by.type2.fail.cpp | 24 ++++++++++ .../pairs/pair.astuple/pairs.by.type3.fail.cpp | 24 ++++++++++ 9 files changed, 268 insertions(+) create mode 100644 libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp create mode 100644 libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp create mode 100644 libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp create mode 100644 libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp create mode 100644 libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp create mode 100644 libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp create mode 100644 libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp create mode 100644 libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp create mode 100644 libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp (limited to 'libcxx/test') diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp new file mode 100644 index 00000000000..1835a9f5284 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex cf; + { + auto t1 = std::tuple { 42, "Hi", { 1,2 }}; + assert ( std::get(t1) == 42 ); // find at the beginning + assert ( std::get(t1) == "Hi" ); // find in the middle + assert ( std::get(t1).real() == 1 ); // find at the end + assert ( std::get(t1).imag() == 2 ); + } + + { + auto t2 = std::tuple { 42, "Hi", 23, { 1,2 }}; +// get would fail! + assert ( std::get(t2) == "Hi" ); + assert (( std::get(t2) == cf{ 1,2 } )); + } + + { + const std::tuple p5 { 1, 2, 3.4, 5.6 }; + const int &i1 = std::get(p5); + const int &i2 = std::get(p5); + assert ( i1 == 1 ); + assert ( i2 == 2 ); + } + + { + typedef std::unique_ptr upint; + std::tuple t(upint(new int(4))); + upint p = std::get(std::move(t)); // get rvalue + assert(*p == 4); + assert(std::get<0>(t) == nullptr); // has been moved from + } + +#endif +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp new file mode 100644 index 00000000000..094f8090542 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex cf; + auto t1 = std::make_tuple ( 42, "Hi" ); + assert ( std::get(t1) == cf {1,2} ); // no such type +#else +#error +#endif +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp new file mode 100644 index 00000000000..0b2fac04c1a --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex cf; + auto t1 = std::make_tuple ( 42, 21, "Hi", { 1,2 } ); + assert ( std::get(t1) == 42 ); // two ints here +#else +#error +#endif +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp new file mode 100644 index 00000000000..f1881717baa --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex cf; + auto t1 = std::make_tuple ( 42, 21, "Hi", { 1,2 } ); + assert ( std::get(t1) == 42 ); // two ints here (one at the end) +#else +#error +#endif +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp new file mode 100644 index 00000000000..e78c4f107c2 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::unique_ptr upint; + std::tuple t(upint(new int(4))); + upint p = std::get(t); +#else +#error +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp new file mode 100644 index 00000000000..176d58330d1 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex cf; + { + auto t1 = std::make_pair ( 42, { 1,2 } ); + assert ( std::get(t1) == 42 ); + assert ( std::get(t1).real() == 1 ); + assert ( std::get(t1).imag() == 2 ); + } + + { + const std::pair p1 { 1, 2 }; + const int &i1 = std::get(p1); + const int &i2 = std::get(p1); + assert ( i1 == 1 ); + assert ( i2 == 2 ); + } + + { + typedef std::unique_ptr upint; + std::pair t(upint(new int(4)), 42); + upint p = std::get<0>(std::move(t)); // get rvalue + assert(*p == 4); + assert(std::get<0>(t) == nullptr); // has been moved from + } + +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp new file mode 100644 index 00000000000..1c01ed74dd8 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex cf; + auto t1 = std::make_pair ( 42, 3.4 ); + assert ( std::get(t1) == cf {1,2} ); // no such type +#else +#error +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp new file mode 100644 index 00000000000..f9e3942d7e7 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex cf; + auto t1 = std::make_pair ( 42, 43 ); + assert ( std::get(t1) == 42 ); // two ints +#else +#error +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp new file mode 100644 index 00000000000..8bf35c7b312 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::unique_ptr upint; + std::pair t(upint(new int(4)), 23); + upint p = std::get(t); +#else +#error +#endif +} -- cgit v1.2.3