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 | |
| 12 | // Test nested types and default template args: |
| 13 | |
Howard Hinnant | 6046ace | 2010-08-22 00:15:28 +0000 | [diff] [blame] | 14 | // template <class T, class Allocator = allocator<T> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | // class vector |
Howard Hinnant | 6046ace | 2010-08-22 00:15:28 +0000 | [diff] [blame] | 16 | // { |
| 17 | // public: |
| 18 | // typedef T value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | // typedef Allocator allocator_type; |
| 20 | // typedef typename allocator_type::reference reference; |
| 21 | // typedef typename allocator_type::const_reference const_reference; |
| 22 | // typedef implementation-defined iterator; |
| 23 | // typedef implementation-defined const_iterator; |
| 24 | // typedef typename allocator_type::size_type size_type; |
| 25 | // typedef typename allocator_type::difference_type difference_type; |
| 26 | // typedef typename allocator_type::pointer pointer; |
| 27 | // typedef typename allocator_type::const_pointer const_pointer; |
| 28 | // typedef std::reverse_iterator<iterator> reverse_iterator; |
| 29 | // typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 30 | // }; |
| 31 | |
| 32 | #include <vector> |
| 33 | #include <iterator> |
| 34 | #include <type_traits> |
| 35 | |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 36 | #include "test_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | #include "../../Copyable.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 38 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | |
Marshall Clow | a1bca66 | 2015-01-26 20:06:52 +0000 | [diff] [blame] | 40 | struct A { std::vector<A> v; }; // incomplete type support |
| 41 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | template <class T, class Allocator> |
| 43 | void |
| 44 | test() |
| 45 | { |
| 46 | typedef std::vector<T, Allocator> C; |
| 47 | |
| 48 | static_assert((std::is_same<typename C::value_type, T>::value), ""); |
| 49 | static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), ""); |
| 50 | static_assert((std::is_same<typename C::allocator_type, Allocator>::value), ""); |
| 51 | static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), ""); |
| 52 | static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), ""); |
| 53 | static_assert((std::is_same<typename C::reference, typename Allocator::reference>::value), ""); |
| 54 | static_assert((std::is_same<typename C::const_reference, typename Allocator::const_reference>::value), ""); |
| 55 | static_assert((std::is_same<typename C::pointer, typename Allocator::pointer>::value), ""); |
| 56 | static_assert((std::is_same<typename C::const_pointer, typename Allocator::const_pointer>::value), ""); |
| 57 | static_assert((std::is_same< |
| 58 | typename std::iterator_traits<typename C::iterator>::iterator_category, |
| 59 | std::random_access_iterator_tag>::value), ""); |
| 60 | static_assert((std::is_same< |
| 61 | typename std::iterator_traits<typename C::const_iterator>::iterator_category, |
| 62 | std::random_access_iterator_tag>::value), ""); |
| 63 | static_assert((std::is_same< |
| 64 | typename C::reverse_iterator, |
| 65 | std::reverse_iterator<typename C::iterator> >::value), ""); |
| 66 | static_assert((std::is_same< |
| 67 | typename C::const_reverse_iterator, |
| 68 | std::reverse_iterator<typename C::const_iterator> >::value), ""); |
| 69 | } |
| 70 | |
| 71 | int main() |
| 72 | { |
| 73 | test<int, test_allocator<int> >(); |
| 74 | test<int*, std::allocator<int*> >(); |
| 75 | test<Copyable, test_allocator<Copyable> >(); |
| 76 | static_assert((std::is_same<std::vector<char>::allocator_type, |
| 77 | std::allocator<char> >::value), ""); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 78 | #if __cplusplus >= 201103L |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 79 | static_assert((std::is_same<std::vector<int, min_allocator<int>>::value_type, int>::value), ""); |
| 80 | static_assert((std::is_same<std::vector<int, min_allocator<int>>::allocator_type, min_allocator<int> >::value), ""); |
| 81 | static_assert((std::is_same<std::vector<int, min_allocator<int>>::reference, int&>::value), ""); |
| 82 | static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_reference, const int&>::value), ""); |
| 83 | static_assert((std::is_same<std::vector<int, min_allocator<int>>::pointer, min_pointer<int>>::value), ""); |
| 84 | static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), ""); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 85 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | } |