diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/utilities/utility/pairs | |
parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) |
Notes
Diffstat (limited to 'test/std/utilities/utility/pairs')
28 files changed, 1067 insertions, 0 deletions
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 0000000000000..b58f5c55b643a --- /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 0000000000000..dbe1c2668665b --- /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 0000000000000..fcda3664d9b62 --- /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 0000000000000..6d61c47ffbf03 --- /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 0000000000000..aa5ca530913c0 --- /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 0000000000000..176d58330d165 --- /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 0000000000000..27194effe5c32 --- /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 0000000000000..f9e3942d7e773 --- /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 0000000000000..484347345747d --- /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 0000000000000..5ac838b37429d --- /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 0000000000000..3756e963fa350 --- /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 0000000000000..90476bcde28c9 --- /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 0000000000000..b58f5c55b643a --- /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 0000000000000..8c7dee2499ddc --- /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 0000000000000..fdef5961437a5 --- /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 0000000000000..a753ee520dfab --- /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 0000000000000..a200390f4882f --- /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 0000000000000..2041b39c2dc91 --- /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 0000000000000..286cce47f0503 --- /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 0000000000000..4b54f717045ad --- /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 0000000000000..bb6661f7966ce --- /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 0000000000000..42a2666dd04b4 --- /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 0000000000000..5fb6c98979b5d --- /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 0000000000000..a912df00d7bb6 --- /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 0000000000000..c16bd71ffcb23 --- /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 0000000000000..9ba8532ab29ec --- /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 0000000000000..48e09735abb02 --- /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 0000000000000..d9d8f27b5225c --- /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); + } +} |