1 // { dg-do compile { target i?86-*-* x86_64-*-* } } 2 // { dg-options "-O3 -mxop" } 3 4 typedef long unsigned int size_t; 5 typedef unsigned long ulong_t; 6 typedef signed long slong_t; 7 8 template<typename _Iterator> 9 struct iterator_traits 10 { 11 typedef typename _Iterator::reference reference; 12 }; 13 14 template<typename _Tp> 15 struct iterator_traits<_Tp*> 16 { 17 typedef _Tp& reference; 18 }; 19 20 template<typename _Iterator, typename _Container> 21 class __normal_iterator 22 { 23 protected: 24 _Iterator _M_current; 25 typedef iterator_traits<_Iterator> __traits_type; 26 27 public: 28 typedef typename __traits_type::reference reference; 29 30 explicit 31 __normal_iterator(const _Iterator& __i) : _M_current(__i) { } 32 33 reference 34 operator*() const 35 { return *_M_current; } 36 37 __normal_iterator& 38 operator++() 39 { 40 ++_M_current; 41 return *this; 42 } 43 44 const _Iterator& 45 base() const 46 { return _M_current; } 47 }; 48 49 template<typename _Iterator, typename _Container> 50 inline bool 51 operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, 52 const __normal_iterator<_Iterator, _Container>& __rhs) 53 { return __lhs.base() != __rhs.base(); } 54 55 template<typename _Tp> 56 class allocator 57 { 58 public: 59 typedef _Tp* pointer; 60 typedef _Tp value_type; 61 62 template<typename _Tp1> 63 struct rebind 64 { typedef allocator<_Tp1> other; }; 65 66 pointer allocate(size_t __n, const void* = 0) 67 { 68 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); 69 } 70 }; 71 72 template<typename _Tp, typename _Alloc> 73 struct _Vector_base 74 { 75 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; 76 77 struct _Vector_impl 78 : public _Tp_alloc_type 79 { 80 typename _Tp_alloc_type::pointer _M_start; 81 typename _Tp_alloc_type::pointer _M_finish; 82 typename _Tp_alloc_type::pointer _M_end_of_storage; 83 84 _Vector_impl(_Tp_alloc_type const& __a) { } 85 }; 86 87 public: 88 typedef _Alloc allocator_type; 89 90 _Vector_base(size_t __n, const allocator_type& __a) 91 : _M_impl(__a) 92 { 93 this->_M_impl._M_start = this->_M_allocate(__n); 94 this->_M_impl._M_finish = this->_M_impl._M_start; 95 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; 96 } 97 98 public: 99 _Vector_impl _M_impl; 100 101 typename _Tp_alloc_type::pointer 102 _M_allocate(size_t __n) 103 { return __n != 0 ? _M_impl.allocate(__n) : 0; } 104 105 }; 106 107 template<typename _Tp, typename _Alloc = allocator<_Tp> > 108 class vector : protected _Vector_base<_Tp, _Alloc> 109 { 110 typedef _Vector_base<_Tp, _Alloc> _Base; 111 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; 112 113 public: 114 typedef _Tp value_type; 115 typedef typename _Tp_alloc_type::pointer pointer; 116 typedef __normal_iterator<pointer, vector> iterator; 117 typedef _Alloc allocator_type; 118 119 protected: 120 using _Base::_M_allocate; 121 using _Base::_M_impl; 122 123 public: 124 125 explicit 126 vector(size_t __n, const value_type& __value = value_type(), 127 const allocator_type& __a = allocator_type()) 128 : _Base(__n, __a) 129 { _M_fill_initialize(__n, __value); } 130 131 iterator begin() 132 { return iterator(this->_M_impl._M_start); } 133 134 iterator end() 135 { return iterator(this->_M_impl._M_finish); } 136 137 protected: 138 void 139 _M_fill_initialize(size_t __n, const value_type& __value) 140 { 141 this->_M_impl._M_finish = this->_M_impl._M_end_of_storage; 142 } 143 }; 144 145 template<typename _InputIterator, typename _OutputIterator, typename _Tp> 146 _OutputIterator 147 replace_copy(_InputIterator __first, _InputIterator __last, 148 _OutputIterator __result, 149 const _Tp& __old_value, const _Tp& __new_value) 150 { 151 ; 152 for (; __first != __last; ++__first, ++__result) 153 if (*__first == __old_value) 154 *__result = __new_value; 155 else 156 *__result = *__first; 157 return __result; 158 } 159 160 extern size_t shape_rank; 161 162 void createDataspaceIdentifier() 163 { 164 vector< ulong_t > dataspaceDims( shape_rank ); 165 vector< ulong_t > maxDataspaceDims( shape_rank ); 166 167 replace_copy( 168 dataspaceDims.begin(), dataspaceDims.end(), 169 maxDataspaceDims.begin(), ulong_t( 0 ), ((ulong_t)(slong_t)(-1)) ); 170 } 171