1 /* ///////////////////////////////////////////////////////////////////////
7 * Brief: the expression vvector class - delay to calculate value array expression
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_MATH_EXPR_VVECTOR_H
14 #define EXTL_MATH_EXPR_VVECTOR_H
16 #ifndef EXTL_MATH_EXPR_VVECTOR_SUPPORT
17 # error expr_vvector.h is not supported by the current compiler.
20 /*!\file expr_vvector.h
21 * \brief the expression vvector class
24 /* ///////////////////////////////////////////////////////////////////////
27 #include "detail/expr_op.h"
28 #include "detail/vvector_expr.h"
30 #ifdef EXTL_MATH_VVECTOR_TEST_ENABLE
31 # include "../counter/counter.h"
32 # include "basic_vvector.h"
34 /* ///////////////////////////////////////////////////////////////////////
39 /*!\brief expr_vvector
41 * \param T The value type
42 * \param A The val-array type
44 * \ingroup extl_group_math
46 template< typename_param_k T
55 typedef expr_vvector class_type
;
56 typedef typename_type_k
array_type::value_type value_type
;
57 typedef typename_type_k
array_type::pointer pointer
;
58 typedef typename_type_k
array_type::const_pointer const_pointer
;
59 typedef typename_type_k
array_type::reference reference
;
60 typedef typename_type_k
array_type::const_reference const_reference
;
61 typedef typename_type_k
array_type::size_type size_type
;
62 typedef typename_type_k
array_type::bool_type bool_type
;
63 typedef typename_type_k
array_type::difference_type difference_type
;
64 typedef typename_type_k
array_type::int_type int_type
;
65 typedef typename_type_k
array_type::index_type index_type
;
75 /// \name Constructors
78 explicit_k
expr_vvector(array_type
& ar
)
84 expr_vvector(class_type
const& rhs
);
90 template< typename_param_k T2
93 class_type
& operator =(EXTL_NS_DETAIL(vvector_expr
)<T2
, E2
> const& expr
)
95 EXTL_ASSERT(size() == expr
.size());
97 for (size_type i
= 0; i
< n
; ++i
)
105 class_type
& operator =(class_type
const& rhs
)
109 EXTL_ASSERT(size() == rhs
.size());
110 size_type n
= size();
111 for (size_type i
= 0; i
< n
; ++i
)
121 class_type
& operator =(const_reference value
)
131 size_type
size() const { return m_array
.size(); }
137 reference
operator [](index_type index
) { return m_array
[index
]; }
138 const_reference
operator [](index_type index
) const { return m_array
[index
]; }
140 array_type
& array() { return m_array
; }
141 array_type
const& array() const { return m_array
; }
148 template< typename_param_k T
149 , typename_param_k A1
150 , typename_param_k A2
152 EXTL_NS_DETAIL(vvector_expr
) < T
153 , EXTL_NS_DETAIL(eop_add
) <T
, A1
, A2
>
155 operator +(expr_vvector
<T
, A1
> const& ar1
, expr_vvector
<T
, A2
> const& ar2
)
157 return EXTL_NS_DETAIL(vvector_expr
) < T
158 , EXTL_NS_DETAIL(eop_add
) <T
, A1
, A2
>
160 ( EXTL_NS_DETAIL(eop_add
) <T
, A1
, A2
>
168 template< typename_param_k T
169 , typename_param_k A1
170 , typename_param_k E2
172 EXTL_NS_DETAIL(vvector_expr
) < T
173 , EXTL_NS_DETAIL(eop_add
) <T
, A1
, E2
>
175 operator +(expr_vvector
<T
, A1
> const& ar1
, EXTL_NS_DETAIL(vvector_expr
)<T
, E2
> const& expr2
)
177 return EXTL_NS_DETAIL(vvector_expr
) < T
178 , EXTL_NS_DETAIL(eop_add
) <T
, A1
, E2
>
180 ( EXTL_NS_DETAIL(eop_add
) <T
, A1
, E2
>
187 template< typename_param_k T
188 , typename_param_k E1
189 , typename_param_k A2
191 EXTL_NS_DETAIL(vvector_expr
) < T
192 , EXTL_NS_DETAIL(eop_add
) <T
, E1
, A2
>
194 operator +(EXTL_NS_DETAIL(vvector_expr
)<T
, E1
> const& expr1
, expr_vvector
<T
, A2
> const& ar2
)
196 return EXTL_NS_DETAIL(vvector_expr
) < T
197 , EXTL_NS_DETAIL(eop_add
) <T
, E1
, A2
>
199 ( EXTL_NS_DETAIL(eop_add
) <T
, E1
, A2
>
207 template< typename_param_k T
208 , typename_param_k A1
209 , typename_param_k A2
211 EXTL_NS_DETAIL(vvector_expr
) < T
212 , EXTL_NS_DETAIL(eop_sub
) <T
, A1
, A2
>
214 operator -(expr_vvector
<T
, A1
> const& ar1
, expr_vvector
<T
, A2
> const& ar2
)
216 return EXTL_NS_DETAIL(vvector_expr
) < T
217 , EXTL_NS_DETAIL(eop_sub
) <T
, A1
, A2
>
219 ( EXTL_NS_DETAIL(eop_sub
) <T
, A1
, A2
>
227 template< typename_param_k T
228 , typename_param_k A1
229 , typename_param_k E2
231 EXTL_NS_DETAIL(vvector_expr
) < T
232 , EXTL_NS_DETAIL(eop_sub
) <T
, A1
, E2
>
234 operator -(expr_vvector
<T
, A1
> const& ar1
, EXTL_NS_DETAIL(vvector_expr
)<T
, E2
> const& expr2
)
236 return EXTL_NS_DETAIL(vvector_expr
) < T
237 , EXTL_NS_DETAIL(eop_sub
) <T
, A1
, E2
>
239 ( EXTL_NS_DETAIL(eop_sub
) <T
, A1
, E2
>
246 template< typename_param_k T
247 , typename_param_k E1
248 , typename_param_k A2
250 EXTL_NS_DETAIL(vvector_expr
) < T
251 , EXTL_NS_DETAIL(eop_sub
) <T
, E1
, A2
>
253 operator -(EXTL_NS_DETAIL(vvector_expr
)<T
, E1
> const& expr1
, expr_vvector
<T
, A2
> const& ar2
)
255 return EXTL_NS_DETAIL(vvector_expr
) < T
256 , EXTL_NS_DETAIL(eop_sub
) <T
, E1
, A2
>
258 ( EXTL_NS_DETAIL(eop_sub
) <T
, E1
, A2
>
266 #ifdef EXTL_MATH_EOP_SCALAR_SUPPORT
268 template< typename_param_k T
269 , typename_param_k A1
271 EXTL_NS_DETAIL(vvector_expr
) < T
272 , EXTL_NS_DETAIL(eop_add
) < T
274 , EXTL_NS_DETAIL(eop_scalar
)<T
>
277 operator +(expr_vvector
<T
, A1
> const& ar1
, T
const& value
)
279 return EXTL_NS_DETAIL(vvector_expr
) < T
280 , EXTL_NS_DETAIL(eop_add
) < T
282 , EXTL_NS_DETAIL(eop_scalar
)<T
>
285 ( EXTL_NS_DETAIL(eop_add
) < T
287 , EXTL_NS_DETAIL(eop_scalar
)<T
>
290 , EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
295 template< typename_param_k T
296 , typename_param_k A2
298 EXTL_NS_DETAIL(vvector_expr
) < T
299 , EXTL_NS_DETAIL(eop_add
) < T
300 , EXTL_NS_DETAIL(eop_scalar
)<T
>
304 operator +(T
const& value
, expr_vvector
<T
, A2
> const& ar2
)
306 return EXTL_NS_DETAIL(vvector_expr
) < T
307 , EXTL_NS_DETAIL(eop_add
) < T
308 , EXTL_NS_DETAIL(eop_scalar
)<T
>
312 ( EXTL_NS_DETAIL(eop_add
) < T
313 , EXTL_NS_DETAIL(eop_scalar
)<T
>
316 ( EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
323 template< typename_param_k T
324 , typename_param_k A1
326 EXTL_NS_DETAIL(vvector_expr
) < T
327 , EXTL_NS_DETAIL(eop_sub
) < T
329 , EXTL_NS_DETAIL(eop_scalar
)<T
>
332 operator -(expr_vvector
<T
, A1
> const& ar1
, T
const& value
)
334 return EXTL_NS_DETAIL(vvector_expr
) < T
335 , EXTL_NS_DETAIL(eop_sub
) < T
337 , EXTL_NS_DETAIL(eop_scalar
)<T
>
340 ( EXTL_NS_DETAIL(eop_sub
) < T
342 , EXTL_NS_DETAIL(eop_scalar
)<T
>
345 , EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
350 template< typename_param_k T
351 , typename_param_k A2
353 EXTL_NS_DETAIL(vvector_expr
) < T
354 , EXTL_NS_DETAIL(eop_sub
) < T
355 , EXTL_NS_DETAIL(eop_scalar
)<T
>
359 operator -(T
const& value
, expr_vvector
<T
, A2
> const& ar2
)
361 return EXTL_NS_DETAIL(vvector_expr
) < T
362 , EXTL_NS_DETAIL(eop_sub
) < T
363 , EXTL_NS_DETAIL(eop_scalar
)<T
>
367 ( EXTL_NS_DETAIL(eop_sub
) < T
368 , EXTL_NS_DETAIL(eop_scalar
)<T
>
371 ( EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
378 template< typename_param_k T
379 , typename_param_k A1
381 EXTL_NS_DETAIL(vvector_expr
) < T
382 , EXTL_NS_DETAIL(eop_mul
) < T
384 , EXTL_NS_DETAIL(eop_scalar
)<T
>
387 operator *(expr_vvector
<T
, A1
> const& ar1
, T
const& value
)
389 return EXTL_NS_DETAIL(vvector_expr
) < T
390 , EXTL_NS_DETAIL(eop_mul
) < T
392 , EXTL_NS_DETAIL(eop_scalar
)<T
>
395 ( EXTL_NS_DETAIL(eop_mul
) < T
397 , EXTL_NS_DETAIL(eop_scalar
)<T
>
400 , EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
405 template< typename_param_k T
406 , typename_param_k A2
408 EXTL_NS_DETAIL(vvector_expr
) < T
409 , EXTL_NS_DETAIL(eop_mul
) < T
410 , EXTL_NS_DETAIL(eop_scalar
)<T
>
414 operator *(T
const& value
, expr_vvector
<T
, A2
> const& ar2
)
416 return EXTL_NS_DETAIL(vvector_expr
) < T
417 , EXTL_NS_DETAIL(eop_mul
) < T
418 , EXTL_NS_DETAIL(eop_scalar
)<T
>
422 ( EXTL_NS_DETAIL(eop_mul
) < T
423 , EXTL_NS_DETAIL(eop_scalar
)<T
>
426 ( EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
433 template< typename_param_k T
434 , typename_param_k A1
436 EXTL_NS_DETAIL(vvector_expr
) < T
437 , EXTL_NS_DETAIL(eop_div
) < T
439 , EXTL_NS_DETAIL(eop_scalar
)<T
>
442 operator /(expr_vvector
<T
, A1
> const& ar1
, T
const& value
)
444 return EXTL_NS_DETAIL(vvector_expr
) < T
445 , EXTL_NS_DETAIL(eop_div
) < T
447 , EXTL_NS_DETAIL(eop_scalar
)<T
>
450 ( EXTL_NS_DETAIL(eop_div
) < T
452 , EXTL_NS_DETAIL(eop_scalar
)<T
>
455 , EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
460 template< typename_param_k T
461 , typename_param_k A2
463 EXTL_NS_DETAIL(vvector_expr
) < T
464 , EXTL_NS_DETAIL(eop_div
) < T
465 , EXTL_NS_DETAIL(eop_scalar
)<T
>
469 operator /(T
const& value
, expr_vvector
<T
, A2
> const& ar2
)
471 return EXTL_NS_DETAIL(vvector_expr
) < T
472 , EXTL_NS_DETAIL(eop_div
) < T
473 , EXTL_NS_DETAIL(eop_scalar
)<T
>
477 ( EXTL_NS_DETAIL(eop_div
) < T
478 , EXTL_NS_DETAIL(eop_scalar
)<T
>
481 ( EXTL_NS_DETAIL(eop_scalar
)<T
>(value
) // temporary copy
489 /* ///////////////////////////////////////////////////////////////////////
494 /* //////////////////////////////////////////////////////////////////// */
495 #endif /* EXTL_MATH_EXPR_VVECTOR_H */
496 /* //////////////////////////////////////////////////////////////////// */