Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <vector> |
| 11 | // vector<bool> |
| 12 | |
| 13 | // explicit vector(size_type n); |
| 14 | |
| 15 | #include <vector> |
| 16 | #include <cassert> |
| 17 | |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 18 | #include "min_allocator.h" |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame^] | 19 | #include "test_allocator.h" |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 20 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | template <class C> |
| 22 | void |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 23 | test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) |
| 24 | { |
| 25 | #if _LIBCPP_STD_VER > 11 |
| 26 | C c(n, a); |
| 27 | assert(c.__invariants()); |
| 28 | assert(c.size() == n); |
| 29 | assert(c.get_allocator() == a); |
| 30 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 31 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) |
| 32 | assert(*i == typename C::value_type()); |
| 33 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 34 | #endif |
| 35 | } |
| 36 | |
| 37 | template <class C> |
| 38 | void |
| 39 | test1(typename C::size_type n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | { |
| 41 | C c(n); |
| 42 | assert(c.__invariants()); |
| 43 | assert(c.size() == n); |
| 44 | assert(c.get_allocator() == typename C::allocator_type()); |
| 45 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) |
| 46 | assert(*i == typename C::value_type()); |
| 47 | } |
| 48 | |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 49 | template <class C> |
| 50 | void |
| 51 | test(typename C::size_type n) |
| 52 | { |
| 53 | test1<C> ( n ); |
| 54 | test2<C> ( n ); |
| 55 | } |
| 56 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | int main() |
| 58 | { |
| 59 | test<std::vector<bool> >(50); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 60 | #if __cplusplus >= 201103L |
| 61 | test<std::vector<bool, min_allocator<bool>> >(50); |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 62 | test2<std::vector<bool, test_allocator<bool>> >( 100, test_allocator<bool>(23)); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 63 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | } |