32 #ifndef _VALARRAY_AFTER_H
33 #define _VALARRAY_AFTER_H 1
35 #pragma GCC system_header
37 namespace std _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 typedef typename _Dom::value_type value_type;
50 _GBase (
const _Dom& __e,
const valarray<size_t>& __i)
51 : _M_expr (__e), _M_index(__i) {}
54 operator[] (
size_t __i)
const
55 {
return _M_expr[_M_index[__i]]; }
59 {
return _M_index.size(); }
63 const valarray<size_t>& _M_index;
66 template<
typename _Tp>
67 class _GBase<_Array<_Tp> >
70 typedef _Tp value_type;
72 _GBase (_Array<_Tp> __a,
const valarray<size_t>& __i)
73 : _M_array (__a), _M_index(__i) {}
76 operator[] (
size_t __i)
const
77 {
return _M_array._M_data[_M_index[__i]]; }
81 {
return _M_index.size(); }
84 const _Array<_Tp> _M_array;
85 const valarray<size_t>& _M_index;
89 struct _GClos<_Expr, _Dom>
92 typedef _GBase<_Dom> _Base;
93 typedef typename _Base::value_type value_type;
95 _GClos (
const _Dom& __e,
const valarray<size_t>& __i)
99 template<
typename _Tp>
100 struct _GClos<_ValArray, _Tp>
101 : _GBase<_Array<_Tp> >
103 typedef _GBase<_Array<_Tp> > _Base;
104 typedef typename _Base::value_type value_type;
106 _GClos (_Array<_Tp> __a,
const valarray<size_t>& __i)
107 : _Base (__a, __i) {}
117 typedef typename _Dom::value_type value_type;
119 _IBase (
const _Dom& __e,
const valarray<size_t>& __i)
120 : _M_expr (__e), _M_index (__i) {}
123 operator[] (
size_t __i)
const
124 {
return _M_expr[_M_index[__i]]; }
128 {
return _M_index.size(); }
132 const valarray<size_t>& _M_index;
136 struct _IClos<_Expr, _Dom>
139 typedef _IBase<_Dom> _Base;
140 typedef typename _Base::value_type value_type;
142 _IClos (
const _Dom& __e,
const valarray<size_t>& __i)
143 : _Base (__e, __i) {}
146 template<
typename _Tp>
147 struct _IClos<_ValArray, _Tp>
148 : _IBase<valarray<_Tp> >
150 typedef _IBase<valarray<_Tp> > _Base;
151 typedef _Tp value_type;
153 _IClos (
const valarray<_Tp>& __a,
const valarray<size_t>& __i)
154 : _Base (__a, __i) {}
160 template<
class _Clos,
typename _Tp>
164 typedef _Tp value_type;
168 const _Clos& operator()()
const;
170 value_type operator[](
size_t)
const;
171 valarray<value_type> operator[](slice)
const;
172 valarray<value_type> operator[](
const gslice&)
const;
173 valarray<value_type> operator[](
const valarray<bool>&)
const;
174 valarray<value_type> operator[](
const valarray<size_t>&)
const;
176 _Expr<_UnClos<__unary_plus, std::_Expr, _Clos>, value_type>
179 _Expr<_UnClos<__negate, std::_Expr, _Clos>, value_type>
182 _Expr<_UnClos<__bitwise_not, std::_Expr, _Clos>, value_type>
185 _Expr<_UnClos<__logical_not, std::_Expr, _Clos>,
bool>
189 value_type sum()
const;
191 valarray<value_type> shift(
int)
const;
192 valarray<value_type> cshift(
int)
const;
194 value_type
min()
const;
195 value_type
max()
const;
197 valarray<value_type> apply(value_type (*)(
const value_type&))
const;
198 valarray<value_type> apply(value_type (*)(value_type))
const;
201 const _Clos _M_closure;
204 template<
class _Clos,
typename _Tp>
206 _Expr<_Clos, _Tp>::_Expr(
const _Clos& __c) : _M_closure(__c) {}
208 template<
class _Clos,
typename _Tp>
210 _Expr<_Clos, _Tp>::operator()()
const
211 {
return _M_closure; }
213 template<
class _Clos,
typename _Tp>
215 _Expr<_Clos, _Tp>::operator[](
size_t __i)
const
216 {
return _M_closure[__i]; }
218 template<
class _Clos,
typename _Tp>
220 _Expr<_Clos, _Tp>::operator[](slice __s)
const
222 valarray<_Tp> __v = valarray<_Tp>(*this)[__s];
226 template<
class _Clos,
typename _Tp>
228 _Expr<_Clos, _Tp>::operator[](
const gslice& __gs)
const
230 valarray<_Tp> __v = valarray<_Tp>(*this)[__gs];
234 template<
class _Clos,
typename _Tp>
236 _Expr<_Clos, _Tp>::operator[](
const valarray<bool>& __m)
const
238 valarray<_Tp> __v = valarray<_Tp>(*this)[__m];
242 template<
class _Clos,
typename _Tp>
244 _Expr<_Clos, _Tp>::operator[](
const valarray<size_t>& __i)
const
246 valarray<_Tp> __v = valarray<_Tp>(*this)[__i];
250 template<
class _Clos,
typename _Tp>
252 _Expr<_Clos, _Tp>::size()
const
253 {
return _M_closure.size(); }
255 template<
class _Clos,
typename _Tp>
257 _Expr<_Clos, _Tp>::shift(
int __n)
const
259 valarray<_Tp> __v = valarray<_Tp>(*this).shift(__n);
263 template<
class _Clos,
typename _Tp>
265 _Expr<_Clos, _Tp>::cshift(
int __n)
const
267 valarray<_Tp> __v = valarray<_Tp>(*this).cshift(__n);
271 template<
class _Clos,
typename _Tp>
273 _Expr<_Clos, _Tp>::apply(_Tp __f(
const _Tp&))
const
275 valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f);
279 template<
class _Clos,
typename _Tp>
281 _Expr<_Clos, _Tp>::apply(_Tp __f(_Tp))
const
283 valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f);
288 template<
class _Clos,
typename _Tp>
290 _Expr<_Clos, _Tp>::sum()
const
292 size_t __n = _M_closure.size();
297 _Tp __s = _M_closure[--__n];
299 __s += _M_closure[--__n];
304 template<
class _Clos,
typename _Tp>
307 {
return __valarray_min(_M_closure); }
309 template<
class _Clos,
typename _Tp>
312 {
return __valarray_max(_M_closure); }
314 template<
class _Dom,
typename _Tp>
315 inline _Expr<_UnClos<__logical_not, _Expr, _Dom>,
bool>
316 _Expr<_Dom, _Tp>::operator!()
const
318 typedef _UnClos<__logical_not, std::_Expr, _Dom> _Closure;
319 return _Expr<_Closure, bool>(_Closure(this->_M_closure));
322 #define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \
323 template<class _Dom, typename _Tp> \
324 inline _Expr<_UnClos<_Name, std::_Expr, _Dom>, _Tp> \
325 _Expr<_Dom, _Tp>::operator _Op() const \
327 typedef _UnClos<_Name, std::_Expr, _Dom> _Closure; \
328 return _Expr<_Closure, _Tp>(_Closure(this->_M_closure)); \
331 _DEFINE_EXPR_UNARY_OPERATOR(+, __unary_plus)
332 _DEFINE_EXPR_UNARY_OPERATOR(-, __negate)
333 _DEFINE_EXPR_UNARY_OPERATOR(~, __bitwise_not)
335 #undef _DEFINE_EXPR_UNARY_OPERATOR
337 #define _DEFINE_EXPR_BINARY_OPERATOR(_Op, _Name) \
338 template<class _Dom1, class _Dom2> \
339 inline _Expr<_BinClos<_Name, _Expr, _Expr, _Dom1, _Dom2>, \
340 typename __fun<_Name, typename _Dom1::value_type>::result_type> \
341 operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \
342 const _Expr<_Dom2, typename _Dom2::value_type>& __w) \
344 typedef typename _Dom1::value_type _Arg; \
345 typedef typename __fun<_Name, _Arg>::result_type _Value; \
346 typedef _BinClos<_Name, _Expr, _Expr, _Dom1, _Dom2> _Closure; \
347 return _Expr<_Closure, _Value>(_Closure(__v(), __w())); \
350 template<class _Dom> \
351 inline _Expr<_BinClos<_Name, _Expr, _Constant, _Dom, \
352 typename _Dom::value_type>, \
353 typename __fun<_Name, typename _Dom::value_type>::result_type> \
354 operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \
355 const typename _Dom::value_type& __t) \
357 typedef typename _Dom::value_type _Arg; \
358 typedef typename __fun<_Name, _Arg>::result_type _Value; \
359 typedef _BinClos<_Name, _Expr, _Constant, _Dom, _Arg> _Closure; \
360 return _Expr<_Closure, _Value>(_Closure(__v(), __t)); \
363 template<class _Dom> \
364 inline _Expr<_BinClos<_Name, _Constant, _Expr, \
365 typename _Dom::value_type, _Dom>, \
366 typename __fun<_Name, typename _Dom::value_type>::result_type> \
367 operator _Op(const typename _Dom::value_type& __t, \
368 const _Expr<_Dom, typename _Dom::value_type>& __v) \
370 typedef typename _Dom::value_type _Arg; \
371 typedef typename __fun<_Name, _Arg>::result_type _Value; \
372 typedef _BinClos<_Name, _Constant, _Expr, _Arg, _Dom> _Closure; \
373 return _Expr<_Closure, _Value>(_Closure(__t, __v())); \
376 template<class _Dom> \
377 inline _Expr<_BinClos<_Name, _Expr, _ValArray, \
378 _Dom, typename _Dom::value_type>, \
379 typename __fun<_Name, typename _Dom::value_type>::result_type> \
380 operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \
381 const valarray<typename _Dom::value_type>& __v) \
383 typedef typename _Dom::value_type _Arg; \
384 typedef typename __fun<_Name, _Arg>::result_type _Value; \
385 typedef _BinClos<_Name, _Expr, _ValArray, _Dom, _Arg> _Closure; \
386 return _Expr<_Closure, _Value>(_Closure(__e(), __v)); \
389 template<class _Dom> \
390 inline _Expr<_BinClos<_Name, _ValArray, _Expr, \
391 typename _Dom::value_type, _Dom>, \
392 typename __fun<_Name, typename _Dom::value_type>::result_type> \
393 operator _Op(const valarray<typename _Dom::value_type>& __v, \
394 const _Expr<_Dom, typename _Dom::value_type>& __e) \
396 typedef typename _Dom::value_type _Tp; \
397 typedef typename __fun<_Name, _Tp>::result_type _Value; \
398 typedef _BinClos<_Name, _ValArray, _Expr, _Tp, _Dom> _Closure; \
399 return _Expr<_Closure, _Value>(_Closure(__v, __e ())); \
402 _DEFINE_EXPR_BINARY_OPERATOR(+, __plus)
403 _DEFINE_EXPR_BINARY_OPERATOR(-, __minus)
404 _DEFINE_EXPR_BINARY_OPERATOR(*, __multiplies)
405 _DEFINE_EXPR_BINARY_OPERATOR(/, __divides)
406 _DEFINE_EXPR_BINARY_OPERATOR(%, __modulus)
407 _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
408 _DEFINE_EXPR_BINARY_OPERATOR(&, __bitwise_and)
409 _DEFINE_EXPR_BINARY_OPERATOR(|, __bitwise_or)
410 _DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)
411 _DEFINE_EXPR_BINARY_OPERATOR(>>, __shift_right)
412 _DEFINE_EXPR_BINARY_OPERATOR(&&, __logical_and)
413 _DEFINE_EXPR_BINARY_OPERATOR(||, __logical_or)
414 _DEFINE_EXPR_BINARY_OPERATOR(==, __equal_to)
415 _DEFINE_EXPR_BINARY_OPERATOR(!=, __not_equal_to)
416 _DEFINE_EXPR_BINARY_OPERATOR(<, __less)
417 _DEFINE_EXPR_BINARY_OPERATOR(>, __greater)
418 _DEFINE_EXPR_BINARY_OPERATOR(<=, __less_equal)
419 _DEFINE_EXPR_BINARY_OPERATOR(>=, __greater_equal)
421 #undef _DEFINE_EXPR_BINARY_OPERATOR
423 #define _DEFINE_EXPR_UNARY_FUNCTION(_Name, _UName) \
424 template<class _Dom> \
425 inline _Expr<_UnClos<_UName, _Expr, _Dom>, \
426 typename _Dom::value_type> \
427 _Name(const _Expr<_Dom, typename _Dom::value_type>& __e) \
429 typedef typename _Dom::value_type _Tp; \
430 typedef _UnClos<_UName, _Expr, _Dom> _Closure; \
431 return _Expr<_Closure, _Tp>(_Closure(__e())); \
434 template<typename _Tp> \
435 inline _Expr<_UnClos<_UName, _ValArray, _Tp>, _Tp> \
436 _Name(const valarray<_Tp>& __v) \
438 typedef _UnClos<_UName, _ValArray, _Tp> _Closure; \
439 return _Expr<_Closure, _Tp>(_Closure(__v)); \
442 _DEFINE_EXPR_UNARY_FUNCTION(abs, _Abs)
443 _DEFINE_EXPR_UNARY_FUNCTION(cos, _Cos)
444 _DEFINE_EXPR_UNARY_FUNCTION(acos, _Acos)
445 _DEFINE_EXPR_UNARY_FUNCTION(cosh, _Cosh)
446 _DEFINE_EXPR_UNARY_FUNCTION(sin, _Sin)
447 _DEFINE_EXPR_UNARY_FUNCTION(asin, _Asin)
448 _DEFINE_EXPR_UNARY_FUNCTION(sinh, _Sinh)
449 _DEFINE_EXPR_UNARY_FUNCTION(tan, _Tan)
450 _DEFINE_EXPR_UNARY_FUNCTION(tanh, _Tanh)
451 _DEFINE_EXPR_UNARY_FUNCTION(atan, _Atan)
452 _DEFINE_EXPR_UNARY_FUNCTION(exp, _Exp)
453 _DEFINE_EXPR_UNARY_FUNCTION(log, _Log)
454 _DEFINE_EXPR_UNARY_FUNCTION(log10, _Log10)
455 _DEFINE_EXPR_UNARY_FUNCTION(sqrt, _Sqrt)
457 #undef _DEFINE_EXPR_UNARY_FUNCTION
459 #define _DEFINE_EXPR_BINARY_FUNCTION(_Fun, _UFun) \
460 template<class _Dom1, class _Dom2> \
461 inline _Expr<_BinClos<_UFun, _Expr, _Expr, _Dom1, _Dom2>, \
462 typename _Dom1::value_type> \
463 _Fun(const _Expr<_Dom1, typename _Dom1::value_type>& __e1, \
464 const _Expr<_Dom2, typename _Dom2::value_type>& __e2) \
466 typedef typename _Dom1::value_type _Tp; \
467 typedef _BinClos<_UFun, _Expr, _Expr, _Dom1, _Dom2> _Closure; \
468 return _Expr<_Closure, _Tp>(_Closure(__e1(), __e2())); \
471 template<class _Dom> \
472 inline _Expr<_BinClos<_UFun, _Expr, _ValArray, _Dom, \
473 typename _Dom::value_type>, \
474 typename _Dom::value_type> \
475 _Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \
476 const valarray<typename _Dom::value_type>& __v) \
478 typedef typename _Dom::value_type _Tp; \
479 typedef _BinClos<_UFun, _Expr, _ValArray, _Dom, _Tp> _Closure; \
480 return _Expr<_Closure, _Tp>(_Closure(__e(), __v)); \
483 template<class _Dom> \
484 inline _Expr<_BinClos<_UFun, _ValArray, _Expr, \
485 typename _Dom::value_type, _Dom>, \
486 typename _Dom::value_type> \
487 _Fun(const valarray<typename _Dom::valarray>& __v, \
488 const _Expr<_Dom, typename _Dom::value_type>& __e) \
490 typedef typename _Dom::value_type _Tp; \
491 typedef _BinClos<_UFun, _ValArray, _Expr, _Tp, _Dom> _Closure; \
492 return _Expr<_Closure, _Tp>(_Closure(__v, __e())); \
495 template<class _Dom> \
496 inline _Expr<_BinClos<_UFun, _Expr, _Constant, _Dom, \
497 typename _Dom::value_type>, \
498 typename _Dom::value_type> \
499 _Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \
500 const typename _Dom::value_type& __t) \
502 typedef typename _Dom::value_type _Tp; \
503 typedef _BinClos<_UFun, _Expr, _Constant, _Dom, _Tp> _Closure; \
504 return _Expr<_Closure, _Tp>(_Closure(__e(), __t)); \
507 template<class _Dom> \
508 inline _Expr<_BinClos<_UFun, _Constant, _Expr, \
509 typename _Dom::value_type, _Dom>, \
510 typename _Dom::value_type> \
511 _Fun(const typename _Dom::value_type& __t, \
512 const _Expr<_Dom, typename _Dom::value_type>& __e) \
514 typedef typename _Dom::value_type _Tp; \
515 typedef _BinClos<_UFun, _Constant, _Expr, _Tp, _Dom> _Closure; \
516 return _Expr<_Closure, _Tp>(_Closure(__t, __e())); \
519 template<typename _Tp> \
520 inline _Expr<_BinClos<_UFun, _ValArray, _ValArray, _Tp, _Tp>, _Tp> \
521 _Fun(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
523 typedef _BinClos<_UFun, _ValArray, _ValArray, _Tp, _Tp> _Closure;\
524 return _Expr<_Closure, _Tp>(_Closure(__v, __w)); \
527 template<typename _Tp> \
528 inline _Expr<_BinClos<_UFun, _ValArray, _Constant, _Tp, _Tp>, _Tp> \
529 _Fun(const valarray<_Tp>& __v, const _Tp& __t) \
531 typedef _BinClos<_UFun, _ValArray, _Constant, _Tp, _Tp> _Closure;\
532 return _Expr<_Closure, _Tp>(_Closure(__v, __t)); \
535 template<typename _Tp> \
536 inline _Expr<_BinClos<_UFun, _Constant, _ValArray, _Tp, _Tp>, _Tp> \
537 _Fun(const _Tp& __t, const valarray<_Tp>& __v) \
539 typedef _BinClos<_UFun, _Constant, _ValArray, _Tp, _Tp> _Closure;\
540 return _Expr<_Closure, _Tp>(_Closure(__t, __v)); \
543 _DEFINE_EXPR_BINARY_FUNCTION(atan2, _Atan2)
544 _DEFINE_EXPR_BINARY_FUNCTION(pow, _Pow)
546 #undef _DEFINE_EXPR_BINARY_FUNCTION
548 _GLIBCXX_END_NAMESPACE_VERSION
const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
basic_string< _CharT, _Traits, _Alloc > operator+(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Concatenate two strings.