blob: b266b3bbb927ef35b3959ea36c12b6de33adec63 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <vector>
11
12// Test nested types and default template args:
13
Howard Hinnant6046ace2010-08-22 00:15:28 +000014// template <class Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000015// class vector<bool, Allocator
Howard Hinnant6046ace2010-08-22 00:15:28 +000016// {
17// public:
18// typedef T value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019// typedef Allocator allocator_type;
20// typedef implementation-defined iterator;
21// typedef implementation-defined const_iterator;
22// typedef typename allocator_type::size_type size_type;
23// typedef typename allocator_type::difference_type difference_type;
24// typedef typename allocator_type::pointer pointer;
25// typedef typename allocator_type::const_pointer const_pointer;
26// typedef std::reverse_iterator<iterator> reverse_iterator;
27// typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
28// };
29
30#include <vector>
31#include <iterator>
32#include <type_traits>
33
Marshall Clow1b921882013-12-03 00:18:10 +000034#include "test_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000035#include "../../Copyable.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000036#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037
38template <class Allocator>
39void
40test()
41{
42 typedef std::vector<bool, Allocator> C;
43
44 static_assert((std::is_same<typename C::value_type, bool>::value), "");
45 static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), "");
46 static_assert((std::is_same<typename C::allocator_type, Allocator>::value), "");
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000047 static_assert((std::is_same<typename C::size_type, typename std::allocator_traits<Allocator>::size_type>::value), "");
48 static_assert((std::is_same<typename C::difference_type, typename std::allocator_traits<Allocator>::difference_type>::value), "");
Dan Albert1d4a1ed2016-05-25 22:36:09 -070049 static_assert((std::is_same<
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050 typename std::iterator_traits<typename C::iterator>::iterator_category,
51 std::random_access_iterator_tag>::value), "");
52 static_assert((std::is_same<
53 typename std::iterator_traits<typename C::const_iterator>::iterator_category,
54 std::random_access_iterator_tag>::value), "");
55 static_assert((std::is_same<
56 typename C::reverse_iterator,
57 std::reverse_iterator<typename C::iterator> >::value), "");
58 static_assert((std::is_same<
59 typename C::const_reverse_iterator,
60 std::reverse_iterator<typename C::const_iterator> >::value), "");
61}
62
63int main()
64{
65 test<test_allocator<bool> >();
66 test<std::allocator<bool> >();
67 static_assert((std::is_same<std::vector<bool>::allocator_type,
68 std::allocator<bool> >::value), "");
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000069#if __cplusplus >= 201103L
70 test<min_allocator<bool> >();
71#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072}