[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / list / list.cons / deduct.pass.cpp
blob766288940b911fff91b1175d7cfbe3e18aa749e5
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <list>
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-no-deduction-guides
14 // template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
15 // list(InputIterator, InputIterator, Allocator = Allocator())
16 // -> list<typename iterator_traits<InputIterator>::value_type, Allocator>;
20 #include <list>
21 #include <iterator>
22 #include <cassert>
23 #include <cstddef>
24 #include <climits> // INT_MAX
26 #include "test_macros.h"
27 #include "test_iterators.h"
28 #include "test_allocator.h"
30 struct A {};
32 int main(int, char**)
35 // Test the explicit deduction guides
37 const int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
38 std::list lst(std::begin(arr), std::end(arr));
40 static_assert(std::is_same_v<decltype(lst), std::list<int>>, "");
41 assert(std::equal(lst.begin(), lst.end(), std::begin(arr), std::end(arr)));
45 const long arr[] = {INT_MAX, 1L, 2L, 3L };
46 std::list lst(std::begin(arr), std::end(arr), std::allocator<long>());
47 static_assert(std::is_same_v<decltype(lst)::value_type, long>, "");
48 assert(lst.size() == 4);
49 auto it = lst.begin();
50 assert(*it++ == INT_MAX);
51 assert(*it++ == 1L);
52 assert(*it++ == 2L);
55 // Test the implicit deduction guides
58 // We don't expect this one to work.
59 // std::list lst(std::allocator<int>()); // list (allocator &)
63 std::list lst(1, A{}); // list (size_type, T)
64 static_assert(std::is_same_v<decltype(lst)::value_type, A>, "");
65 static_assert(std::is_same_v<decltype(lst)::allocator_type, std::allocator<A>>, "");
66 assert(lst.size() == 1);
70 std::list lst(1, A{}, test_allocator<A>()); // list (size_type, T, allocator)
71 static_assert(std::is_same_v<decltype(lst)::value_type, A>, "");
72 static_assert(std::is_same_v<decltype(lst)::allocator_type, test_allocator<A>>, "");
73 assert(lst.size() == 1);
77 std::list lst{1U, 2U, 3U, 4U, 5U}; // list(initializer-list)
78 static_assert(std::is_same_v<decltype(lst)::value_type, unsigned>, "");
79 assert(lst.size() == 5);
80 auto it = lst.begin();
81 std::advance(it, 2);
82 assert(*it == 3U);
86 std::list lst({1.0, 2.0, 3.0, 4.0}, test_allocator<double>()); // list(initializer-list, allocator)
87 static_assert(std::is_same_v<decltype(lst)::value_type, double>, "");
88 static_assert(std::is_same_v<decltype(lst)::allocator_type, test_allocator<double>>, "");
89 assert(lst.size() == 4);
90 auto it = lst.begin();
91 std::advance(it, 3);
92 assert(*it == 4.0);
96 std::list<long double> source;
97 std::list lst(source); // list(list &)
98 static_assert(std::is_same_v<decltype(lst)::value_type, long double>, "");
99 static_assert(std::is_same_v<decltype(lst)::allocator_type, std::allocator<long double>>, "");
100 assert(lst.size() == 0);
103 return 0;