33 #ifndef _VALARRAY_AFTER_H
34 #define _VALARRAY_AFTER_H 1
36 #pragma GCC system_header
38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 typedef typename _Dom::value_type value_type;
51 _GBase (
const _Dom& __e,
const valarray<size_t>& __i)
52 : _M_expr (__e), _M_index(__i) {}
56 {
return _M_expr[_M_index[__i]]; }
60 {
return _M_index.size(); }
64 const valarray<size_t>& _M_index;
67 template<
typename _Tp>
68 class _GBase<_Array<_Tp> >
71 typedef _Tp value_type;
73 _GBase (_Array<_Tp> __a,
const valarray<size_t>& __i)
74 : _M_array (__a), _M_index(__i) {}
78 {
return _M_array._M_data[_M_index[__i]]; }
82 {
return _M_index.size(); }
85 const _Array<_Tp> _M_array;
86 const valarray<size_t>& _M_index;
90 struct _GClos<_Expr, _Dom>
93 typedef _GBase<_Dom> _Base;
94 typedef typename _Base::value_type value_type;
96 _GClos (
const _Dom& __e,
const valarray<size_t>& __i)
100 template<
typename _Tp>
101 struct _GClos<_ValArray, _Tp>
102 : _GBase<_Array<_Tp> >
104 typedef _GBase<_Array<_Tp> > _Base;
105 typedef typename _Base::value_type value_type;
107 _GClos (_Array<_Tp> __a,
const valarray<size_t>& __i)
108 : _Base (__a, __i) {}
118 typedef typename _Dom::value_type value_type;
120 _IBase (
const _Dom& __e,
const valarray<size_t>& __i)
121 : _M_expr (__e), _M_index (__i) {}
125 {
return _M_expr[_M_index[__i]]; }
129 {
return _M_index.size(); }
133 const valarray<size_t>& _M_index;
137 struct _IClos<_Expr, _Dom>
140 typedef _IBase<_Dom> _Base;
141 typedef typename _Base::value_type value_type;
143 _IClos (
const _Dom& __e,
const valarray<size_t>& __i)
144 : _Base (__e, __i) {}
147 template<
typename _Tp>
148 struct _IClos<_ValArray, _Tp>
149 : _IBase<valarray<_Tp> >
151 typedef _IBase<valarray<_Tp> > _Base;
152 typedef _Tp value_type;
154 _IClos (
const valarray<_Tp>& __a,
const valarray<size_t>& __i)
155 : _Base (__a, __i) {}
161 template<
class _Clos,
typename _Tp>
165 typedef _Tp value_type;
169 const _Clos& operator()()
const;
173 valarray<value_type>
operator[](
const gslice&)
const;
174 valarray<value_type>
operator[](
const valarray<bool>&)
const;
175 valarray<value_type>
operator[](
const valarray<size_t>&)
const;
177 _Expr<_UnClos<__unary_plus, std::_Expr, _Clos>, value_type>
180 _Expr<_UnClos<__negate, std::_Expr, _Clos>, value_type>
183 _Expr<_UnClos<__bitwise_not, std::_Expr, _Clos>, value_type>
186 _Expr<_UnClos<__logical_not, std::_Expr, _Clos>,
bool>
190 value_type sum()
const;
192 valarray<value_type> shift(
int)
const;
193 valarray<value_type> cshift(
int)
const;
195 value_type
min()
const;
196 value_type
max()
const;
198 valarray<value_type> apply(value_type (*)(
const value_type&))
const;
199 valarray<value_type> apply(value_type (*)(value_type))
const;
202 const _Clos _M_closure;
205 template<
class _Clos,
typename _Tp>
207 _Expr<_Clos, _Tp>::_Expr(
const _Clos& __c) : _M_closure(__c) {}
209 template<
class _Clos,
typename _Tp>
211 _Expr<_Clos, _Tp>::operator()()
const
212 {
return _M_closure; }
214 template<
class _Clos,
typename _Tp>
217 {
return _M_closure[__i]; }
219 template<
class _Clos,
typename _Tp>
223 valarray<_Tp> __v = valarray<_Tp>(*this)[__s];
227 template<
class _Clos,
typename _Tp>
231 valarray<_Tp> __v = valarray<_Tp>(*this)[__gs];
235 template<
class _Clos,
typename _Tp>
239 valarray<_Tp> __v = valarray<_Tp>(*this)[__m];
243 template<
class _Clos,
typename _Tp>
247 valarray<_Tp> __v = valarray<_Tp>(*this)[__i];
251 template<
class _Clos,
typename _Tp>
254 {
return _M_closure.size(); }
256 template<
class _Clos,
typename _Tp>
258 _Expr<_Clos, _Tp>::shift(
int __n)
const
260 valarray<_Tp> __v = valarray<_Tp>(*this).shift(__n);
264 template<
class _Clos,
typename _Tp>
266 _Expr<_Clos, _Tp>::cshift(
int __n)
const
268 valarray<_Tp> __v = valarray<_Tp>(*this).cshift(__n);
272 template<
class _Clos,
typename _Tp>
274 _Expr<_Clos, _Tp>::apply(_Tp __f(
const _Tp&))
const
276 valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f);
280 template<
class _Clos,
typename _Tp>
282 _Expr<_Clos, _Tp>::apply(_Tp __f(_Tp))
const
284 valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f);
289 template<
class _Clos,
typename _Tp>
291 _Expr<_Clos, _Tp>::sum()
const
293 size_t __n = _M_closure.size();
298 _Tp __s = _M_closure[--__n];
300 __s += _M_closure[--__n];
305 template<
class _Clos,
typename _Tp>
308 {
return __valarray_min(_M_closure); }
310 template<
class _Clos,
typename _Tp>
313 {
return __valarray_max(_M_closure); }
315 template<
class _Dom,
typename _Tp>
316 inline _Expr<_UnClos<__logical_not, _Expr, _Dom>,
bool>
317 _Expr<_Dom, _Tp>::operator!()
const
319 typedef _UnClos<__logical_not, std::_Expr, _Dom> _Closure;
320 return _Expr<_Closure, bool>(_Closure(this->_M_closure));
323 #define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \
324 template<class _Dom, typename _Tp> \
325 inline _Expr<_UnClos<_Name, std::_Expr, _Dom>, _Tp> \
326 _Expr<_Dom, _Tp>::operator _Op() const \
328 typedef _UnClos<_Name, std::_Expr, _Dom> _Closure; \
329 return _Expr<_Closure, _Tp>(_Closure(this->_M_closure)); \
332 _DEFINE_EXPR_UNARY_OPERATOR(+, __unary_plus)
333 _DEFINE_EXPR_UNARY_OPERATOR(-, __negate)
334 _DEFINE_EXPR_UNARY_OPERATOR(~, __bitwise_not)
336 #undef _DEFINE_EXPR_UNARY_OPERATOR
338 #define _DEFINE_EXPR_BINARY_OPERATOR(_Op, _Name) \
339 template<class _Dom1, class _Dom2> \
340 inline _Expr<_BinClos<_Name, _Expr, _Expr, _Dom1, _Dom2>, \
341 typename __fun<_Name, typename _Dom1::value_type>::result_type> \
342 operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \
343 const _Expr<_Dom2, typename _Dom2::value_type>& __w) \
345 typedef typename _Dom1::value_type _Arg; \
346 typedef typename __fun<_Name, _Arg>::result_type _Value; \
347 typedef _BinClos<_Name, _Expr, _Expr, _Dom1, _Dom2> _Closure; \
348 return _Expr<_Closure, _Value>(_Closure(__v(), __w())); \
351 template<class _Dom> \
352 inline _Expr<_BinClos<_Name, _Expr, _Constant, _Dom, \
353 typename _Dom::value_type>, \
354 typename __fun<_Name, typename _Dom::value_type>::result_type> \
355 operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \
356 const typename _Dom::value_type& __t) \
358 typedef typename _Dom::value_type _Arg; \
359 typedef typename __fun<_Name, _Arg>::result_type _Value; \
360 typedef _BinClos<_Name, _Expr, _Constant, _Dom, _Arg> _Closure; \
361 return _Expr<_Closure, _Value>(_Closure(__v(), __t)); \
364 template<class _Dom> \
365 inline _Expr<_BinClos<_Name, _Constant, _Expr, \
366 typename _Dom::value_type, _Dom>, \
367 typename __fun<_Name, typename _Dom::value_type>::result_type> \
368 operator _Op(const typename _Dom::value_type& __t, \
369 const _Expr<_Dom, typename _Dom::value_type>& __v) \
371 typedef typename _Dom::value_type _Arg; \
372 typedef typename __fun<_Name, _Arg>::result_type _Value; \
373 typedef _BinClos<_Name, _Constant, _Expr, _Arg, _Dom> _Closure; \
374 return _Expr<_Closure, _Value>(_Closure(__t, __v())); \
377 template<class _Dom> \
378 inline _Expr<_BinClos<_Name, _Expr, _ValArray, \
379 _Dom, typename _Dom::value_type>, \
380 typename __fun<_Name, typename _Dom::value_type>::result_type> \
381 operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \
382 const valarray<typename _Dom::value_type>& __v) \
384 typedef typename _Dom::value_type _Arg; \
385 typedef typename __fun<_Name, _Arg>::result_type _Value; \
386 typedef _BinClos<_Name, _Expr, _ValArray, _Dom, _Arg> _Closure; \
387 return _Expr<_Closure, _Value>(_Closure(__e(), __v)); \
390 template<class _Dom> \
391 inline _Expr<_BinClos<_Name, _ValArray, _Expr, \
392 typename _Dom::value_type, _Dom>, \
393 typename __fun<_Name, typename _Dom::value_type>::result_type> \
394 operator _Op(const valarray<typename _Dom::value_type>& __v, \
395 const _Expr<_Dom, typename _Dom::value_type>& __e) \
397 typedef typename _Dom::value_type _Tp; \
398 typedef typename __fun<_Name, _Tp>::result_type _Value; \
399 typedef _BinClos<_Name, _ValArray, _Expr, _Tp, _Dom> _Closure; \
400 return _Expr<_Closure, _Value>(_Closure(__v, __e ())); \
403 _DEFINE_EXPR_BINARY_OPERATOR(+, __plus)
404 _DEFINE_EXPR_BINARY_OPERATOR(-, __minus)
405 _DEFINE_EXPR_BINARY_OPERATOR(*, __multiplies)
406 _DEFINE_EXPR_BINARY_OPERATOR(/, __divides)
407 _DEFINE_EXPR_BINARY_OPERATOR(%, __modulus)
408 _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
409 _DEFINE_EXPR_BINARY_OPERATOR(&, __bitwise_and)
410 _DEFINE_EXPR_BINARY_OPERATOR(|, __bitwise_or)
411 _DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)
412 _DEFINE_EXPR_BINARY_OPERATOR(>>, __shift_right)
413 _DEFINE_EXPR_BINARY_OPERATOR(&&, __logical_and)
414 _DEFINE_EXPR_BINARY_OPERATOR(||, __logical_or)
415 _DEFINE_EXPR_BINARY_OPERATOR(==, __equal_to)
416 _DEFINE_EXPR_BINARY_OPERATOR(!=, __not_equal_to)
417 _DEFINE_EXPR_BINARY_OPERATOR(<, __less)
418 _DEFINE_EXPR_BINARY_OPERATOR(>, __greater)
419 _DEFINE_EXPR_BINARY_OPERATOR(<=, __less_equal)
420 _DEFINE_EXPR_BINARY_OPERATOR(>=, __greater_equal)
422 #undef _DEFINE_EXPR_BINARY_OPERATOR
424 #define _DEFINE_EXPR_UNARY_FUNCTION(_Name, _UName) \
425 template<class _Dom> \
426 inline _Expr<_UnClos<_UName, _Expr, _Dom>, \
427 typename _Dom::value_type> \
428 _Name(const _Expr<_Dom, typename _Dom::value_type>& __e) \
430 typedef typename _Dom::value_type _Tp; \
431 typedef _UnClos<_UName, _Expr, _Dom> _Closure; \
432 return _Expr<_Closure, _Tp>(_Closure(__e())); \
435 template<typename _Tp> \
436 inline _Expr<_UnClos<_UName, _ValArray, _Tp>, _Tp> \
437 _Name(const valarray<_Tp>& __v) \
439 typedef _UnClos<_UName, _ValArray, _Tp> _Closure; \
440 return _Expr<_Closure, _Tp>(_Closure(__v)); \
443 _DEFINE_EXPR_UNARY_FUNCTION(
abs, _Abs)
444 _DEFINE_EXPR_UNARY_FUNCTION(
cos, _Cos)
445 _DEFINE_EXPR_UNARY_FUNCTION(
acos, _Acos)
446 _DEFINE_EXPR_UNARY_FUNCTION(
cosh, _Cosh)
447 _DEFINE_EXPR_UNARY_FUNCTION(
sin, _Sin)
448 _DEFINE_EXPR_UNARY_FUNCTION(
asin, _Asin)
449 _DEFINE_EXPR_UNARY_FUNCTION(
sinh, _Sinh)
450 _DEFINE_EXPR_UNARY_FUNCTION(
tan, _Tan)
451 _DEFINE_EXPR_UNARY_FUNCTION(
tanh, _Tanh)
452 _DEFINE_EXPR_UNARY_FUNCTION(
atan, _Atan)
453 _DEFINE_EXPR_UNARY_FUNCTION(
exp, _Exp)
454 _DEFINE_EXPR_UNARY_FUNCTION(
log, _Log)
455 _DEFINE_EXPR_UNARY_FUNCTION(
log10, _Log10)
456 _DEFINE_EXPR_UNARY_FUNCTION(
sqrt, _Sqrt)
458 #undef _DEFINE_EXPR_UNARY_FUNCTION
460 #define _DEFINE_EXPR_BINARY_FUNCTION(_Fun, _UFun) \
461 template<class _Dom1, class _Dom2> \
462 inline _Expr<_BinClos<_UFun, _Expr, _Expr, _Dom1, _Dom2>, \
463 typename _Dom1::value_type> \
464 _Fun(const _Expr<_Dom1, typename _Dom1::value_type>& __e1, \
465 const _Expr<_Dom2, typename _Dom2::value_type>& __e2) \
467 typedef typename _Dom1::value_type _Tp; \
468 typedef _BinClos<_UFun, _Expr, _Expr, _Dom1, _Dom2> _Closure; \
469 return _Expr<_Closure, _Tp>(_Closure(__e1(), __e2())); \
472 template<class _Dom> \
473 inline _Expr<_BinClos<_UFun, _Expr, _ValArray, _Dom, \
474 typename _Dom::value_type>, \
475 typename _Dom::value_type> \
476 _Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \
477 const valarray<typename _Dom::value_type>& __v) \
479 typedef typename _Dom::value_type _Tp; \
480 typedef _BinClos<_UFun, _Expr, _ValArray, _Dom, _Tp> _Closure; \
481 return _Expr<_Closure, _Tp>(_Closure(__e(), __v)); \
484 template<class _Dom> \
485 inline _Expr<_BinClos<_UFun, _ValArray, _Expr, \
486 typename _Dom::value_type, _Dom>, \
487 typename _Dom::value_type> \
488 _Fun(const valarray<typename _Dom::valarray>& __v, \
489 const _Expr<_Dom, typename _Dom::value_type>& __e) \
491 typedef typename _Dom::value_type _Tp; \
492 typedef _BinClos<_UFun, _ValArray, _Expr, _Tp, _Dom> _Closure; \
493 return _Expr<_Closure, _Tp>(_Closure(__v, __e())); \
496 template<class _Dom> \
497 inline _Expr<_BinClos<_UFun, _Expr, _Constant, _Dom, \
498 typename _Dom::value_type>, \
499 typename _Dom::value_type> \
500 _Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \
501 const typename _Dom::value_type& __t) \
503 typedef typename _Dom::value_type _Tp; \
504 typedef _BinClos<_UFun, _Expr, _Constant, _Dom, _Tp> _Closure; \
505 return _Expr<_Closure, _Tp>(_Closure(__e(), __t)); \
508 template<class _Dom> \
509 inline _Expr<_BinClos<_UFun, _Constant, _Expr, \
510 typename _Dom::value_type, _Dom>, \
511 typename _Dom::value_type> \
512 _Fun(const typename _Dom::value_type& __t, \
513 const _Expr<_Dom, typename _Dom::value_type>& __e) \
515 typedef typename _Dom::value_type _Tp; \
516 typedef _BinClos<_UFun, _Constant, _Expr, _Tp, _Dom> _Closure; \
517 return _Expr<_Closure, _Tp>(_Closure(__t, __e())); \
520 template<typename _Tp> \
521 inline _Expr<_BinClos<_UFun, _ValArray, _ValArray, _Tp, _Tp>, _Tp> \
522 _Fun(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
524 typedef _BinClos<_UFun, _ValArray, _ValArray, _Tp, _Tp> _Closure;\
525 return _Expr<_Closure, _Tp>(_Closure(__v, __w)); \
528 template<typename _Tp> \
529 inline _Expr<_BinClos<_UFun, _ValArray, _Constant, _Tp, _Tp>, _Tp> \
530 _Fun(const valarray<_Tp>& __v, const _Tp& __t) \
532 typedef _BinClos<_UFun, _ValArray, _Constant, _Tp, _Tp> _Closure;\
533 return _Expr<_Closure, _Tp>(_Closure(__v, __t)); \
536 template<typename _Tp> \
537 inline _Expr<_BinClos<_UFun, _Constant, _ValArray, _Tp, _Tp>, _Tp> \
538 _Fun(const _Tp& __t, const valarray<_Tp>& __v) \
540 typedef _BinClos<_UFun, _Constant, _ValArray, _Tp, _Tp> _Closure;\
541 return _Expr<_Closure, _Tp>(_Closure(__t, __v)); \
544 _DEFINE_EXPR_BINARY_FUNCTION(atan2, _Atan2)
545 _DEFINE_EXPR_BINARY_FUNCTION(
pow, _Pow)
547 #undef _DEFINE_EXPR_BINARY_FUNCTION
549 _GLIBCXX_END_NAMESPACE_VERSION