size.pass.cpp revision 73d21a4f0774d3fadab98e690619a359cfb160a3
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <deque>
11
12// explicit deque(size_type n);
13
14#include <deque>
15#include <cassert>
16
17#include "../../../stack_allocator.h"
18#include "../../../DefaultOnly.h"
19
20template <class T, class Allocator>
21void
22test(unsigned n)
23{
24    typedef std::deque<T, Allocator> C;
25    typedef typename C::const_iterator const_iterator;
26    assert(DefaultOnly::count == 0);
27    {
28    C d(n);
29    assert(DefaultOnly::count == n);
30    assert(d.size() == n);
31    assert(distance(d.begin(), d.end()) == d.size());
32#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
33    for (const_iterator i = d.begin(), e = d.end(); i != e; ++i)
34        assert(*i == T());
35#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
36    }
37    assert(DefaultOnly::count == 0);
38}
39
40int main()
41{
42    test<DefaultOnly, std::allocator<DefaultOnly> >(0);
43    test<DefaultOnly, std::allocator<DefaultOnly> >(1);
44    test<DefaultOnly, std::allocator<DefaultOnly> >(10);
45    test<DefaultOnly, std::allocator<DefaultOnly> >(1023);
46    test<DefaultOnly, std::allocator<DefaultOnly> >(1024);
47    test<DefaultOnly, std::allocator<DefaultOnly> >(1025);
48    test<DefaultOnly, std::allocator<DefaultOnly> >(2047);
49    test<DefaultOnly, std::allocator<DefaultOnly> >(2048);
50    test<DefaultOnly, std::allocator<DefaultOnly> >(2049);
51    test<DefaultOnly, std::allocator<DefaultOnly> >(4095);
52    test<DefaultOnly, std::allocator<DefaultOnly> >(4096);
53    test<DefaultOnly, std::allocator<DefaultOnly> >(4097);
54    test<DefaultOnly, stack_allocator<DefaultOnly, 4096> >(4095);
55}
56