diff options
author | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
commit | 5a83710e371fe68a06e6e3876c6a2c8b820a8976 (patch) | |
tree | afde4c82ad6704681781c5cd49baa3fbd05c85db /libcxx/test/std/utilities/tuple/tuple.tuple | |
parent | f11e8eab527fba316c64112f6e05de1a79693a3e (diff) | |
download | bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.tar.gz bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.zip |
Move test into test/std subdirectory.
llvm-svn: 224658
Diffstat (limited to 'libcxx/test/std/utilities/tuple/tuple.tuple')
58 files changed, 3785 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/MoveOnly.h b/libcxx/test/std/utilities/tuple/tuple.tuple/MoveOnly.h new file mode 100644 index 00000000000..e4d9f649560 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/MoveOnly.h @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef MOVEONLY_H +#define MOVEONLY_H + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#include <cstddef> +#include <functional> + +class MoveOnly +{ + MoveOnly(const MoveOnly&); + MoveOnly& operator=(const MoveOnly&); + + int data_; +public: + MoveOnly(int data = 1) : data_(data) {} + MoveOnly(MoveOnly&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly& operator=(MoveOnly&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + + int get() const {return data_;} + + bool operator==(const MoveOnly& x) const {return data_ == x.data_;} + bool operator< (const MoveOnly& x) const {return data_ < x.data_;} +}; + +namespace std { + +template <> +struct hash<MoveOnly> + : public std::unary_function<MoveOnly, std::size_t> +{ + std::size_t operator()(const MoveOnly& x) const {return x.get();} +}; + +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // MOVEONLY_H diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/TupleFunction.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/TupleFunction.pass.cpp new file mode 100644 index 00000000000..df5fdff511e --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/TupleFunction.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. +// +//===----------------------------------------------------------------------===// + +// This is for bugs 18853 and 19118 + +#if __cplusplus >= 201103L + +#include <tuple> +#include <functional> + +struct X +{ + X() {} + + template <class T> + X(T); + + void operator()() {} +}; + +int +main() +{ + X x; + std::function<void()> f(x); +} +#else +int main () {} +#endif diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/alloc_first.h b/libcxx/test/std/utilities/tuple/tuple.tuple/alloc_first.h new file mode 100644 index 00000000000..237a2897e87 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/alloc_first.h @@ -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. +// +//===----------------------------------------------------------------------===// + +#ifndef ALLOC_FIRST_H +#define ALLOC_FIRST_H + +#include <cassert> + +#include "allocators.h" + +struct alloc_first +{ + static bool allocator_constructed; + + typedef A1<int> allocator_type; + + int data_; + + alloc_first() : data_(0) {} + alloc_first(int d) : data_(d) {} + alloc_first(std::allocator_arg_t, const A1<int>& a) + : data_(0) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_first(std::allocator_arg_t, const A1<int>& a, int d) + : data_(d) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_first(std::allocator_arg_t, const A1<int>& a, const alloc_first& d) + : data_(d.data_) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + ~alloc_first() {data_ = -1;} + + friend bool operator==(const alloc_first& x, const alloc_first& y) + {return x.data_ == y.data_;} + friend bool operator< (const alloc_first& x, const alloc_first& y) + {return x.data_ < y.data_;} +}; + +bool alloc_first::allocator_constructed = false; + +#endif // ALLOC_FIRST_H diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/alloc_last.h b/libcxx/test/std/utilities/tuple/tuple.tuple/alloc_last.h new file mode 100644 index 00000000000..71a9b9e97ac --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/alloc_last.h @@ -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. +// +//===----------------------------------------------------------------------===// + +#ifndef ALLOC_LAST_H +#define ALLOC_LAST_H + +#include <cassert> + +#include "allocators.h" + +struct alloc_last +{ + static bool allocator_constructed; + + typedef A1<int> allocator_type; + + int data_; + + alloc_last() : data_(0) {} + alloc_last(int d) : data_(d) {} + alloc_last(const A1<int>& a) + : data_(0) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_last(int d, const A1<int>& a) + : data_(d) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + alloc_last(const alloc_last& d, const A1<int>& a) + : data_(d.data_) + { + assert(a.id() == 5); + allocator_constructed = true; + } + + ~alloc_last() {data_ = -1;} + + friend bool operator==(const alloc_last& x, const alloc_last& y) + {return x.data_ == y.data_;} + friend bool operator< (const alloc_last& x, const alloc_last& y) + {return x.data_ < y.data_;} +}; + +bool alloc_last::allocator_constructed = false; + +#endif // ALLOC_LAST_H diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/empty_member.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/empty_member.pass.cpp new file mode 100644 index 00000000000..ddf558cfc8d --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/empty_member.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// This is not a portable test + +#include <tuple> + +struct A {}; + +struct B {}; + +int main() +{ + { + typedef std::tuple<int, A> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, int> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, int, B> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, B, int> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<int, A, B> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp new file mode 100644 index 00000000000..677bd044956 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> +// tuple& operator=(const pair<U1, U2>& u); + +#include <tuple> +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<double, char> T0; + typedef std::tuple<int, short> T1; + T0 t0(2.5, 'a'); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == short('a')); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp new file mode 100644 index 00000000000..a0848594d70 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// tuple& operator=(const tuple<UTypes...>& u); + +#include <tuple> +#include <string> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i = 0) : id_(i) {} +}; + +struct D + : B +{ + explicit D(int i = 0) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1; + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + D d2(2); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d2); + T1 t1(1.5, 'b', d); + t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp new file mode 100644 index 00000000000..670ca04ae1e --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// tuple& operator=(tuple<UTypes...>&& u); + +#include <tuple> +#include <string> +#include <memory> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i= 0) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + D d2(2); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d2); + T1 t1(1.5, 'b', d); + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple<double, char, std::unique_ptr<D>> T0; + typedef std::tuple<int, int, std::unique_ptr<B>> T1; + T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3))); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.fail.cpp new file mode 100644 index 00000000000..525dfe6e309 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple& operator=(const tuple& u); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +int main() +{ + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(2)); + T t; + t = t0; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp new file mode 100644 index 00000000000..f19043ca338 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple& operator=(const tuple& u); + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t; + t = t0; + } + { + typedef std::tuple<int> T; + T t0(2); + T t; + t = t0; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<int, char> T; + T t0(2, 'a'); + T t; + t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + } + { + typedef std::tuple<int, char, std::string> T; + const T t0(2, 'a', "some text"); + T t; + t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + assert(std::get<2>(t) == "some text"); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp new file mode 100644 index 00000000000..302c1f9247f --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple& operator=(tuple&& u); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t; + t = std::move(t0); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t; + t = std::move(t0); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t; + t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t; + t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp new file mode 100644 index 00000000000..fe0163ce505 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> +// tuple& operator=(pair<U1, U2>&& u); + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i = 0) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair<double, std::unique_ptr<D>> T0; + typedef std::tuple<int, std::unique_ptr<B>> T1; + T0 t0(2.5, std::unique_ptr<D>(new D(3))); + T1 t1; + t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.pass.cpp new file mode 100644 index 00000000000..f62d2fed483 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/tuple_array_template_depth.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Tuple, __tuple_assignable<Tuple, tuple> > +// tuple & operator=(Tuple &&); + +// This test checks that we do not evaluate __make_tuple_types +// on the array when it doesn't match the size of the tuple. + +#include <array> +#include <tuple> + +// Use 1256 to try and blow the template instantiation depth for all compilers. +typedef std::array<char, 1256> array_t; +typedef std::tuple<array_t> tuple_t; + +int main() +{ + array_t arr; + tuple_t tup; + tup = arr; +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp new file mode 100644 index 00000000000..c2c00f2e13b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +/* + This is testing an extension whereby only Types having an explicit conversion + from UTypes are bound by the explicit tuple constructor. +*/ + +#include <tuple> +#include <cassert> + +class MoveOnly +{ + MoveOnly(const MoveOnly&); + MoveOnly& operator=(const MoveOnly&); + + int data_; +public: + explicit MoveOnly(int data = 1) : data_(data) {} + MoveOnly(MoveOnly&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly& operator=(MoveOnly&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + + int get() const {return data_;} + + bool operator==(const MoveOnly& x) const {return data_ == x.data_;} + bool operator< (const MoveOnly& x) const {return data_ < x.data_;} +}; + +int main() +{ + { + std::tuple<MoveOnly> t = 1; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp new file mode 100644 index 00000000000..3d8b194eb32 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +#include <tuple> +#include <cassert> +#include <type_traits> + +#include "../MoveOnly.h" + +#if _LIBCPP_STD_VER > 11 + +struct Empty {}; +struct A +{ + int id_; + explicit constexpr A(int i) : id_(i) {} +}; + +#endif + +struct NoDefault { NoDefault() = delete; }; + +// Make sure the _Up... constructor SFINAEs out when the types that +// are not explicitly initialized are not all default constructible. +// Otherwise, std::is_constructible would return true but instantiating +// the constructor would fail. +void test_default_constructible_extension_sfinae() +{ + { + typedef std::tuple<MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + MoveOnly, MoveOnly, NoDefault + >::value, ""); + } + { + // Same idea as above but with a nested tuple type. + typedef std::tuple<MoveOnly, NoDefault> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(!std::is_constructible< + NestedTuple, + MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } + { + typedef std::tuple<MoveOnly, int> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } +} + +int main() +{ + { + std::tuple<MoveOnly> t(MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple<MoveOnly, MoveOnly> t(MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0), + MoveOnly(1), + MoveOnly(2)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + // extensions + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0), + MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == MoveOnly()); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == MoveOnly()); + assert(std::get<2>(t) == MoveOnly()); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<Empty> t0{Empty()}; + } + { + constexpr std::tuple<A, A> t(3, 2); + static_assert(std::get<0>(t).id_ == 3, ""); + } +#endif + // Check that SFINAE is properly applied with the default reduced arity + // constructor extensions. + test_default_constructible_extension_sfinae(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp new file mode 100644 index 00000000000..606c60996d6 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a); + +#include <tuple> +#include <cassert> + +#include "DefaultOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple<> t(std::allocator_arg, A1<int>()); + } + { + std::tuple<int> t(std::allocator_arg, A1<int>()); + assert(std::get<0>(t) == 0); + } + { + std::tuple<DefaultOnly> t(std::allocator_arg, A1<int>()); + assert(std::get<0>(t) == DefaultOnly()); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first()); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last()); + } + { + alloc_first::allocator_constructed = false; + std::tuple<DefaultOnly, alloc_first> t(std::allocator_arg, A1<int>(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last()); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg, + A2<int>(5)); + assert(std::get<0>(t) == DefaultOnly()); + assert(!alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first()); + assert(!alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last()); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp new file mode 100644 index 00000000000..00bc5e05402 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp @@ -0,0 +1,139 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, UTypes&&...); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct NoDefault { NoDefault() = delete; }; + +// Make sure the _Up... constructor SFINAEs out when the types that +// are not explicitly initialized are not all default constructible. +// Otherwise, std::is_constructible would return true but instantiating +// the constructor would fail. +void test_default_constructible_extension_sfinae() +{ + { + typedef std::tuple<MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + Tuple, + std::allocator_arg_t, A1<int>, MoveOnly, NoDefault + >::value, ""); + } + { + typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple; + + static_assert(!std::is_constructible< + std::tuple<MoveOnly, MoveOnly, NoDefault>, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + std::tuple<MoveOnly, MoveOnly, NoDefault>, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, NoDefault + >::value, ""); + } + { + // Same idea as above but with a nested tuple + typedef std::tuple<MoveOnly, NoDefault> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(!std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } + { + typedef std::tuple<MoveOnly, int> Tuple; + typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly + >::value, ""); + + static_assert(std::is_constructible< + NestedTuple, + std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly + >::value, ""); + } +} + +int main() +{ + { + std::tuple<MoveOnly> t(std::allocator_arg, A1<int>(), MoveOnly(0)); + assert(std::get<0>(t) == 0); + } + { + std::tuple<MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + MoveOnly(0), MoveOnly(1)); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + MoveOnly(0), + 1, 2); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(5), 1, 2, 3); + assert(std::get<0>(t) == 1); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } + // extensions + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + 0, 1); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == MoveOnly()); + } + { + std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), + 0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == MoveOnly()); + assert(std::get<2>(t) == MoveOnly()); + } + // Check that SFINAE is properly applied with the default reduced arity + // constructor extensions. + test_default_constructible_extension_sfinae(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp new file mode 100644 index 00000000000..5f6a586f67a --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, const Types&...); + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + std::tuple<int> t(std::allocator_arg, A1<int>(), 3); + assert(std::get<0>(t) == 3); + } + { + assert(!alloc_first::allocator_constructed); + std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5), alloc_first(3)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == alloc_first(3)); + } + { + assert(!alloc_last::allocator_constructed); + std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5), alloc_last(3)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == alloc_last(3)); + } + { + alloc_first::allocator_constructed = false; + std::tuple<int, alloc_first> t(std::allocator_arg, A1<int>(5), + 10, alloc_first(15)); + assert(std::get<0>(t) == 10); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(15)); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, + A1<int>(5), 1, alloc_first(2), + alloc_last(3)); + assert(std::get<0>(t) == 1); + assert(alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } + { + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, + A2<int>(5), 1, alloc_first(2), + alloc_last(3)); + assert(std::get<0>(t) == 1); + assert(!alloc_first::allocator_constructed); + assert(std::get<1>(t) == alloc_first(2)); + assert(!alloc_last::allocator_constructed); + assert(std::get<2>(t) == alloc_last(3)); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp new file mode 100644 index 00000000000..0b210e5901f --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class U1, class U2> +// tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); + +#include <tuple> +#include <utility> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::pair<double, int> T0; + typedef std::tuple<int, double> T1; + T0 t0(2, 3); + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair<int, int> T0; + typedef std::tuple<alloc_first, double> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::pair<int, int> T0; + typedef std::tuple<alloc_first, alloc_last> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp new file mode 100644 index 00000000000..fd127caeb80 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&); + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1(std::allocator_arg, A1<int>(), t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<int> T0; + typedef std::tuple<alloc_first> T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<int, int> T0; + typedef std::tuple<alloc_first, alloc_last> T1; + T0 t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == 3); + } + { + typedef std::tuple<double, int, int> T0; + typedef std::tuple<int, alloc_first, alloc_last> T1; + T0 t0(1.5, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 1); + assert(std::get<1>(t1) == 2); + assert(std::get<2>(t1) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp new file mode 100644 index 00000000000..b420588b03b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class... UTypes> +// tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&); + +#include <tuple> +#include <string> +#include <memory> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<int> T0; + typedef std::tuple<alloc_first> T1; + T0 t0(2); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<std::unique_ptr<D>> T0; + typedef std::tuple<std::unique_ptr<B>> T1; + T0 t0(std::unique_ptr<D>(new D(3))); + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(std::get<0>(t1)->id_ == 3); + } + { + typedef std::tuple<int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_first, std::unique_ptr<B>> T1; + T0 t0(2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } + { + typedef std::tuple<int, int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1; + T0 t0(1, 2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t1) == 1); + assert(std::get<1>(t1) == 2); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp new file mode 100644 index 00000000000..568ed9700db --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, const tuple&); + +#include <tuple> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t(std::allocator_arg, A1<int>(), t0); + } + { + typedef std::tuple<int> T; + T t0(2); + T t(std::allocator_arg, A1<int>(), t0); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_first> T; + T t0(2); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_last> T; + T t0(2); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<alloc_first, alloc_last> T; + T t0(2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 3); + } + { + typedef std::tuple<int, alloc_first, alloc_last> T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), t0); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp new file mode 100644 index 00000000000..575a99404eb --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc> +// tuple(allocator_arg_t, const Alloc& a, tuple&&); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t(std::allocator_arg, A1<int>(), std::move(t0)); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t(std::allocator_arg, A1<int>(), std::move(t0)); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<alloc_first> T; + T t0(1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple<alloc_last> T; + T t0(1); + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + } + { + typedef std::tuple<MoveOnly, alloc_first> T; + T t0(0 ,1); + alloc_first::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple<MoveOnly, alloc_first, alloc_last> T; + T t0(1, 2, 3); + alloc_first::allocator_constructed = false; + alloc_last::allocator_constructed = false; + T t(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(alloc_last::allocator_constructed); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp new file mode 100644 index 00000000000..31c605ea065 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Alloc, class U1, class U2> +// tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +#include "allocators.h" +#include "../alloc_first.h" +#include "../alloc_last.h" + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair<int, std::unique_ptr<D>> T0; + typedef std::tuple<alloc_first, std::unique_ptr<B>> T1; + T0 t0(2, std::unique_ptr<D>(new D(3))); + alloc_first::allocator_constructed = false; + T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); + assert(alloc_first::allocator_constructed); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp new file mode 100644 index 00000000000..e8a78d1983e --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + std::tuple<int*> t = 0; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp new file mode 100644 index 00000000000..ca53cd3c519 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp @@ -0,0 +1,130 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +#include <tuple> +#include <string> +#include <cassert> + + +template <class ...> +struct never { + enum { value = 0 }; +}; + +struct NoValueCtor +{ + NoValueCtor() : id(++count) {} + NoValueCtor(NoValueCtor const & other) : id(other.id) { ++count; } + + // The constexpr is required to make is_constructible instantiate this template. + // The explicit is needed to test-around a similar bug with is_convertible. + template <class T> + constexpr explicit NoValueCtor(T) + { static_assert(never<T>::value, "This should not be instantiated"); } + + static int count; + int id; +}; + +int NoValueCtor::count = 0; + + +struct NoValueCtorEmpty +{ + NoValueCtorEmpty() {} + NoValueCtorEmpty(NoValueCtorEmpty const &) {} + + template <class T> + constexpr explicit NoValueCtorEmpty(T) + { static_assert(never<T>::value, "This should not be instantiated"); } +}; + +int main() +{ + { + std::tuple<int> t(2); + assert(std::get<0>(t) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<int> t(2); + static_assert(std::get<0>(t) == 2, ""); + } + { + constexpr std::tuple<int> t; + static_assert(std::get<0>(t) == 0, ""); + } +#endif + { + std::tuple<int, char*> t(2, 0); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<int, char*> t(2, nullptr); + static_assert(std::get<0>(t) == 2, ""); + static_assert(std::get<1>(t) == nullptr, ""); + } +#endif + { + std::tuple<int, char*> t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple<int, char*, std::string> t(2, nullptr, "text"); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == "text"); + } + // __tuple_leaf<T> uses is_constructible<T, U> to disable its explicit converting + // constructor overload __tuple_leaf(U &&). Evaluating is_constructible can cause a compile error. + // This overload is evaluated when __tuple_leafs copy or move ctor is called. + // This checks that is_constructible is not evaluated when U == __tuple_leaf. + { + std::tuple<int, NoValueCtor, int, int> t(1, NoValueCtor(), 2, 3); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t).id == 1); + assert(std::get<2>(t) == 2); + assert(std::get<3>(t) == 3); + } + { + std::tuple<int, NoValueCtorEmpty, int, int> t(1, NoValueCtorEmpty(), 2, 3); + assert(std::get<0>(t) == 1); + assert(std::get<2>(t) == 2); + assert(std::get<3>(t) == 3); + } + // extensions + { + std::tuple<int, char*, std::string> t(2); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string> t(2, nullptr); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string, double> t(2, nullptr, "text"); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == "text"); + assert(std::get<3>(t) == 0.0); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp new file mode 100644 index 00000000000..4b3359e0a27 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// explicit tuple(const T&...); + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + std::tuple<int, char*, std::string, double&> t(2, nullptr, "text"); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp new file mode 100644 index 00000000000..d40196b07ed --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> tuple(const pair<U1, U2>& u); + +#include <tuple> +#include <utility> +#include <cassert> + +int main() +{ + { + typedef std::pair<double, char> T0; + typedef std::tuple<int, short> T1; + T0 t0(2.5, 'a'); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == short('a')); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<double, char> P0; + typedef std::tuple<int, short> T1; + constexpr P0 p0(2.5, 'a'); + constexpr T1 t1 = p0; + static_assert(std::get<0>(t1) != std::get<0>(p0), ""); + static_assert(std::get<1>(t1) == std::get<1>(p0), ""); + static_assert(std::get<0>(t1) == 2, ""); + static_assert(std::get<1>(t1) == short('a'), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp new file mode 100644 index 00000000000..bcdb9d99b9b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> tuple(const tuple<UTypes...>& u); + +#include <tuple> +#include <string> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +#if _LIBCPP_STD_VER > 11 + +struct A +{ + int id_; + + constexpr A(int i) : id_(i) {} + friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;} +}; + +struct C +{ + int id_; + + constexpr explicit C(int i) : id_(i) {} + friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;} +}; + +#endif + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<double> T0; + typedef std::tuple<A> T1; + constexpr T0 t0(2.5); + constexpr T1 t1 = t0; + static_assert(std::get<0>(t1) == 2, ""); + } + { + typedef std::tuple<int> T0; + typedef std::tuple<C> T1; + constexpr T0 t0(2); + constexpr T1 t1{t0}; + static_assert(std::get<0>(t1) == C(2), ""); + } +#endif + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1 = t0; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d); + T1 t1 = t0; + d.id_ = 2; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple<double, char, int> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', 3); + T1 t1(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp new file mode 100644 index 00000000000..ff19c2eecf6 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> tuple(tuple<UTypes...>&& u); + +#include <tuple> +#include <string> +#include <memory> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::tuple<double> T0; + typedef std::tuple<int> T1; + T0 t0(2.5); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + } + { + typedef std::tuple<double, char> T0; + typedef std::tuple<int, int> T1; + T0 t0(2.5, 'a'); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + } + { + typedef std::tuple<double, char, D> T0; + typedef std::tuple<int, int, B> T1; + T0 t0(2.5, 'a', D(3)); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 3); + } + { + D d(3); + typedef std::tuple<double, char, D&> T0; + typedef std::tuple<int, int, B&> T1; + T0 t0(2.5, 'a', d); + T1 t1 = std::move(t0); + d.id_ = 2; + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1).id_ == 2); + } + { + typedef std::tuple<double, char, std::unique_ptr<D>> T0; + typedef std::tuple<int, int, std::unique_ptr<B>> T1; + T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3))); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1) == int('a')); + assert(std::get<2>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp new file mode 100644 index 00000000000..8b8ec0ca53f --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(const tuple& u) = default; + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +int main() +{ + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(2)); + T t = t0; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp new file mode 100644 index 00000000000..fd953f84340 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(const tuple& u) = default; + +#include <tuple> +#include <string> +#include <cassert> + +struct Empty {}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = t0; + } + { + typedef std::tuple<int> T; + T t0(2); + T t = t0; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<int, char> T; + T t0(2, 'a'); + T t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + } + { + typedef std::tuple<int, char, std::string> T; + const T t0(2, 'a', "some text"); + T t = t0; + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 'a'); + assert(std::get<2>(t) == "some text"); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<int> T; + constexpr T t0(2); + constexpr T t = t0; + static_assert(std::get<0>(t) == 2, ""); + } + { + typedef std::tuple<Empty> T; + constexpr T t0; + constexpr T t = t0; + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp new file mode 100644 index 00000000000..9cde90da3f5 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// constexpr tuple(); + +#include <tuple> +#include <string> +#include <cassert> +#include <type_traits> + +#include "DefaultOnly.h" + +struct NoDefault { + NoDefault() = delete; + explicit NoDefault(int) { } +}; + +struct NoExceptDefault { + NoExceptDefault() noexcept = default; +}; + +struct ThrowingDefault { + ThrowingDefault() { } +}; + +int main() +{ + { + std::tuple<> t; + } + { + std::tuple<int> t; + assert(std::get<0>(t) == 0); + } + { + std::tuple<int, char*> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } + { + std::tuple<int, char*, std::string> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + } + { + std::tuple<int, char*, std::string, DefaultOnly> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + assert(std::get<2>(t) == ""); + assert(std::get<3>(t) == DefaultOnly()); + } + { + // See bug #21157. + static_assert(!std::is_default_constructible<std::tuple<NoDefault>>(), ""); + static_assert(!std::is_default_constructible<std::tuple<DefaultOnly, NoDefault>>(), ""); + static_assert(!std::is_default_constructible<std::tuple<NoDefault, DefaultOnly, NoDefault>>(), ""); + } + { + static_assert(noexcept(std::tuple<NoExceptDefault>()), ""); + static_assert(noexcept(std::tuple<NoExceptDefault, NoExceptDefault>()), ""); + + static_assert(!noexcept(std::tuple<ThrowingDefault, NoExceptDefault>()), ""); + static_assert(!noexcept(std::tuple<NoExceptDefault, ThrowingDefault>()), ""); + static_assert(!noexcept(std::tuple<ThrowingDefault, ThrowingDefault>()), ""); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::tuple<> t; + } + { + constexpr std::tuple<int> t; + assert(std::get<0>(t) == 0); + } + { + constexpr std::tuple<int, char*> t; + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == nullptr); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp new file mode 100644 index 00000000000..8dc7d21ec28 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(tuple&& u); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +struct ConstructsWithTupleLeaf +{ + ConstructsWithTupleLeaf() {} + + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); } + ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} + + template <class T> + ConstructsWithTupleLeaf(T t) + { assert(false); } +}; + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t = std::move(t0); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t = std::move(t0); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 1); + assert(std::get<2>(t) == 2); + } + // A bug in tuple caused __tuple_leaf to use its explicit converting constructor + // as its move constructor. This tests that ConstructsWithTupleLeaf is not called + // (w/ __tuple_leaf) + { + typedef std::tuple<ConstructsWithTupleLeaf> d_t; + d_t d((ConstructsWithTupleLeaf())); + d_t d2(static_cast<d_t &&>(d)); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp new file mode 100644 index 00000000000..05d78459cec --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class U1, class U2> tuple(pair<U1, U2>&& u); + +#include <tuple> +#include <utility> +#include <memory> +#include <cassert> + +struct B +{ + int id_; + + explicit B(int i) : id_(i) {} + + virtual ~B() {} +}; + +struct D + : B +{ + explicit D(int i) : B(i) {} +}; + +int main() +{ + { + typedef std::pair<double, std::unique_ptr<D>> T0; + typedef std::tuple<int, std::unique_ptr<B>> T1; + T0 t0(2.5, std::unique_ptr<D>(new D(3))); + T1 t1 = std::move(t0); + assert(std::get<0>(t1) == 2); + assert(std::get<1>(t1)->id_ == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp new file mode 100644 index 00000000000..65a1c701c51 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/tuple_array_template_depth.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class Tuple, __tuple_convertible<Tuple, tuple> > +// tuple(Tuple &&); +// +// template <class Tuple, __tuple_constructible<Tuple, tuple> > +// tuple(Tuple &&); + +// This test checks that we do not evaluate __make_tuple_types +// on the array. + +#include <array> +#include <tuple> + +// Use 1256 to try and blow the template instantiation depth for all compilers. +typedef std::array<char, 1256> array_t; +typedef std::tuple<array_t> tuple_t; + +int main() +{ + array_t arr; + tuple_t tup(arr); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp new file mode 100644 index 00000000000..5e84ff8e882 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/forward_as_tuple.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template<class... Types> +// tuple<Types&&...> forward_as_tuple(Types&&... t); + +#include <tuple> +#include <cassert> + +template <class Tuple> +void +test0(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 0, ""); +} + +template <class Tuple> +void +test1a(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 1, ""); + static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&&>::value, ""); + assert(std::get<0>(t) == 1); +} + +template <class Tuple> +void +test1b(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 1, ""); + static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&>::value, ""); + assert(std::get<0>(t) == 2); +} + +template <class Tuple> +void +test2a(const Tuple& t) +{ + static_assert(std::tuple_size<Tuple>::value == 2, ""); + static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, double&>::value, ""); + static_assert(std::is_same<typename std::tuple_element<1, Tuple>::type, char&>::value, ""); + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == 'a'); +} + +#if _LIBCPP_STD_VER > 11 +template <class Tuple> +constexpr int +test3(const Tuple& t) +{ + return std::tuple_size<Tuple>::value; +} +#endif + +int main() +{ + { + test0(std::forward_as_tuple()); + } + { + test1a(std::forward_as_tuple(1)); + } + { + int i = 2; + test1b(std::forward_as_tuple(i)); + } + { + double i = 2.5; + char c = 'a'; + test2a(std::forward_as_tuple(i, c)); +#if _LIBCPP_STD_VER > 11 + static_assert ( test3 (std::forward_as_tuple(i, c)) == 2, "" ); +#endif + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp new file mode 100644 index 00000000000..5b33d1a23f8 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... Types> +// tuple<VTypes...> make_tuple(Types&&... t); + +#include <tuple> +#include <functional> +#include <cassert> + +int main() +{ + { + int i = 0; + float j = 0; + std::tuple<int, int&, float&> t = std::make_tuple(1, std::ref(i), + std::ref(j)); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 0); + assert(std::get<2>(t) == 0); + i = 2; + j = 3.5; + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + assert(std::get<2>(t) == 3.5); + std::get<1>(t) = 0; + std::get<2>(t) = 0; + assert(i == 0); + assert(j == 0); + } +#if _LIBCPP_STD_VER > 11 + { + constexpr auto t1 = std::make_tuple(0, 1, 3.14); + constexpr int i1 = std::get<1>(t1); + constexpr double d1 = std::get<2>(t1); + static_assert (i1 == 1, "" ); + static_assert (d1 == 3.14, "" ); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp new file mode 100644 index 00000000000..e6ebf958e6f --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... Types> +// tuple<Types&...> tie(Types&... t); + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + int i = 0; + std::string s; + std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++"); + assert(i == 42); + assert(s == "C++"); + } +#if _LIBCPP_STD_VER > 11 + { + static constexpr int i = 42; + static constexpr double f = 1.1; + constexpr std::tuple<const int &, const double &> t = std::tie(i, f); + static_assert ( std::get<0>(t) == 42, "" ); + static_assert ( std::get<1>(t) == 1.1, "" ); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp new file mode 100644 index 00000000000..3fca5738929 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp @@ -0,0 +1,230 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); + +#include <tuple> +#include <utility> +#include <array> +#include <string> +#include <cassert> + +#include "../MoveOnly.h" + +int main() +{ + { + std::tuple<> t = std::tuple_cat(); + } + { + std::tuple<> t1; + std::tuple<> t2 = std::tuple_cat(t1); + } + { + std::tuple<> t = std::tuple_cat(std::tuple<>()); + } + { + std::tuple<> t = std::tuple_cat(std::array<int, 0>()); + } + { + std::tuple<int> t1(1); + std::tuple<int> t = std::tuple_cat(t1); + assert(std::get<0>(t) == 1); + } + +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<> t = std::tuple_cat(); + } + { + constexpr std::tuple<> t1; + constexpr std::tuple<> t2 = std::tuple_cat(t1); + } + { + constexpr std::tuple<> t = std::tuple_cat(std::tuple<>()); + } + { + constexpr std::tuple<> t = std::tuple_cat(std::array<int, 0>()); + } + { + constexpr std::tuple<int> t1(1); + constexpr std::tuple<int> t = std::tuple_cat(t1); + static_assert(std::get<0>(t) == 1, ""); + } + { + constexpr std::tuple<int> t1(1); + constexpr std::tuple<int, int> t = std::tuple_cat(t1, t1); + static_assert(std::get<0>(t) == 1, ""); + static_assert(std::get<1>(t) == 1, ""); + } +#endif + { + std::tuple<int, MoveOnly> t = + std::tuple_cat(std::tuple<int, MoveOnly>(1, 2)); + assert(std::get<0>(t) == 1); + assert(std::get<1>(t) == 2); + } + { + std::tuple<int, int, int> t = std::tuple_cat(std::array<int, 3>()); + assert(std::get<0>(t) == 0); + assert(std::get<1>(t) == 0); + assert(std::get<2>(t) == 0); + } + { + std::tuple<int, MoveOnly> t = std::tuple_cat(std::pair<int, MoveOnly>(2, 1)); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == 1); + } + + { + std::tuple<> t1; + std::tuple<> t2; + std::tuple<> t3 = std::tuple_cat(t1, t2); + } + { + std::tuple<> t1; + std::tuple<int> t2(2); + std::tuple<int> t3 = std::tuple_cat(t1, t2); + assert(std::get<0>(t3) == 2); + } + { + std::tuple<> t1; + std::tuple<int> t2(2); + std::tuple<int> t3 = std::tuple_cat(t2, t1); + assert(std::get<0>(t3) == 2); + } + { + std::tuple<int*> t1; + std::tuple<int> t2(2); + std::tuple<int*, int> t3 = std::tuple_cat(t1, t2); + assert(std::get<0>(t3) == nullptr); + assert(std::get<1>(t3) == 2); + } + { + std::tuple<int*> t1; + std::tuple<int> t2(2); + std::tuple<int, int*> t3 = std::tuple_cat(t2, t1); + assert(std::get<0>(t3) == 2); + assert(std::get<1>(t3) == nullptr); + } + { + std::tuple<int*> t1; + std::tuple<int, double> t2(2, 3.5); + std::tuple<int*, int, double> t3 = std::tuple_cat(t1, t2); + assert(std::get<0>(t3) == nullptr); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == 3.5); + } + { + std::tuple<int*> t1; + std::tuple<int, double> t2(2, 3.5); + std::tuple<int, double, int*> t3 = std::tuple_cat(t2, t1); + assert(std::get<0>(t3) == 2); + assert(std::get<1>(t3) == 3.5); + assert(std::get<2>(t3) == nullptr); + } + { + std::tuple<int*, MoveOnly> t1(nullptr, 1); + std::tuple<int, double> t2(2, 3.5); + std::tuple<int*, MoveOnly, int, double> t3 = + std::tuple_cat(std::move(t1), t2); + assert(std::get<0>(t3) == nullptr); + assert(std::get<1>(t3) == 1); + assert(std::get<2>(t3) == 2); + assert(std::get<3>(t3) == 3.5); + } + { + std::tuple<int*, MoveOnly> t1(nullptr, 1); + std::tuple<int, double> t2(2, 3.5); + std::tuple<int, double, int*, MoveOnly> t3 = + std::tuple_cat(t2, std::move(t1)); + assert(std::get<0>(t3) == 2); + assert(std::get<1>(t3) == 3.5); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 1); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::move(t1), std::move(t2)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::tuple<>(), + std::move(t1), + std::move(t2)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::move(t1), + std::tuple<>(), + std::move(t2)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 = + std::tuple_cat(std::move(t1), + std::move(t2), + std::tuple<>()); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + } + { + std::tuple<MoveOnly, MoveOnly> t1(1, 2); + std::tuple<int*, MoveOnly> t2(nullptr, 4); + std::tuple<MoveOnly, MoveOnly, int*, MoveOnly, int> t3 = + std::tuple_cat(std::move(t1), + std::move(t2), + std::tuple<int>(5)); + assert(std::get<0>(t3) == 1); + assert(std::get<1>(t3) == 2); + assert(std::get<2>(t3) == nullptr); + assert(std::get<3>(t3) == 4); + assert(std::get<4>(t3) == 5); + } + { + // See bug #19616. + auto t1 = std::tuple_cat( + std::make_tuple(std::make_tuple(1)), + std::make_tuple() + ); + assert(t1 == std::make_tuple(std::make_tuple(1))); + + auto t2 = std::tuple_cat( + std::make_tuple(std::make_tuple(1)), + std::make_tuple(std::make_tuple(2)) + ); + assert(t2 == std::make_tuple(std::make_tuple(1), std::make_tuple(2))); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.fail.cpp new file mode 100644 index 00000000000..d6e8811b537 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.fail.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type const& +// get(const tuple<Types...>& t); + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<double&, std::string, int> T; + double d = 1.5; + const T t(d, "high", 5); + assert(std::get<0>(t) == 1.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + std::get<0>(t) = 2.5; + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + assert(d == 2.5); + + std::get<1>(t) = "four"; + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp new file mode 100644 index 00000000000..0ba898d98d8 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type const& +// get(const tuple<Types...>& t); + +#include <tuple> +#include <string> +#include <cassert> + +struct Empty {}; + +int main() +{ + { + typedef std::tuple<int> T; + const T t(3); + assert(std::get<0>(t) == 3); + } + { + typedef std::tuple<std::string, int> T; + const T t("high", 5); + assert(std::get<0>(t) == "high"); + assert(std::get<1>(t) == 5); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<double, int> T; + constexpr T t(2.718, 5); + static_assert(std::get<0>(t) == 2.718, ""); + static_assert(std::get<1>(t) == 5, ""); + } + { + typedef std::tuple<Empty> T; + constexpr T t{Empty()}; + constexpr Empty e = std::get<0>(t); + } +#endif + { + typedef std::tuple<double&, std::string, int> T; + double d = 1.5; + const T t(d, "high", 5); + assert(std::get<0>(t) == 1.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + std::get<0>(t) = 2.5; + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + assert(d == 2.5); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp new file mode 100644 index 00000000000..3b98b5e3333 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type& +// get(tuple<Types...>& t); + +#include <tuple> +#include <string> +#include <cassert> + +#if __cplusplus > 201103L + +struct Empty {}; + +struct S { + std::tuple<int, Empty> a; + int k; + Empty e; + constexpr S() : a{1,Empty{}}, k(std::get<0>(a)), e(std::get<1>(a)) {} + }; + +constexpr std::tuple<int, int> getP () { return { 3, 4 }; } +#endif + +int main() +{ + { + typedef std::tuple<int> T; + T t(3); + assert(std::get<0>(t) == 3); + std::get<0>(t) = 2; + assert(std::get<0>(t) == 2); + } + { + typedef std::tuple<std::string, int> T; + T t("high", 5); + assert(std::get<0>(t) == "high"); + assert(std::get<1>(t) == 5); + std::get<0>(t) = "four"; + std::get<1>(t) = 4; + assert(std::get<0>(t) == "four"); + assert(std::get<1>(t) == 4); + } + { + typedef std::tuple<double&, std::string, int> T; + double d = 1.5; + T t(d, "high", 5); + assert(std::get<0>(t) == 1.5); + assert(std::get<1>(t) == "high"); + assert(std::get<2>(t) == 5); + std::get<0>(t) = 2.5; + std::get<1>(t) = "four"; + std::get<2>(t) = 4; + assert(std::get<0>(t) == 2.5); + assert(std::get<1>(t) == "four"); + assert(std::get<2>(t) == 4); + assert(d == 2.5); + } +#if _LIBCPP_STD_VER > 11 + { // get on an rvalue tuple + static_assert ( std::get<0> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 0, "" ); + static_assert ( std::get<1> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 1, "" ); + static_assert ( std::get<2> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 2, "" ); + static_assert ( std::get<3> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 3, "" ); + static_assert(S().k == 1, ""); + static_assert(std::get<1>(getP()) == 4, ""); + } +#endif + +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_rv.pass.cpp new file mode 100644 index 00000000000..5a97710c2e3 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_rv.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// typename tuple_element<I, tuple<Types...> >::type&& +// get(tuple<Types...>&& t); + +#include <tuple> +#include <memory> +#include <cassert> + +int main() +{ + { + typedef std::tuple<std::unique_ptr<int> > T; + T t(std::unique_ptr<int>(new int(3))); + std::unique_ptr<int> p = std::get<0>(std::move(t)); + assert(*p == 3); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp new file mode 100644 index 00000000000..5cc33e16c0c --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.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. +// +//===----------------------------------------------------------------------===// + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + { + auto t1 = std::tuple<int, std::string, cf> { 42, "Hi", { 1,2 }}; + assert ( std::get<int>(t1) == 42 ); // find at the beginning + assert ( std::get<std::string>(t1) == "Hi" ); // find in the middle + assert ( std::get<cf>(t1).real() == 1 ); // find at the end + assert ( std::get<cf>(t1).imag() == 2 ); + } + + { + auto t2 = std::tuple<int, std::string, int, cf> { 42, "Hi", 23, { 1,2 }}; +// get<int> would fail! + assert ( std::get<std::string>(t2) == "Hi" ); + assert (( std::get<cf>(t2) == cf{ 1,2 } )); + } + + { + constexpr std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 }; + static_assert ( std::get<int>(p5) == 1, "" ); + static_assert ( std::get<const int>(p5) == 2, "" ); + } + + { + const std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 }; + const int &i1 = std::get<int>(p5); + const int &i2 = std::get<const int>(p5); + assert ( i1 == 1 ); + assert ( i2 == 2 ); + } + + { + typedef std::unique_ptr<int> upint; + std::tuple<upint> t(upint(new int(4))); + upint p = std::get<upint>(std::move(t)); // get rvalue + assert(*p == 4); + assert(std::get<0>(t) == nullptr); // has been moved from + } + +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp new file mode 100644 index 00000000000..d9554560e75 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type1.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_tuple<int, std::string> ( 42, "Hi" ); + assert (( std::get<cf>(t1) == cf {1,2} )); // no such type +#else +#error +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp new file mode 100644 index 00000000000..fde7c69f761 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type2.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_tuple<int, int, std::string, cf> ( 42, 21, "Hi", { 1,2 } ); + assert ( std::get<int>(t1) == 42 ); // two ints here +#else +#error +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp new file mode 100644 index 00000000000..f1881717baa --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type3.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <tuple> +#include <string> +#include <complex> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::complex<float> cf; + auto t1 = std::make_tuple<double, int, std::string, cf, int> ( 42, 21, "Hi", { 1,2 } ); + assert ( std::get<int>(t1) == 42 ); // two ints here (one at the end) +#else +#error +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp new file mode 100644 index 00000000000..b6d5773be38 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type4.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <tuple> +#include <string> +#include <memory> + +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + typedef std::unique_ptr<int> upint; + std::tuple<upint> t(upint(new int(4))); + upint p = std::get<upint>(t); +#else +#error +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp new file mode 100644 index 00000000000..d8a72c617cb --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.array.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// class tuple_element<I, tuple<Types...> > +// { +// public: +// typedef Ti type; +// }; +// +// LWG #2212 says that tuple_size and tuple_element must be +// available after including <utility> + +#include <array> +#include <type_traits> + +template <class T, std::size_t N, class U, size_t idx> +void test() +{ + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<volatile T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const volatile T> >::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), ""); +} + +int main() +{ + test<std::array<int, 5>, 5, int, 0>(); + test<std::array<int, 5>, 5, int, 1>(); + test<std::array<const char *, 4>, 4, const char *, 3>(); + test<std::array<volatile int, 4>, 4, volatile int, 3>(); + test<std::array<char *, 3>, 3, char *, 1>(); + test<std::array<char *, 3>, 3, char *, 2>(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.utility.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.utility.pass.cpp new file mode 100644 index 00000000000..8c8357d95d9 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple.include.utility.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types> +// class tuple_size<tuple<Types...>> +// : public integral_constant<size_t, sizeof...(Types)> { }; +// +// LWG #2212 says that tuple_size and tuple_element must be +// available after including <utility> + +#include <utility> +#include <type_traits> + +template <class T, std::size_t N, class U, size_t idx> +void test() +{ + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<volatile T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const volatile T> >::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), ""); +} + +int main() +{ + test<std::pair<int, int>, 2, int, 0>(); + test<std::pair<int, int>, 2, int, 1>(); + test<std::pair<const int, int>, 2, int, 1>(); + test<std::pair<int, volatile int>, 2, volatile int, 1>(); + test<std::pair<char *, int>, 2, char *, 0>(); + test<std::pair<char *, int>, 2, int, 1>(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp new file mode 100644 index 00000000000..f3f8f2b109d --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <size_t I, class... Types> +// class tuple_element<I, tuple<Types...> > +// { +// public: +// typedef Ti type; +// }; + +#include <tuple> +#include <type_traits> + +template <class T, std::size_t N, class U> +void test() +{ + static_assert((std::is_same<typename std::tuple_element<N, T>::type, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<N, const T>::type, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<N, volatile T>::type, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element<N, const volatile T>::type, const volatile U>::value), ""); +#if _LIBCPP_STD_VER > 11 + static_assert((std::is_same<typename std::tuple_element_t<N, T>, U>::value), ""); + static_assert((std::is_same<typename std::tuple_element_t<N, const T>, const U>::value), ""); + static_assert((std::is_same<typename std::tuple_element_t<N, volatile T>, volatile U>::value), ""); + static_assert((std::is_same<typename std::tuple_element_t<N, const volatile T>, const volatile U>::value), ""); +#endif +} + +int main() +{ + test<std::tuple<int>, 0, int>(); + test<std::tuple<char, int>, 0, char>(); + test<std::tuple<char, int>, 1, int>(); + test<std::tuple<int*, char, int>, 0, int*>(); + test<std::tuple<int*, char, int>, 1, char>(); + test<std::tuple<int*, char, int>, 2, int>(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.pass.cpp new file mode 100644 index 00000000000..6db5823dab1 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types> +// class tuple_size<tuple<Types...>> +// : public integral_constant<size_t, sizeof...(Types)> { }; + +#include <tuple> +#include <type_traits> + +template <class T, std::size_t N> +void test() +{ + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<volatile T> >::value), ""); + static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, + std::tuple_size<const volatile T> >::value), ""); +} + +int main() +{ + test<std::tuple<>, 0>(); + test<std::tuple<int>, 1>(); + test<std::tuple<char, int>, 2>(); + test<std::tuple<char, char*, int>, 3>(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp new file mode 100644 index 00000000000..e05cd6125e7 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... TTypes, class... UTypes> +// bool +// operator==(const tuple<TTypes...>& t, const tuple<UTypes...>& u); + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<> T1; + typedef std::tuple<> T2; + const T1 t1; + const T2 t2; + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<int> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1.1); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<int> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1); + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, char(2)); + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, char(3)); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1.1, char(2)); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<int, double> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1.1, char(3)); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 3); + assert(t1 == t2); + assert(!(t1 != t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 2, 3); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 3, 3); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 4); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 3, 2); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 2, 2); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 3, 3); + assert(!(t1 == t2)); + assert(t1 != t2); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 3, 2); + assert(!(t1 == t2)); + assert(t1 != t2); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + constexpr T1 t1(1, 2, 3); + constexpr T2 t2(1.1, 3, 2); + static_assert(!(t1 == t2), ""); + static_assert(t1 != t2, ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp new file mode 100644 index 00000000000..f09a1050346 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp @@ -0,0 +1,208 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template<class... TTypes, class... UTypes> +// bool +// operator<(const tuple<TTypes...>& t, const tuple<UTypes...>& u); +// +// template<class... TTypes, class... UTypes> +// bool +// operator>(const tuple<TTypes...>& t, const tuple<UTypes...>& u); +// +// template<class... TTypes, class... UTypes> +// bool +// operator<=(const tuple<TTypes...>& t, const tuple<UTypes...>& u); +// +// template<class... TTypes, class... UTypes> +// bool +// operator>=(const tuple<TTypes...>& t, const tuple<UTypes...>& u); + +#include <tuple> +#include <string> +#include <cassert> + +int main() +{ + { + typedef std::tuple<> T1; + typedef std::tuple<> T2; + const T1 t1; + const T2 t2; + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1); + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(0.9); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char> T1; + typedef std::tuple<double> T2; + const T1 t1(1); + const T2 t2(1.1); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, 2); + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(0.9, 2); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1.1, 2); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, 1); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int> T1; + typedef std::tuple<double, char> T2; + const T1 t1(1, 2); + const T2 t2(1, 3); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 3); + assert(!(t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(0.9, 2, 3); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1.1, 2, 3); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 1, 3); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 3, 3); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 2); + assert(!(t1 < t2)); + assert(!(t1 <= t2)); + assert( (t1 > t2)); + assert( (t1 >= t2)); + } + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + const T1 t1(1, 2, 3); + const T2 t2(1, 2, 4); + assert( (t1 < t2)); + assert( (t1 <= t2)); + assert(!(t1 > t2)); + assert(!(t1 >= t2)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple<char, int, double> T1; + typedef std::tuple<double, char, int> T2; + constexpr T1 t1(1, 2, 3); + constexpr T2 t2(1, 2, 4); + static_assert( (t1 < t2), ""); + static_assert( (t1 <= t2), ""); + static_assert(!(t1 > t2), ""); + static_assert(!(t1 >= t2), ""); + } +#endif +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.special/non_member_swap.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..415e9641c34 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.special/non_member_swap.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types> +// void swap(tuple<Types...>& x, tuple<Types...>& y); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t1; + swap(t0, t1); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t1(MoveOnly(1)); + swap(t0, t1); + assert(std::get<0>(t0) == 1); + assert(std::get<0>(t1) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t1(MoveOnly(2), MoveOnly(3)); + swap(t0, t1); + assert(std::get<0>(t0) == 2); + assert(std::get<1>(t0) == 3); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5)); + swap(t0, t1); + assert(std::get<0>(t0) == 3); + assert(std::get<1>(t0) == 4); + assert(std::get<2>(t0) == 5); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + assert(std::get<2>(t1) == 2); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.swap/member_swap.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.swap/member_swap.pass.cpp new file mode 100644 index 00000000000..c7c96f8bc84 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.swap/member_swap.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// void swap(tuple& rhs); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +int main() +{ + { + typedef std::tuple<> T; + T t0; + T t1; + t0.swap(t1); + } + { + typedef std::tuple<MoveOnly> T; + T t0(MoveOnly(0)); + T t1(MoveOnly(1)); + t0.swap(t1); + assert(std::get<0>(t0) == 1); + assert(std::get<0>(t1) == 0); + } + { + typedef std::tuple<MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1)); + T t1(MoveOnly(2), MoveOnly(3)); + t0.swap(t1); + assert(std::get<0>(t0) == 2); + assert(std::get<1>(t0) == 3); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + } + { + typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; + T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); + T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5)); + t0.swap(t1); + assert(std::get<0>(t0) == 3); + assert(std::get<1>(t0) == 4); + assert(std::get<2>(t0) == 5); + assert(std::get<0>(t1) == 0); + assert(std::get<1>(t1) == 1); + assert(std::get<2>(t1) == 2); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.traits/uses_allocator.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.traits/uses_allocator.pass.cpp new file mode 100644 index 00000000000..c81835c5560 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.traits/uses_allocator.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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... Types, class Alloc> +// struct uses_allocator<tuple<Types...>, Alloc> : true_type { }; + +#include <tuple> +#include <type_traits> + +struct A {}; + +int main() +{ + { + typedef std::tuple<> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } + { + typedef std::tuple<int> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } + { + typedef std::tuple<char, int> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } + { + typedef std::tuple<double&, char, int> T; + static_assert((std::is_base_of<std::true_type, + std::uses_allocator<T, A>>::value), ""); + } +} |