remove \r
[extl.git] / extl / math / expr_vvector.h
blob11de857ff0e4d9b5e99fd60363449648c5f9e937
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: expr_vvector.h
4 * Created: 08.08.11
5 * Updated: 09.01.27
7 * Brief: the expression vvector class - delay to calculate value array expression
9 * [<Home>]
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.
18 #endif
20 /*!\file expr_vvector.h
21 * \brief the expression vvector class
24 /* ///////////////////////////////////////////////////////////////////////
25 * Includes
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"
33 #endif
34 /* ///////////////////////////////////////////////////////////////////////
35 * ::extl namespace
37 EXTL_BEGIN_NAMESPACE
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
47 , typename_param_k A
49 class expr_vvector
51 /// \name Types
52 /// @{
53 public:
54 typedef A array_type;
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;
66 /// @}
68 /// \name Members
69 /// @{
70 private:
71 // note: reference
72 array_type& m_array;
73 /// @}
75 /// \name Constructors
76 /// @{
77 public:
78 explicit_k expr_vvector(array_type& ar)
79 : m_array(ar)
81 /// @}
83 private:
84 expr_vvector(class_type const& rhs);
86 /// \name Assignment
87 /// @{
88 public:
89 /// expr => array
90 template< typename_param_k T2
91 , typename_param_k E2
93 class_type& operator =(EXTL_NS_DETAIL(vvector_expr)<T2, E2> const& expr)
95 EXTL_ASSERT(size() == expr.size());
96 size_type n = size();
97 for (size_type i = 0; i < n; ++i)
99 m_array[i] = expr[i];
101 return *this;
104 /// array => array
105 class_type& operator =(class_type const& rhs)
107 if (this != &rhs)
109 EXTL_ASSERT(size() == rhs.size());
110 size_type n = size();
111 for (size_type i = 0; i < n; ++i)
113 m_array[i] = rhs[i];
117 return *this;
120 /// value => array
121 class_type& operator =(const_reference value)
123 m_array = value;
124 return *this;
126 /// @}
128 /// \name Attributes
129 /// @{
130 public:
131 size_type size() const { return m_array.size(); }
132 /// @}
134 /// \name Accessors
135 /// @{
136 public:
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; }
142 /// @}
147 // array + 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>
161 ( ar1.array()
162 , ar2.array()
167 // array + expr
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>
181 ( ar1.array()
182 , expr2.expr()
186 // expr + array
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>
200 ( expr1.expr()
201 , ar2.array()
206 // array - array
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>
220 ( ar1.array()
221 , ar2.array()
226 // array - expr
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>
240 ( ar1.array()
241 , expr2.expr()
245 // expr - array
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>
259 ( expr1.expr()
260 , ar2.array()
266 #ifdef EXTL_MATH_EOP_SCALAR_SUPPORT
267 // array + value
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
273 , A1
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
281 , A1
282 , EXTL_NS_DETAIL(eop_scalar)<T>
285 ( EXTL_NS_DETAIL(eop_add) < T
286 , A1
287 , EXTL_NS_DETAIL(eop_scalar)<T>
289 ( ar1.array()
290 , EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
294 // value + array
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>
301 , A2
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>
309 , A2
312 ( EXTL_NS_DETAIL(eop_add) < T
313 , EXTL_NS_DETAIL(eop_scalar)<T>
314 , A2
316 ( EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
317 , ar2.array()
322 // array - value
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
328 , A1
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
336 , A1
337 , EXTL_NS_DETAIL(eop_scalar)<T>
340 ( EXTL_NS_DETAIL(eop_sub) < T
341 , A1
342 , EXTL_NS_DETAIL(eop_scalar)<T>
344 ( ar1.array()
345 , EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
349 // value - array
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>
356 , A2
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>
364 , A2
367 ( EXTL_NS_DETAIL(eop_sub) < T
368 , EXTL_NS_DETAIL(eop_scalar)<T>
369 , A2
371 ( EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
372 , ar2.array()
377 // array * value
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
383 , A1
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
391 , A1
392 , EXTL_NS_DETAIL(eop_scalar)<T>
395 ( EXTL_NS_DETAIL(eop_mul) < T
396 , A1
397 , EXTL_NS_DETAIL(eop_scalar)<T>
399 ( ar1.array()
400 , EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
404 // value * array
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>
411 , A2
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>
419 , A2
422 ( EXTL_NS_DETAIL(eop_mul) < T
423 , EXTL_NS_DETAIL(eop_scalar)<T>
424 , A2
426 ( EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
427 , ar2.array()
432 // array / value
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
438 , A1
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
446 , A1
447 , EXTL_NS_DETAIL(eop_scalar)<T>
450 ( EXTL_NS_DETAIL(eop_div) < T
451 , A1
452 , EXTL_NS_DETAIL(eop_scalar)<T>
454 ( ar1.array()
455 , EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
459 // value / array
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>
466 , A2
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>
474 , A2
477 ( EXTL_NS_DETAIL(eop_div) < T
478 , EXTL_NS_DETAIL(eop_scalar)<T>
479 , A2
481 ( EXTL_NS_DETAIL(eop_scalar)<T>(value) // temporary copy
482 , ar2.array()
486 #endif
489 /* ///////////////////////////////////////////////////////////////////////
490 * ::extl namespace
492 EXTL_END_NAMESPACE
494 /* //////////////////////////////////////////////////////////////////// */
495 #endif /* EXTL_MATH_EXPR_VVECTOR_H */
496 /* //////////////////////////////////////////////////////////////////// */