diff options
Diffstat (limited to 'libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr')
22 files changed, 1233 insertions, 0 deletions
diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp new file mode 100644 index 00000000000..65c2fa63ea3 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +int main() +{ + { + std::tuple<MoveOnly> t = MoveOnly(0); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp new file mode 100644 index 00000000000..43416afbf05 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// template <class... UTypes> +// explicit tuple(UTypes&&... u); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +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()); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp new file mode 100644 index 00000000000..e9ad4524b7d --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp new file mode 100644 index 00000000000..c3e09b9b5a4 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" + +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()); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp new file mode 100644 index 00000000000..d32e62d805e --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_Types.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp new file mode 100644 index 00000000000..00ee35add78 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp new file mode 100644 index 00000000000..4b5310a735f --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp new file mode 100644 index 00000000000..2c3c5dcc1d2 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp new file mode 100644 index 00000000000..2bb2bc05fa1 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_copy.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp new file mode 100644 index 00000000000..938230bd3c2 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp new file mode 100644 index 00000000000..d04c946c8cf --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_move_pair.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp new file mode 100644 index 00000000000..93f28d5e6d7 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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 = 2; + assert(std::get<0>(t) == 2); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp new file mode 100644 index 00000000000..b2a945db21f --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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(2); + assert(std::get<0>(t) == 2); + } + { + std::tuple<int, char*> t(2, 0); + assert(std::get<0>(t) == 2); + assert(std::get<1>(t) == nullptr); + } + { + 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"); + } + // 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/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp new file mode 100644 index 00000000000..864896e0b21 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types2.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp new file mode 100644 index 00000000000..91b14f5c7be --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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')); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp new file mode 100644 index 00000000000..4672b9eb24b --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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) {} +}; + +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); + } + { + 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); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp new file mode 100644 index 00000000000..4ab026d8faa --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp new file mode 100644 index 00000000000..6aff2270d2b --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp new file mode 100644 index 00000000000..1c637f354d6 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(const tuple& u) = default; + +#include <tuple> +#include <string> +#include <cassert> + +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; + 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"); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp new file mode 100644 index 00000000000..0321fc13a7b --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// constexpr tuple(); + +#include <tuple> +#include <string> +#include <cassert> + +#include "../DefaultOnly.h" + +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()); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp new file mode 100644 index 00000000000..dd4867b18f3 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// tuple(tuple&& u); + +#include <tuple> +#include <cassert> + +#include "../MoveOnly.h" + +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); + } +} diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp new file mode 100644 index 00000000000..c6f8e710965 --- /dev/null +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); + } +} |