diff options
Diffstat (limited to 'test/std/utilities/utility')
48 files changed, 1946 insertions, 0 deletions
diff --git a/test/std/utilities/utility/declval/declval.pass.cpp b/test/std/utilities/utility/declval/declval.pass.cpp new file mode 100644 index 000000000000..81f4df8e8b2b --- /dev/null +++ b/test/std/utilities/utility/declval/declval.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + 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/test/std/utilities/utility/exchange/exchange.pass.cpp b/test/std/utilities/utility/exchange/exchange.pass.cpp new file mode 100644 index 000000000000..620b4149d1d0 --- /dev/null +++ b/test/std/utilities/utility/exchange/exchange.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// utilities + +// exchange + +#include <utility> +#include <cassert> +#include <string> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + int v = 12; + assert ( std::exchange ( v, 23 ) == 12 ); + assert ( v == 23 ); + assert ( std::exchange ( v, 67.2 ) == 23 ); + assert ( v == 67 ); + + assert ((std::exchange<int, float> ( v, {} )) == 67 ); + assert ( v == 0 ); + + } + + { + bool b = false; + assert ( !std::exchange ( b, true )); + assert ( b ); + } + + { + const std::string s1 ( "Hi Mom!" ); + const std::string s2 ( "Yo Dad!" ); + std::string s3 = s1; // Mom + assert ( std::exchange ( s3, s2 ) == s1 ); + assert ( s3 == s2 ); + assert ( std::exchange ( s3, "Hi Mom!" ) == s2 ); + assert ( s3 == s1 ); + + s3 = s2; // Dad + assert ( std::exchange ( s3, {} ) == s2 ); + assert ( s3.size () == 0 ); + + s3 = s2; // Dad + assert ( std::exchange ( s3, "" ) == s2 ); + assert ( s3.size () == 0 ); + } + +#endif +} diff --git a/test/std/utilities/utility/forward/forward.pass.cpp b/test/std/utilities/utility/forward/forward.pass.cpp new file mode 100644 index 000000000000..357b36fafa96 --- /dev/null +++ b/test/std/utilities/utility/forward/forward.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// 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&); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +four test(A&&); +eight test(const A&&); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ + A a; + const A ca = A(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER > 11 + constexpr int i1 = std::move(23); + static_assert(i1 == 23, "" ); + constexpr int i2 = std::forward<int>(42); + static_assert(i2 == 42, "" ); +#endif +} diff --git a/test/std/utilities/utility/forward/forward1.fail.cpp b/test/std/utilities/utility/forward/forward1.fail.cpp new file mode 100644 index 000000000000..43884d54bf86 --- /dev/null +++ b/test/std/utilities/utility/forward/forward1.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. +// +//===----------------------------------------------------------------------===// + +// 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/test/std/utilities/utility/forward/forward2.fail.cpp b/test/std/utilities/utility/forward/forward2.fail.cpp new file mode 100644 index 000000000000..9ff07233fee8 --- /dev/null +++ b/test/std/utilities/utility/forward/forward2.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. +// +//===----------------------------------------------------------------------===// + +// 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/test/std/utilities/utility/forward/forward3.fail.cpp b/test/std/utilities/utility/forward/forward3.fail.cpp new file mode 100644 index 000000000000..7e1e9b38fdc2 --- /dev/null +++ b/test/std/utilities/utility/forward/forward3.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. +// +//===----------------------------------------------------------------------===// + +// 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/test/std/utilities/utility/forward/forward4.fail.cpp b/test/std/utilities/utility/forward/forward4.fail.cpp new file mode 100644 index 000000000000..276506f811b5 --- /dev/null +++ b/test/std/utilities/utility/forward/forward4.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. +// +//===----------------------------------------------------------------------===// + +// 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/test/std/utilities/utility/forward/forward5.fail.cpp b/test/std/utilities/utility/forward/forward5.fail.cpp new file mode 100644 index 000000000000..86c2b5651b90 --- /dev/null +++ b/test/std/utilities/utility/forward/forward5.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. +// +//===----------------------------------------------------------------------===// + +// 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/test/std/utilities/utility/forward/forward6.fail.cpp b/test/std/utilities/utility/forward/forward6.fail.cpp new file mode 100644 index 000000000000..1f4b37d946ca --- /dev/null +++ b/test/std/utilities/utility/forward/forward6.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +int main() +{ + A a; + std::forward(a); // error +} diff --git a/test/std/utilities/utility/forward/move_copy.pass.cpp b/test/std/utilities/utility/forward/move_copy.pass.cpp new file mode 100644 index 000000000000..fa15553f669f --- /dev/null +++ b/test/std/utilities/utility/forward/move_copy.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +// UNSUPPORTED: c++98, c++03 + +#include <utility> +#include <cassert> + +int copy_ctor = 0; +int move_ctor = 0; + +class A +{ +public: + + A(const A&) {++copy_ctor;} + A& operator=(const A&); + + A(A&&) {++move_ctor;} + A& operator=(A&&); + + 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/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp b/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp new file mode 100644 index 000000000000..c8375e9d7238 --- /dev/null +++ b/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> +// typename conditional +// < +// !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, +// const T&, +// T&& +// >::type +// move_if_noexcept(T& x); + +#include <utility> + +#include "test_macros.h" + +class A +{ + A(const A&); + A& operator=(const A&); +public: + + A() {} +#if TEST_STD_VER >= 11 + A(A&&) {} +#endif +}; + +struct legacy +{ + legacy() {} + legacy(const legacy&); +}; + +int main() +{ + int i = 0; + const int ci = 0; + + legacy l; + A a; + const A ca; + +#if TEST_STD_VER >= 11 + 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)), A&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), ""); +#else // C++ < 11 + // libc++ defines decltype to be __typeof__ in C++03. __typeof__ does not + // deduce the reference qualifiers. + 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), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy>::value), ""); +#endif + +#if TEST_STD_VER > 11 + constexpr int i1 = 23; + constexpr int i2 = std::move_if_noexcept(i1); + static_assert(i2 == 23, "" ); +#endif + +} diff --git a/test/std/utilities/utility/forward/move_only.pass.cpp b/test/std/utilities/utility/forward/move_only.pass.cpp new file mode 100644 index 000000000000..520bf5e5b6a1 --- /dev/null +++ b/test/std/utilities/utility/forward/move_only.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +// UNSUPPORTED: c++98, c++03 + +#include <utility> +#include <cassert> + +class move_only +{ + move_only(const move_only&); + move_only& operator=(const move_only&); +public: + move_only(move_only&&) {} + move_only& operator=(move_only&&) {return *this;} + + 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/test/std/utilities/utility/forward/move_only1.fail.cpp b/test/std/utilities/utility/forward/move_only1.fail.cpp new file mode 100644 index 000000000000..5e7623a1bd19 --- /dev/null +++ b/test/std/utilities/utility/forward/move_only1.fail.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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + 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/test/std/utilities/utility/forward/move_only2.fail.cpp b/test/std/utilities/utility/forward/move_only2.fail.cpp new file mode 100644 index 000000000000..2043f3d4bde7 --- /dev/null +++ b/test/std/utilities/utility/forward/move_only2.fail.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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + 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/test/std/utilities/utility/forward/move_only3.fail.cpp b/test/std/utilities/utility/forward/move_only3.fail.cpp new file mode 100644 index 000000000000..84c83ae48f8a --- /dev/null +++ b/test/std/utilities/utility/forward/move_only3.fail.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + 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/test/std/utilities/utility/forward/move_only4.fail.cpp b/test/std/utilities/utility/forward/move_only4.fail.cpp new file mode 100644 index 000000000000..5eeca89abe36 --- /dev/null +++ b/test/std/utilities/utility/forward/move_only4.fail.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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + 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/test/std/utilities/utility/operators/rel_ops.pass.cpp b/test/std/utilities/utility/operators/rel_ops.pass.cpp new file mode 100644 index 000000000000..26e766592f2b --- /dev/null +++ b/test/std/utilities/utility/operators/rel_ops.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// 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/test/std/utilities/utility/pairs/nothing_to_do.pass.cpp b/test/std/utilities/utility/pairs/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/utilities/utility/pairs/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_const.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_const.fail.cpp new file mode 100644 index 000000000000..dbe1c2668665 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_const.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp new file mode 100644 index 000000000000..fcda3664d9b6 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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>&); + +#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); + } + +#if __cplusplus > 201103L + { + typedef std::pair<int, short> P; + constexpr P p1(3, 4); + static_assert(std::get<0>(p1) == 3, ""); + static_assert(std::get<1>(p1) == 4, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp new file mode 100644 index 000000000000..6d61c47ffbf0 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <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> + +#if __cplusplus > 201103L +struct S { + std::pair<int, int> a; + int k; + constexpr S() : a{1,2}, k(std::get<0>(a)) {} + }; + +constexpr std::pair<int, int> getP () { return { 3, 4 }; } +#endif + +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); + } + +#if __cplusplus > 201103L + { + static_assert(S().k == 1, ""); + static_assert(std::get<1>(getP()) == 4, ""); + } +#endif + +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp new file mode 100644 index 000000000000..aa5ca530913c --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// template<size_t I, class T1, class T2> +// typename tuple_element<I, std::pair<T1, T2> >::type&& +// get(pair<T1, T2>&&); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<std::unique_ptr<int>, short> P; + P p(std::unique_ptr<int>(new int(3)), 4); + std::unique_ptr<int> ptr = std::get<0>(std::move(p)); + assert(*ptr == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type.pass.cpp new file mode 100644 index 000000000000..176d58330d16 --- /dev/null +++ b/test/std/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 <utility> +#include <string> +#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 } ); + assert ( std::get<int>(t1) == 42 ); + 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); + const int &i2 = std::get<const int>(p1); + assert ( i1 == 1 ); + assert ( i2 == 2 ); + } + + { + 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 + assert(*p == 4); + assert(std::get<0>(t) == nullptr); // has been moved from + } + +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type1.fail.cpp new file mode 100644 index 000000000000..27194effe5c3 --- /dev/null +++ b/test/std/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 <utility> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_pair<int, double> ( 42, 3.4 ); + assert (( std::get<cf>(t1) == cf {1,2} )); // no such type +#else +#error +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type2.fail.cpp new file mode 100644 index 000000000000..f9e3942d7e77 --- /dev/null +++ b/test/std/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 <utility> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_pair<int, int> ( 42, 43 ); + assert ( std::get<int>(t1) == 42 ); // two ints +#else +#error +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp b/test/std/utilities/utility/pairs/pair.astuple/pairs.by.type3.fail.cpp new file mode 100644 index 000000000000..484347345747 --- /dev/null +++ b/test/std/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 <utility> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::unique_ptr<int> upint; + std::pair<upint, int> t(upint(new int(4)), 23); + upint p = std::get<upint>(t); +#else +#error +#endif +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp new file mode 100644 index 000000000000..5ac838b37429 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/tuple_element.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// tuple_element<I, pair<T1, T2> >::type + +#include <utility> + +template <class T1, class T2> +void test() +{ + { + typedef T1 Exp1; + typedef T2 Exp2; + typedef std::pair<T1, T2> P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } + { + typedef T1 const Exp1; + typedef T2 const Exp2; + typedef std::pair<T1, T2> const P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } + { + typedef T1 volatile Exp1; + typedef T2 volatile Exp2; + typedef std::pair<T1, T2> volatile P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } + { + typedef T1 const volatile Exp1; + typedef T2 const volatile Exp2; + typedef std::pair<T1, T2> const volatile P; + static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), ""); + static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), ""); + } +} + +int main() +{ + test<int, short>(); + test<int*, char>(); +} diff --git a/test/std/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp b/test/std/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp new file mode 100644 index 000000000000..3756e963fa35 --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.astuple/tuple_size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// tuple_size<pair<T1, T2> >::value + +#include <utility> + +int main() +{ + { + typedef std::pair<int, short> P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } + { + typedef std::pair<int, short> const P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } + { + typedef std::pair<int, short> volatile P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } + { + typedef std::pair<int, short> const volatile P1; + static_assert((std::tuple_size<P1>::value == 2), ""); + } +} diff --git a/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp b/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp new file mode 100644 index 000000000000..90476bcde28c --- /dev/null +++ b/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// struct piecewise_construct_t { }; +// constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); + +#include <utility> +#include <tuple> +#include <cassert> + +class A +{ + int i_; + char c_; +public: + A(int i, char c) : i_(i), c_(c) {} + int get_i() const {return i_;} + char get_c() const {return c_;} +}; + +class B +{ + double d_; + unsigned u1_; + unsigned u2_; +public: + B(double d, unsigned u1, unsigned u2) : d_(d), u1_(u1), u2_(u2) {} + double get_d() const {return d_;} + unsigned get_u1() const {return u1_;} + unsigned get_u2() const {return u2_;} +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::pair<A, B> p(std::piecewise_construct, + std::make_tuple(4, 'a'), + std::make_tuple(3.5, 6u, 2u)); + assert(p.first.get_i() == 4); + assert(p.first.get_c() == 'a'); + assert(p.second.get_d() == 3.5); + assert(p.second.get_u1() == 6u); + assert(p.second.get_u2() == 2u); +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp b/test/std/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/U_V.pass.cpp new file mode 100644 index 000000000000..8c7dee2499dd --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/U_V.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp new file mode 100644 index 000000000000..fdef5961437a --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp new file mode 100644 index 000000000000..a753ee520dfa --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T1, class T2> struct pair + +// pair& operator=(pair&& p); + +#include <utility> +#include <memory> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp new file mode 100644 index 000000000000..a200390f4882 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// 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<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() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp new file mode 100644 index 000000000000..2041b39c2dc9 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// 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) const {return data_ == a.data_;} +}; + +#if _LIBCPP_STD_VER > 11 +class AC +{ + int data_; +public: + constexpr AC(int data) : data_(data) {} + + constexpr bool operator==(const AC& a) const {return data_ == a.data_;} +}; +#endif + +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); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<float, short*> P; + constexpr P p(3.5f, 0); + static_assert(p.first == 3.5f, ""); + static_assert(p.second == nullptr, ""); + } + { + typedef std::pair<AC, int> P; + constexpr P p(1, 2); + static_assert(p.first == AC(1), ""); + static_assert(p.second == 2, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp new file mode 100644 index 000000000000..286cce47f050 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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 <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); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P1; + typedef std::pair<double, long> P2; + constexpr P1 p1(3, 4); + constexpr P2 p2 = p1; + static_assert(p2.first == 3, ""); + static_assert(p2.second == 4, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp new file mode 100644 index 000000000000..4b54f717045a --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// 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); + } + + static_assert((std::is_trivially_copy_constructible<std::pair<int, int> >::value), ""); + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P1; + constexpr P1 p1(3, 4); + constexpr P1 p2 = p1; + static_assert(p2.first == 3, ""); + static_assert(p2.second == 4, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp new file mode 100644 index 000000000000..bb6661f7966c --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// 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); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<float, short*> P; + constexpr P p; + static_assert(p.first == 0.0f, ""); + static_assert(p.second == nullptr, ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp new file mode 100644 index 000000000000..42a2666dd04b --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 <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 // _LIBCPP_HAS_NO_VARIADICS +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp new file mode 100644 index 000000000000..5fb6c98979b5 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 <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() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp new file mode 100644 index 000000000000..a912df00d7bb --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// 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/test/std/utilities/utility/pairs/pairs.pair/types.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/types.pass.cpp new file mode 100644 index 000000000000..c16bd71ffcb2 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// { +// 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/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp b/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp new file mode 100644 index 000000000000..9ba8532ab29e --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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 <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)); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P; + constexpr P p1(3, 4); + constexpr P p2(3, 2); + static_assert(!(p1 == p2), ""); + static_assert( (p1 != p2), ""); + static_assert(!(p1 < p2), ""); + static_assert(!(p1 <= p2), ""); + static_assert( (p1 > p2), ""); + static_assert( (p1 >= p2), ""); + } +#endif +} diff --git a/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp b/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp new file mode 100644 index 000000000000..48e09735abb0 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// <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); + } + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<int, short> P1; + constexpr P1 p1 = std::make_pair(3, 4); + static_assert(p1.first == 3, ""); + static_assert(p1.second == 4, ""); + } +#endif + +} diff --git a/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp b/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp new file mode 100644 index 000000000000..d9d8f27b5225 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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 <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/test/std/utilities/utility/utility.swap/swap.pass.cpp b/test/std/utilities/utility/utility.swap/swap.pass.cpp new file mode 100644 index 000000000000..8606611f6603 --- /dev/null +++ b/test/std/utilities/utility/utility.swap/swap.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 T> +// requires MoveAssignable<T> && MoveConstructible<T> +// void +// swap(T& a, T& b); + +#include <utility> +#include <cassert> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#include <memory> +#endif + +void +test() +{ + int i = 1; + int j = 2; + std::swap(i, j); + assert(i == 2); + assert(j == 1); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ + test(); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test1(); +#endif +} diff --git a/test/std/utilities/utility/utility.swap/swap_array.pass.cpp b/test/std/utilities/utility/utility.swap/swap_array.pass.cpp new file mode 100644 index 000000000000..b1209c3c3651 --- /dev/null +++ b/test/std/utilities/utility/utility.swap/swap_array.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// 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<ValueType T, size_t N> +// requires Swappable<T> +// void +// swap(T (&a)[N], T (&b)[N]); + +#include <utility> +#include <cassert> +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#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); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ + test(); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test1(); +#endif +} diff --git a/test/std/utilities/utility/version.pass.cpp b/test/std/utilities/utility/version.pass.cpp new file mode 100644 index 000000000000..77d145d94457 --- /dev/null +++ b/test/std/utilities/utility/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +#include <utility> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |