2 // { dg-options "-O3 -floop-nest-optimize -Wno-conversion-null -Wno-return-type" }
4 void __throw_bad_alloc ();
6 template <typename _Tp> void
7 swap (_Tp & __a, _Tp __b)
12 template <typename _Category> struct iterator
14 typedef _Category iterator_category;
17 template <typename _Tp> struct allocator
19 typedef __SIZE_TYPE__ size_type;
21 pointer allocate (size_type)
28 template <class T, class = allocator <T> >class unbounded_array;
29 template <class T, class = unbounded_array <T> >class vector;
30 template <class = int> class scalar_vector;
31 template <class IC> struct random_access_iterator_base : public iterator <IC>
35 template <class X, class> struct promote_traits
37 typedef __typeof__ ((X ())) promote_type;
40 template <class T> struct scalar_traits
42 typedef T const_reference;
46 template <class T> struct type_traits : scalar_traits <T>
50 struct dense_proxy_tag
54 template <class> struct iterator_base_traits;
56 template <> struct iterator_base_traits <dense_proxy_tag>
58 template <class, class> struct iterator_base
60 typedef random_access_iterator_base <dense_proxy_tag> type;
64 template <class I1, class> struct iterator_restrict_traits
66 typedef I1 iterator_category;
69 template <class> class storage_array
73 template <class T, class ALLOC> struct unbounded_array : public storage_array <unbounded_array <ALLOC> >
75 typedef typename ALLOC::size_type size_type;
76 typedef T & reference;
78 unbounded_array (size_type size, ALLOC = ALLOC ()) : alloc_ (), size_ (size)
80 alloc_.allocate (size_);
93 operator[] (size_type i)
98 swap (unbounded_array & a)
100 ::swap (size_, a.size_);
107 template <class T1, class T2> struct scalar_binary_functor
109 typedef typename promote_traits <T1, T2>::promote_type result_type;
112 template <class T1, class T2> struct scalar_plus : public scalar_binary_functor <T1, T2>
116 template <class T1, class T2> struct scalar_multiplies : public scalar_binary_functor <T1, T2>
120 template <class T1, class T2> struct scalar_binary_assign_functor
122 typedef typename type_traits <T1>::reference argument1_type;
123 typedef typename type_traits <T2>::const_reference argument2_type;
126 template <class T1, class T2> struct scalar_assign : public scalar_binary_assign_functor <T1, T2>
128 typedef typename scalar_binary_assign_functor <T1, T2>::argument1_type argument1_type;
129 typedef typename scalar_binary_assign_functor <T1, T2>::argument2_type argument2_type;
130 static const bool computed = false;
132 apply (argument1_type t1, argument2_type t2)
138 template <class E> struct vector_expression
140 typedef E expression_type;
141 const expression_type &
144 return *static_cast <const expression_type *>(this);
148 template <class C> class vector_container : public vector_expression <C>
152 template <class E> struct vector_reference : public vector_expression <vector_reference <E> >
154 typedef typename E::size_type size_type;
155 typename E::const_reference const_reference;
156 typedef E referred_type;
157 vector_reference (referred_type & e) : e_ (e)
163 return expression ().size ();
173 template <class E1, class E2, class F> struct vector_binary : public vector_expression <vector_binary <E1, E2, F> >
175 typedef E1 expression1_type;
176 typedef E2 expression2_type;
177 typedef typename E1::const_closure_type expression1_closure_type;
178 typedef typename E2::const_closure_type expression2_closure_type;
179 typedef typename promote_traits <typename E1::size_type, typename E2::size_type>::promote_type size_type;
180 typedef typename F::result_type value_type;
182 vector_binary (const expression1_type & e1, expression2_type e2) : e1_ (e1), e2_ (e2)
192 class const_iterator : public iterator_base_traits <typename iterator_restrict_traits <typename E1::const_iterator::iterator_category, const_iterator>::iterator_category>::template iterator_base <const_iterator, value_type>::type
195 expression1_closure_type e1_;
196 expression2_closure_type e2_;
199 template <class E1, class E2, class F> struct vector_binary_traits
201 typedef vector_binary <E1, E2, F> expression_type;
202 typedef expression_type result_type;
205 template <class E1, class E2> typename vector_binary_traits <E1, E2, scalar_plus <typename E1::value_type, typename E2::value_type> >::result_type
206 operator + (vector_expression <E1> &e1, const vector_expression <E2> &e2)
208 typedef typename vector_binary_traits <E1, E2, scalar_plus <typename E1::value_type, typename E2::value_type> >::expression_type expression_type;
209 return expression_type (e1 (), e2 ());
212 template <class E1, class E2, class F> struct vector_binary_scalar2 : public vector_expression <vector_binary_scalar2 <E1, E2, F> >
214 typedef vector_binary_scalar2 <E1, E2, F> self_type;
215 typedef typename E1::size_type size_type;
216 typedef typename F::result_type value_type;
217 typedef self_type const_closure_type;
220 template <class E1, class E2, class F> struct vector_binary_scalar2_traits
222 typedef vector_binary_scalar2 <E1, E2, F> result_type;
225 template <class E1, class T2>
226 typename vector_binary_scalar2_traits <E1, T2, scalar_multiplies <typename E1::value_type, T2> >::result_type
227 operator * (vector_expression <E1>, T2)
231 template <class SC> struct vector_assign_traits
233 typedef SC storage_category;
236 template <template <class, class> class F, class V, class E> void
237 indexing_vector_assign (V & v, vector_expression <E>)
239 typedef F <typename V::reference, typename E::value_type> functor_type;
240 typedef typename V::size_type size_type;
241 size_type size (v.size ());
242 for (size_type i; i <size; ++i)
243 functor_type::apply (v (i), (i));
246 template <template <class, class> class F, class V, class E> void
247 vector_assign (V & v, const vector_expression <E> &e, dense_proxy_tag)
249 indexing_vector_assign <F> (v, e);
252 template <template <class, class> class F, class V, class E> void
253 vector_assign (V & v, const vector_expression <E> &e)
255 typedef typename vector_assign_traits <typename V::storage_category>::storage_category storage_category;
256 vector_assign <F> (v, e, storage_category ());
259 template <class T, class A> struct vector : public vector_container <vector <T> >
261 typedef vector <T> self_type;
262 typedef typename A::size_type size_type;
263 typedef T value_type;
264 typedef typename type_traits <T>::const_reference const_reference;
265 typedef T &reference;
266 typedef A array_type;
267 typedef vector_reference <const self_type> const_closure_type;
268 typedef dense_proxy_tag storage_category;
269 vector (size_type size):vector_container <self_type> (), data_ (size)
272 vector (size_type size, value_type):vector_container <self_type> (), data_ (size)
275 template <class AE> vector (const vector_expression <AE> &ae) : vector_container <self_type> (), data_ (ae ().size ())
277 vector_assign <scalar_assign> (*this, ae);
282 return data_.size ();
290 operator () (size_type i)
294 template <class AE> vector operator += (const vector_expression <AE> &ae)
296 self_type temporary (*this + ae);
297 data_.swap (temporary.data ());
300 class const_iterator : public random_access_iterator_base <dense_proxy_tag>
306 template <class T> struct scalar_vector : public vector_container <scalar_vector <> >
308 typedef scalar_vector self_type;
309 typedef __SIZE_TYPE__ size_type;
310 typedef T value_type;
311 typedef T const_reference;
312 typedef vector_reference <self_type> const_closure_type;
316 bar (vector <double>)
323 vector <double> xi (n_samp, 0);
324 for (int n = 0; n <n_samp; ++n)
326 vector <double> cos_w_n (n_samp);
329 vector <double> cos_wd (n_samp);
331 bar (xi + scalar_vector <> ());