diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
| commit | 3e519524c118651123eecf60c2bbc5d65ad9bac3 (patch) | |
| tree | b2dd4168cfe448920a602cd7d2e40f95da187153 /libcxx/test/utilities/utility | |
| parent | 9132c59d43b6c590c9bb33496eebf9f192d6857a (diff) | |
| download | bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.tar.gz bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.zip | |
libcxx initial import
llvm-svn: 103490
Diffstat (limited to 'libcxx/test/utilities/utility')
44 files changed, 1613 insertions, 0 deletions
diff --git a/libcxx/test/utilities/utility/declval/declval.pass.cpp b/libcxx/test/utilities/utility/declval/declval.pass.cpp new file mode 100644 index 00000000000..eacf1f1daa6 --- /dev/null +++ b/libcxx/test/utilities/utility/declval/declval.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T> typename add_rvalue_reference<T>::type declval() noexcept; + +#include <utility> +#include <type_traits> + +class A +{ + A(const A&); + A& operator=(const A&); +}; + +int main() +{ +#ifdef _LIBCPP_MOVE + static_assert((std::is_same<decltype(std::declval<A>()), A&&>::value), ""); +#else + static_assert((std::is_same<decltype(std::declval<A>()), A>::value), ""); +#endif +} diff --git a/libcxx/test/utilities/utility/forward/forward.pass.cpp b/libcxx/test/utilities/utility/forward/forward.pass.cpp new file mode 100644 index 00000000000..1667491a4f2 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/forward.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> +#include <cassert> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +typedef char one; +struct two {one _[2];}; +struct four {one _[4];}; +struct eight {one _[8];}; + +one test(A&); +two test(const A&); + +#ifdef _LIBCPP_MOVE + +four test(A&&); +eight test(const A&&); + +#endif + +int main() +{ + A a; + const A ca = A(); + +#ifdef _LIBCPP_MOVE + static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); + static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); + static_assert(sizeof(test(std::forward<A>(source()))) == 4, ""); + + static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); +// static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(a))) == 8, ""); + static_assert(sizeof(test(std::forward<const A>(source()))) == 8, ""); + + static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); +// static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(ca))) == 8, ""); + static_assert(sizeof(test(std::forward<const A>(csource()))) == 8, ""); + +#else + + static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); + static_assert(sizeof(test(std::forward<A>(a))) == 1, ""); +// static_assert(sizeof(test(std::forward<A>(source()))) == 2, ""); + + static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); + static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(a))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(source()))) == 2, ""); + + static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); + static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(ca))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, ""); +#endif +} diff --git a/libcxx/test/utilities/utility/forward/forward1.fail.cpp b/libcxx/test/utilities/utility/forward/forward1.fail.cpp new file mode 100644 index 00000000000..eab3b8bb210 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/forward1.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + std::forward<A&>(source()); // error +} diff --git a/libcxx/test/utilities/utility/forward/forward2.fail.cpp b/libcxx/test/utilities/utility/forward/forward2.fail.cpp new file mode 100644 index 00000000000..e2c387401c2 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/forward2.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A&>(ca); // error +} diff --git a/libcxx/test/utilities/utility/forward/forward3.fail.cpp b/libcxx/test/utilities/utility/forward/forward3.fail.cpp new file mode 100644 index 00000000000..3a681fc9f48 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/forward3.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + std::forward<A&>(csource()); // error +} diff --git a/libcxx/test/utilities/utility/forward/forward4.fail.cpp b/libcxx/test/utilities/utility/forward/forward4.fail.cpp new file mode 100644 index 00000000000..f6e0036db9e --- /dev/null +++ b/libcxx/test/utilities/utility/forward/forward4.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A>(ca); // error +} diff --git a/libcxx/test/utilities/utility/forward/forward5.fail.cpp b/libcxx/test/utilities/utility/forward/forward5.fail.cpp new file mode 100644 index 00000000000..a590ea63271 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/forward5.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A>(csource()); // error +} diff --git a/libcxx/test/utilities/utility/forward/forward6.fail.cpp b/libcxx/test/utilities/utility/forward/forward6.fail.cpp new file mode 100644 index 00000000000..0c13448f533 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/forward6.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +int main() +{ + A a; + std::forward(a); // error +} diff --git a/libcxx/test/utilities/utility/forward/move_copy.pass.cpp b/libcxx/test/utilities/utility/forward/move_copy.pass.cpp new file mode 100644 index 00000000000..94a27d5f034 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/move_copy.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +int copy_ctor = 0; +int move_ctor = 0; + +class A +{ +#ifdef _LIBCPP_MOVE +#else +#endif + +public: + +#ifdef _LIBCPP_MOVE + A(const A&) {++copy_ctor;} + A& operator=(const A&); + + A(A&&) {++move_ctor;} + A& operator=(A&&); +#else + A(const A&) {++copy_ctor;} + A& operator=(A&); + + operator std::__rv<A> () {return std::__rv<A>(*this);} + A(std::__rv<A>) {++move_ctor;} +#endif + + A() {} +}; + +A source() {return A();} +const A csource() {return A();} + +void test(A) {} + +int main() +{ + A a; + const A ca = A(); + + assert(copy_ctor == 0); + assert(move_ctor == 0); + + A a2 = a; + assert(copy_ctor == 1); + assert(move_ctor == 0); + + A a3 = std::move(a); + assert(copy_ctor == 1); + assert(move_ctor == 1); + + A a4 = ca; + assert(copy_ctor == 2); + assert(move_ctor == 1); + + A a5 = std::move(ca); + assert(copy_ctor == 3); + assert(move_ctor == 1); +} diff --git a/libcxx/test/utilities/utility/forward/move_if_noexcept.pass.cpp b/libcxx/test/utilities/utility/forward/move_if_noexcept.pass.cpp new file mode 100644 index 00000000000..1646b20d299 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/move_if_noexcept.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T> +// typename conditional +// < +// !has_nothrow_move_constructor<T>::value && has_copy_constructor<T>::value, +// const T&, +// T&& +// >::type +// move_if_noexcept(T& x); + +#include <utility> + +class A +{ + A(const A&); + A& operator=(const A&); +public: + + A() {} +#ifdef _LIBCPP_MOVE + A(A&&) {} +#endif +}; + +int main() +{ + int i = 0; + const int ci = 0; + + A a; + const A ca; + +#ifdef _LIBCPP_MOVE + static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&>::value), ""); +#else + static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A>::value), ""); +#endif + +} diff --git a/libcxx/test/utilities/utility/forward/move_only.pass.cpp b/libcxx/test/utilities/utility/forward/move_only.pass.cpp new file mode 100644 index 00000000000..350ed86dfb8 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/move_only.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +class move_only +{ +#ifdef _LIBCPP_MOVE + move_only(const move_only&); + move_only& operator=(const move_only&); +#else + move_only(move_only&); + move_only& operator=(move_only&); +#endif + +public: + +#ifdef _LIBCPP_MOVE + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only mo; + + test(std::move(mo)); + test(source()); +} diff --git a/libcxx/test/utilities/utility/forward/move_only1.fail.cpp b/libcxx/test/utilities/utility/forward/move_only1.fail.cpp new file mode 100644 index 00000000000..53559bc47b9 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/move_only1.fail.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifdef _LIBCPP_MOVE + move_only(const move_only&); + move_only& operator=(const move_only&); +#else + move_only(move_only&); + move_only& operator=(move_only&); +#endif + +public: + +#ifdef _LIBCPP_MOVE + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(a); +} diff --git a/libcxx/test/utilities/utility/forward/move_only2.fail.cpp b/libcxx/test/utilities/utility/forward/move_only2.fail.cpp new file mode 100644 index 00000000000..7f4eff51d08 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/move_only2.fail.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifdef _LIBCPP_MOVE + move_only(const move_only&); + move_only& operator=(const move_only&); +#else + move_only(move_only&); + move_only& operator=(move_only&); +#endif + +public: + +#ifdef _LIBCPP_MOVE + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(ca); +} diff --git a/libcxx/test/utilities/utility/forward/move_only3.fail.cpp b/libcxx/test/utilities/utility/forward/move_only3.fail.cpp new file mode 100644 index 00000000000..a6f87cfaed0 --- /dev/null +++ b/libcxx/test/utilities/utility/forward/move_only3.fail.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +class move_only +{ +#ifdef _LIBCPP_MOVE + move_only(const move_only&); + move_only& operator=(const move_only&); +#else + move_only(move_only&); + move_only& operator=(move_only&); +#endif + +public: + +#ifdef _LIBCPP_MOVE + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(std::move(ca)); +} diff --git a/libcxx/test/utilities/utility/forward/move_only4.fail.cpp b/libcxx/test/utilities/utility/forward/move_only4.fail.cpp new file mode 100644 index 00000000000..181aa3451ed --- /dev/null +++ b/libcxx/test/utilities/utility/forward/move_only4.fail.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifdef _LIBCPP_MOVE + move_only(const move_only&); + move_only& operator=(const move_only&); +#else + move_only(move_only&); + move_only& operator=(move_only&); +#endif + +public: + +#ifdef _LIBCPP_MOVE + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(csource()); +} diff --git a/libcxx/test/utilities/utility/operators/rel_ops.pass.cpp b/libcxx/test/utilities/utility/operators/rel_ops.pass.cpp new file mode 100644 index 00000000000..4be33ea5e32 --- /dev/null +++ b/libcxx/test/utilities/utility/operators/rel_ops.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test rel_ops + +#include <utility> +#include <cassert> + +struct A +{ + int data_; + + explicit A(int data = -1) : data_(data) {} +}; + +inline +bool +operator == (const A& x, const A& y) +{ + return x.data_ == y.data_; +} + +inline +bool +operator < (const A& x, const A& y) +{ + return x.data_ < y.data_; +} + +int main() +{ + using namespace std::rel_ops; + A a1(1); + A a2(2); + assert(a1 == a1); + assert(a1 != a2); + assert(a1 < a2); + assert(a2 > a1); + assert(a1 <= a1); + assert(a1 <= a2); + assert(a2 >= a2); + assert(a2 >= a1); +} diff --git a/libcxx/test/utilities/utility/pairs/nothing_to_do.pass.cpp b/libcxx/test/utilities/utility/pairs/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..fa4d462f18d --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/get_const.fail.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/get_const.fail.cpp new file mode 100644 index 00000000000..b9a53ada329 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/get_const.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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>&); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P; + const P p(3, 4); + assert(std::get<0>(p) == 3); + assert(std::get<1>(p) == 4); + std::get<0>(p) = 5; + } +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp new file mode 100644 index 00000000000..a04f16f0ca6 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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>&); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P; + const P p(3, 4); + assert(std::get<0>(p) == 3); + assert(std::get<1>(p) == 4); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp new file mode 100644 index 00000000000..27e207bba1d --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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 <cassert> + +int main() +{ + { + typedef std::pair<int, short> P; + P p(3, 4); + assert(std::get<0>(p) == 3); + assert(std::get<1>(p) == 4); + std::get<0>(p) = 5; + std::get<1>(p) = 6; + assert(std::get<0>(p) == 5); + assert(std::get<1>(p) == 6); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp new file mode 100644 index 00000000000..0edf08b0b43 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// tuple_element<I, pair<T1, T2> >::type + +#include <utility> + +int main() +{ + { + typedef std::pair<int, short> P1; + static_assert((std::is_same<std::tuple_element<0, P1>::type, int>::value), ""); + static_assert((std::is_same<std::tuple_element<1, P1>::type, short>::value), ""); + } + { + typedef std::pair<int*, char> P1; + static_assert((std::is_same<std::tuple_element<0, P1>::type, int*>::value), ""); + static_assert((std::is_same<std::tuple_element<1, P1>::type, char>::value), ""); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp new file mode 100644 index 00000000000..eba41f1c75b --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// tuple_size<pair<T1, T2> >::value + +#include <utility> + +int main() +{ + { + typedef std::pair<int, short> P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp new file mode 100644 index 00000000000..106eed9cbe3 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// struct piecewise_construct_t { }; +// constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); + +#include <utility> + +int main() +{ + std::piecewise_construct_t p = std::piecewise_construct; +} diff --git a/libcxx/test/utilities/utility/pairs/pair.range/begin.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.range/begin.pass.cpp new file mode 100644 index 00000000000..7f7de2960d5 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.range/begin.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class InputIterator> +// InputIterator +// begin(const std::pair<InputIterator, InputIterator>& p); + +#include <utility> +#include <iterator> +#include <cassert> + +int main() +{ + { + typedef std::pair<int*, int*> P; + int a[3] = {0}; + P p(std::begin(a), std::end(a)); + assert(std::begin(p) == a); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pair.range/end.pass.cpp b/libcxx/test/utilities/utility/pairs/pair.range/end.pass.cpp new file mode 100644 index 00000000000..b1d8dacee3e --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pair.range/end.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class InputIterator> +// InputIterator +// end(const std::pair<InputIterator, InputIterator>& p); + +#include <utility> +#include <iterator> +#include <cassert> + +int main() +{ + { + typedef std::pair<int*, int*> P; + int a[3] = {0}; + P p(std::begin(a), std::end(a)); + assert(std::end(p) == a+3); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..fa4d462f18d --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/U_V.pass.cpp new file mode 100644 index 00000000000..c4ecf6ebd10 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/U_V.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<class U, class V> pair(U&& x, V&& y); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<std::unique_ptr<int>, short*> P; + P p(std::unique_ptr<int>(new int(3)), nullptr); + assert(*p.first == 3); + assert(p.second == nullptr); + } +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp new file mode 100644 index 00000000000..99f29918fe0 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<class U, class V> pair& operator=(const pair<U, V>& p); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + typedef std::pair<double, long> P2; + P1 p1(3, 4); + P2 p2; + p2 = p1; + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp new file mode 100644 index 00000000000..2c7b2bda2c2 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair& operator=(pair&& p); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<std::unique_ptr<int>, short> P; + P p1(std::unique_ptr<int>(new int(3)), 4); + P p2; + p2 = std::move(p1); + assert(*p2.first == 3); + assert(p2.second == 4); + } +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp new file mode 100644 index 00000000000..0048ce8f119 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<class U, class V> pair& operator=(pair<U, V>&& p); + +#include <utility> +#include <memory> +#include <cassert> + +struct Base +{ + virtual ~Base() {} +}; + +struct Derived + : public Base +{ +}; + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<std::unique_ptr<Derived>, short> P1; + typedef std::pair<std::unique_ptr<Base>, long> P2; + P1 p1(std::unique_ptr<Derived>(), 4); + P2 p2; + p2 = std::move(p1); + assert(p2.first == nullptr); + assert(p2.second == 4); + } +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/comparison.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/comparison.pass.cpp new file mode 100644 index 00000000000..0c6297a6466 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/comparison.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); +// template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P; + P p1(3, 4); + P p2(3, 4); + assert( (p1 == p2)); + assert(!(p1 != p2)); + assert(!(p1 < p2)); + assert( (p1 <= p2)); + assert(!(p1 > p2)); + assert( (p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(2, 4); + P p2(3, 4); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert( (p1 < p2)); + assert( (p1 <= p2)); + assert(!(p1 > p2)); + assert(!(p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(3, 2); + P p2(3, 4); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert( (p1 < p2)); + assert( (p1 <= p2)); + assert(!(p1 > p2)); + assert(!(p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(3, 4); + P p2(2, 4); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert(!(p1 < p2)); + assert(!(p1 <= p2)); + assert( (p1 > p2)); + assert( (p1 >= p2)); + } + { + typedef std::pair<int, short> P; + P p1(3, 4); + P p2(3, 2); + assert(!(p1 == p2)); + assert( (p1 != p2)); + assert(!(p1 < p2)); + assert(!(p1 <= p2)); + assert( (p1 > p2)); + assert( (p1 >= p2)); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp new file mode 100644 index 00000000000..d13b1c59e0c --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair(const T1& x, const T2& y); + +#include <utility> +#include <cassert> + +class A +{ + int data_; +public: + A(int data) : data_(data) {} + + bool operator==(const A& a) {return data_ == a.data_;} +}; + +int main() +{ + { + typedef std::pair<float, short*> P; + P p(3.5f, 0); + assert(p.first == 3.5f); + assert(p.second == nullptr); + } + { + typedef std::pair<A, int> P; + P p(1, 2); + assert(p.first == A(1)); + assert(p.second == 2); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp new file mode 100644 index 00000000000..86fa7904d66 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class U, class V> pair(const pair<U, V>& p); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + typedef std::pair<double, long> P2; + P1 p1(3, 4); + P2 p2 = p1; + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp new file mode 100644 index 00000000000..874d17e67be --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair(const pair&) = default; + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1(3, 4); + P1 p2 = p1; + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/default.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/default.pass.cpp new file mode 100644 index 00000000000..16ff4bde762 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/default.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// constexpr pair(); + +#include <utility> +#include <cassert> + +int main() +{ + typedef std::pair<float, short*> P; + P p; + assert(p.first == 0.0f); + assert(p.second == nullptr); +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/make_pair.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/make_pair.pass.cpp new file mode 100644 index 00000000000..60e7e101f10 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/make_pair.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1 = std::make_pair(3, 4); + assert(p1.first == 3); + assert(p1.second == 4); + } +#ifdef _LIBCPP_MOVE + { + typedef std::pair<std::unique_ptr<int>, short> P1; + P1 p1 = std::make_pair(std::unique_ptr<int>(new int(3)), 4); + assert(*p1.first == 3); + assert(p1.second == 4); + } + { + typedef std::pair<std::unique_ptr<int>, short> P1; + P1 p1 = std::make_pair(nullptr, 4); + assert(p1.first == nullptr); + assert(p1.second == 4); + } +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/non_member_swap.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/non_member_swap.pass.cpp new file mode 100644 index 00000000000..626d98f647d --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/non_member_swap.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class T1, class T2> void swap(pair<T1, T2>& x, pair<T1, T2>& y); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1(3, 4); + P1 p2(5, 6); + swap(p1, p2); + assert(p1.first == 5); + assert(p1.second == 6); + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp new file mode 100644 index 00000000000..3f411029180 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class... Args1, class... Args2> +// pair(piecewise_construct_t, tuple<Args1...> first_args, +// tuple<Args2...> second_args); + +#include <utility> +#include <tuple> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + { + typedef std::pair<int, int*> P1; + typedef std::pair<int*, int> P2; + typedef std::pair<P1, P2> P3; + P3 p3(std::piecewise_construct, std::tuple<int, int*>(3, nullptr), + std::tuple<int*, int>(nullptr, 4)); + assert(p3.first == P1(3, nullptr)); + assert(p3.second == P2(nullptr, 4)); + } +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp new file mode 100644 index 00000000000..0476a370f04 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template <class U, class V> pair(pair<U, V>&& p); + +#include <utility> +#include <memory> +#include <cassert> + +struct Base +{ + virtual ~Base() {} +}; + +struct Derived + : public Base +{ +}; + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<std::unique_ptr<Derived>, short> P1; + typedef std::pair<std::unique_ptr<Base>, long> P2; + P1 p1(std::unique_ptr<Derived>(), 4); + P2 p2 = std::move(p1); + assert(p2.first == nullptr); + assert(p2.second == 4); + } +#endif +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/swap.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/swap.pass.cpp new file mode 100644 index 00000000000..2898144db96 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/swap.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// void swap(pair& p); + +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<int, short> P1; + P1 p1(3, 4); + P1 p2(5, 6); + p1.swap(p2); + assert(p1.first == 5); + assert(p1.second == 6); + assert(p2.first == 3); + assert(p2.second == 4); + } +} diff --git a/libcxx/test/utilities/utility/pairs/pairs.pair/types.pass.cpp b/libcxx/test/utilities/utility/pairs/pairs.pair/types.pass.cpp new file mode 100644 index 00000000000..dd217a56e22 --- /dev/null +++ b/libcxx/test/utilities/utility/pairs/pairs.pair/types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> +// struct pair +// { +// typedef T1 first_type; +// typedef T2 second_type; + + +#include <utility> +#include <type_traits> + +int main() +{ + typedef std::pair<float, short*> P; + static_assert((std::is_same<P::first_type, float>::value), ""); + static_assert((std::is_same<P::second_type, short*>::value), ""); +} diff --git a/libcxx/test/utilities/utility/utility.swap/swap.pass.cpp b/libcxx/test/utilities/utility/utility.swap/swap.pass.cpp new file mode 100644 index 00000000000..acb366418d6 --- /dev/null +++ b/libcxx/test/utilities/utility/utility.swap/swap.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<class T> +// requires MoveAssignable<T> && MoveConstructible<T> +// void +// swap(T& a, T& b); + +#include <utility> +#include <cassert> +#ifdef _LIBCPP_MOVE +#include <memory> +#endif + +void +test() +{ + int i = 1; + int j = 2; + std::swap(i, j); + assert(i == 2); + assert(j == 1); +} + +#ifdef _LIBCPP_MOVE + +void +test1() +{ + std::unique_ptr<int> i(new int(1)); + std::unique_ptr<int> j(new int(2)); + std::swap(i, j); + assert(*i == 2); + assert(*j == 1); +} + +#endif + +int main() +{ + test(); +#ifdef _LIBCPP_MOVE + test1(); +#endif +} diff --git a/libcxx/test/utilities/utility/utility.swap/swap_array.pass.cpp b/libcxx/test/utilities/utility/utility.swap/swap_array.pass.cpp new file mode 100644 index 00000000000..1ab168973ac --- /dev/null +++ b/libcxx/test/utilities/utility/utility.swap/swap_array.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template<ValueType T, size_t N> +// requires Swappable<T> +// void +// swap(T (&a)[N], T (&b)[N]); + +#include <utility> +#include <cassert> +#ifdef _LIBCPP_MOVE +#include <memory> +#endif + +void +test() +{ + int i[3] = {1, 2, 3}; + int j[3] = {4, 5, 6}; + std::swap(i, j); + assert(i[0] == 4); + assert(i[1] == 5); + assert(i[2] == 6); + assert(j[0] == 1); + assert(j[1] == 2); + assert(j[2] == 3); +} + +#ifdef _LIBCPP_MOVE + +void +test1() +{ + std::unique_ptr<int> i[3]; + for (int k = 0; k < 3; ++k) + i[k].reset(new int(k+1)); + std::unique_ptr<int> j[3]; + for (int k = 0; k < 3; ++k) + j[k].reset(new int(k+4)); + std::swap(i, j); + assert(*i[0] == 4); + assert(*i[1] == 5); + assert(*i[2] == 6); + assert(*j[0] == 1); + assert(*j[1] == 2); + assert(*j[2] == 3); +} + +#endif + +int main() +{ + test(); +#ifdef _LIBCPP_MOVE + test1(); +#endif +} diff --git a/libcxx/test/utilities/utility/version.pass.cpp b/libcxx/test/utilities/utility/version.pass.cpp new file mode 100644 index 00000000000..5eb9b212718 --- /dev/null +++ b/libcxx/test/utilities/utility/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +#include <utility> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |

