xref: /llvm-project/libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp (revision 10ec9276d40024c23a481e6671dad1521151dd85)
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 //===----------------------------------------------------------------------===//
8 
9 // <deque>
10 
11 // deque(size_type n, const value_type& v, const allocator_type& a);
12 
13 #include "asan_testing.h"
14 #include <deque>
15 #include <cassert>
16 #include <cstddef>
17 
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 
21 template <class T, class Allocator>
22 void
test(unsigned n,const T & x,const Allocator & a)23 test(unsigned n, const T& x, const Allocator& a)
24 {
25     typedef std::deque<T, Allocator> C;
26     typedef typename C::const_iterator const_iterator;
27     C d(n, x, a);
28     assert(d.get_allocator() == a);
29     assert(d.size() == n);
30     assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size());
31     LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d));
32     for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
33         assert(*i == x);
34 }
35 
main(int,char **)36 int main(int, char**)
37 {
38     {
39     std::allocator<int> a;
40     test(0, 5, a);
41     test(1, 10, a);
42     test(10, 11, a);
43     test(1023, -11, a);
44     test(1024, 25, a);
45     test(1025, 0, a);
46     test(2047, 110, a);
47     test(2048, -500, a);
48     test(2049, 654, a);
49     test(4095, 78, a);
50     test(4096, 1165, a);
51     test(4097, 157, a);
52     }
53 #if TEST_STD_VER >= 11
54     {
55     min_allocator<int> a;
56     test(0, 5, a);
57     test(1, 10, a);
58     test(10, 11, a);
59     test(1023, -11, a);
60     test(1024, 25, a);
61     test(1025, 0, a);
62     test(2047, 110, a);
63     test(2048, -500, a);
64     test(2049, 654, a);
65     test(4095, 78, a);
66     test(4096, 1165, a);
67     test(4097, 157, a);
68     }
69 #endif
70 
71   return 0;
72 }
73