Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
| 12 | // explicit basic_string(const Allocator& a = Allocator()); |
| 13 | |
| 14 | #include <string> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | c3deeb5 | 2013-12-03 00:18:10 +0000 | [diff] [blame^] | 17 | #include "test_allocator.h" |
Marshall Clow | e34f6f6 | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 18 | #include "min_allocator.h" |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | |
| 20 | template <class S> |
| 21 | void |
| 22 | test() |
| 23 | { |
| 24 | { |
| 25 | S s; |
| 26 | assert(s.__invariants()); |
| 27 | assert(s.data()); |
| 28 | assert(s.size() == 0); |
| 29 | assert(s.capacity() >= s.size()); |
| 30 | assert(s.get_allocator() == typename S::allocator_type()); |
| 31 | } |
| 32 | { |
| 33 | S s(typename S::allocator_type(5)); |
| 34 | assert(s.__invariants()); |
| 35 | assert(s.data()); |
| 36 | assert(s.size() == 0); |
| 37 | assert(s.capacity() >= s.size()); |
| 38 | assert(s.get_allocator() == typename S::allocator_type(5)); |
| 39 | } |
| 40 | } |
| 41 | |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 42 | #if __cplusplus >= 201103L |
| 43 | |
| 44 | template <class S> |
| 45 | void |
| 46 | test2() |
| 47 | { |
| 48 | { |
| 49 | S s; |
| 50 | assert(s.__invariants()); |
| 51 | assert(s.data()); |
| 52 | assert(s.size() == 0); |
| 53 | assert(s.capacity() >= s.size()); |
| 54 | assert(s.get_allocator() == typename S::allocator_type()); |
| 55 | } |
| 56 | { |
| 57 | S s(typename S::allocator_type{}); |
| 58 | assert(s.__invariants()); |
| 59 | assert(s.data()); |
| 60 | assert(s.size() == 0); |
| 61 | assert(s.capacity() >= s.size()); |
| 62 | assert(s.get_allocator() == typename S::allocator_type()); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #endif |
| 67 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | int main() |
| 69 | { |
| 70 | test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >(); |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 71 | #if __cplusplus >= 201103L |
| 72 | test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); |
| 73 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 74 | } |