diff options
author | kan <kan@FreeBSD.org> | 2003-07-11 03:42:04 +0000 |
---|---|---|
committer | kan <kan@FreeBSD.org> | 2003-07-11 03:42:04 +0000 |
commit | c7bbbdd036d3dd7ae253fb13c9994215af06f073 (patch) | |
tree | ce14546aca3a67fa3440aed52f132bafaf68fe70 /contrib/libstdc++/include/std/std_valarray.h | |
parent | b2a8872fbe1ec1c49094559ac7b78e6ea4ab7180 (diff) | |
download | FreeBSD-src-c7bbbdd036d3dd7ae253fb13c9994215af06f073.zip FreeBSD-src-c7bbbdd036d3dd7ae253fb13c9994215af06f073.tar.gz |
Gcc 3.3.1-pre 2003-07-11 C++ support bits.
Diffstat (limited to 'contrib/libstdc++/include/std/std_valarray.h')
-rw-r--r-- | contrib/libstdc++/include/std/std_valarray.h | 757 |
1 files changed, 354 insertions, 403 deletions
diff --git a/contrib/libstdc++/include/std/std_valarray.h b/contrib/libstdc++/include/std/std_valarray.h index 3957d7f..b4de5df 100644 --- a/contrib/libstdc++/include/std/std_valarray.h +++ b/contrib/libstdc++/include/std/std_valarray.h @@ -45,48 +45,47 @@ #include <cmath> #include <cstdlib> #include <numeric> -#include <functional> #include <algorithm> namespace std { - template<class _Clos, typename _Tp> class _Expr; + template<class _Clos, typename _Tp> + class _Expr; - template<typename _Tp1, typename _Tp2> class _ValArray; + template<typename _Tp1, typename _Tp2> + class _ValArray; - template<template<class> class _Oper, - template<class, class> class _Meta, class _Dom> struct _UnClos; + template<class _Oper, template<class, class> class _Meta, class _Dom> + struct _UnClos; - template<template<class> class _Oper, + template<class _Oper, template<class, class> class _Meta1, template<class, class> class _Meta2, - class _Dom1, class _Dom2> class _BinClos; + class _Dom1, class _Dom2> + class _BinClos; - template<template<class, class> class _Meta, class _Dom> class _SClos; + template<template<class, class> class _Meta, class _Dom> + class _SClos; - template<template<class, class> class _Meta, class _Dom> class _GClos; + template<template<class, class> class _Meta, class _Dom> + class _GClos; - template<template<class, class> class _Meta, class _Dom> class _IClos; + template<template<class, class> class _Meta, class _Dom> + class _IClos; - template<template<class, class> class _Meta, class _Dom> class _ValFunClos; - - template<template<class, class> class _Meta, class _Dom> class _RefFunClos; - - template<class _Tp> struct _Unary_plus; - template<class _Tp> struct _Bitwise_and; - template<class _Tp> struct _Bitwise_or; - template<class _Tp> struct _Bitwise_xor; - template<class _Tp> struct _Bitwise_not; - template<class _Tp> struct _Shift_left; - template<class _Tp> struct _Shift_right; + template<template<class, class> class _Meta, class _Dom> + class _ValFunClos; - template<class _Tp> class valarray; // An array of type _Tp - class slice; // BLAS-like slice out of an array - template<class _Tp> class slice_array; - class gslice; // generalized slice out of an array - template<class _Tp> class gslice_array; - template<class _Tp> class mask_array; // masked array - template<class _Tp> class indirect_array; // indirected array + template<template<class, class> class _Meta, class _Dom> + class _RefFunClos; + + template<class _Tp> class valarray; // An array of type _Tp + class slice; // BLAS-like slice out of an array + template<class _Tp> class slice_array; + class gslice; // generalized slice out of an array + template<class _Tp> class gslice_array; + template<class _Tp> class mask_array; // masked array + template<class _Tp> class indirect_array; // indirected array } // namespace std @@ -95,12 +94,19 @@ namespace std namespace std { - template<class _Tp> class valarray - { - public: + template<class _Tp> + class valarray + { + template<class _Op> + struct _UnaryOp + { + typedef typename __fun<_Op, _Tp>::result_type __rt; + typedef _Expr<_UnClos<_Op, _ValArray, _Tp>, __rt> _Rt; + }; + public: typedef _Tp value_type; - - // _lib.valarray.cons_ construct/destroy: + + // _lib.valarray.cons_ construct/destroy: valarray(); explicit valarray(size_t); valarray(const _Tp&, size_t); @@ -111,8 +117,8 @@ namespace std valarray(const mask_array<_Tp>&); valarray(const indirect_array<_Tp>&); template<class _Dom> - valarray(const _Expr<_Dom,_Tp>& __e); - ~valarray(); + valarray(const _Expr<_Dom,_Tp>& __e); + ~valarray(); // _lib.valarray.assign_ assignment: valarray<_Tp>& operator=(const valarray<_Tp>&); @@ -123,7 +129,7 @@ namespace std valarray<_Tp>& operator=(const indirect_array<_Tp>&); template<class _Dom> valarray<_Tp>& - operator= (const _Expr<_Dom,_Tp>&); + operator= (const _Expr<_Dom,_Tp>&); // _lib.valarray.access_ element access: // XXX: LWG to be resolved. @@ -137,67 +143,67 @@ namespace std valarray<_Tp> operator[](const valarray<bool>&) const; mask_array<_Tp> operator[](const valarray<bool>&); _Expr<_IClos<_ValArray, _Tp>, _Tp> - operator[](const valarray<size_t>&) const; + operator[](const valarray<size_t>&) const; indirect_array<_Tp> operator[](const valarray<size_t>&); // _lib.valarray.unary_ unary operators: - _Expr<_UnClos<_Unary_plus,_ValArray,_Tp>,_Tp> operator+ () const; - _Expr<_UnClos<negate,_ValArray,_Tp>,_Tp> operator- () const; - _Expr<_UnClos<_Bitwise_not,_ValArray,_Tp>,_Tp> operator~ () const; - _Expr<_UnClos<logical_not,_ValArray,_Tp>,bool> operator! () const; - + typename _UnaryOp<__unary_plus>::_Rt operator+() const; + typename _UnaryOp<__negate>::_Rt operator-() const; + typename _UnaryOp<__bitwise_not>::_Rt operator~() const; + typename _UnaryOp<__logical_not>::_Rt operator!() const; + // _lib.valarray.cassign_ computed assignment: - valarray<_Tp>& operator*= (const _Tp&); - valarray<_Tp>& operator/= (const _Tp&); - valarray<_Tp>& operator%= (const _Tp&); - valarray<_Tp>& operator+= (const _Tp&); - valarray<_Tp>& operator-= (const _Tp&); - valarray<_Tp>& operator^= (const _Tp&); - valarray<_Tp>& operator&= (const _Tp&); - valarray<_Tp>& operator|= (const _Tp&); + valarray<_Tp>& operator*=(const _Tp&); + valarray<_Tp>& operator/=(const _Tp&); + valarray<_Tp>& operator%=(const _Tp&); + valarray<_Tp>& operator+=(const _Tp&); + valarray<_Tp>& operator-=(const _Tp&); + valarray<_Tp>& operator^=(const _Tp&); + valarray<_Tp>& operator&=(const _Tp&); + valarray<_Tp>& operator|=(const _Tp&); valarray<_Tp>& operator<<=(const _Tp&); valarray<_Tp>& operator>>=(const _Tp&); - valarray<_Tp>& operator*= (const valarray<_Tp>&); - valarray<_Tp>& operator/= (const valarray<_Tp>&); - valarray<_Tp>& operator%= (const valarray<_Tp>&); - valarray<_Tp>& operator+= (const valarray<_Tp>&); - valarray<_Tp>& operator-= (const valarray<_Tp>&); - valarray<_Tp>& operator^= (const valarray<_Tp>&); - valarray<_Tp>& operator|= (const valarray<_Tp>&); - valarray<_Tp>& operator&= (const valarray<_Tp>&); + valarray<_Tp>& operator*=(const valarray<_Tp>&); + valarray<_Tp>& operator/=(const valarray<_Tp>&); + valarray<_Tp>& operator%=(const valarray<_Tp>&); + valarray<_Tp>& operator+=(const valarray<_Tp>&); + valarray<_Tp>& operator-=(const valarray<_Tp>&); + valarray<_Tp>& operator^=(const valarray<_Tp>&); + valarray<_Tp>& operator|=(const valarray<_Tp>&); + valarray<_Tp>& operator&=(const valarray<_Tp>&); valarray<_Tp>& operator<<=(const valarray<_Tp>&); valarray<_Tp>& operator>>=(const valarray<_Tp>&); template<class _Dom> - valarray<_Tp>& operator*= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator*=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator/= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator/=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator%= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator%=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator+= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator+=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator-= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator-=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator^= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator^=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator|= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator|=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator&= (const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator&=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator<<=(const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator<<=(const _Expr<_Dom,_Tp>&); template<class _Dom> - valarray<_Tp>& operator>>=(const _Expr<_Dom,_Tp>&); + valarray<_Tp>& operator>>=(const _Expr<_Dom,_Tp>&); + - // _lib.valarray.members_ member functions: size_t size() const; _Tp sum() const; _Tp min() const; _Tp max() const; -// // FIXME: Extension -// _Tp product () const; + // // FIXME: Extension + // _Tp product () const; valarray<_Tp> shift (int) const; valarray<_Tp> cshift(int) const; @@ -205,56 +211,25 @@ namespace std _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(const _Tp&)) const; void resize(size_t __size, _Tp __c = _Tp()); - private: + private: size_t _M_size; _Tp* __restrict__ _M_data; - + friend class _Array<_Tp>; - }; - - - template<typename _Tp> struct _Unary_plus : unary_function<_Tp,_Tp> { - _Tp operator() (const _Tp& __t) const { return __t; } - }; - - template<typename _Tp> struct _Bitwise_and : binary_function<_Tp,_Tp,_Tp> { - _Tp operator() (_Tp __x, _Tp __y) const { return __x & __y; } - }; - - template<typename _Tp> struct _Bitwise_or : binary_function<_Tp,_Tp,_Tp> { - _Tp operator() (_Tp __x, _Tp __y) const { return __x | __y; } - }; - - template<typename _Tp> struct _Bitwise_xor : binary_function<_Tp,_Tp,_Tp> { - _Tp operator() (_Tp __x, _Tp __y) const { return __x ^ __y; } - }; - - template<typename _Tp> struct _Bitwise_not : unary_function<_Tp,_Tp> { - _Tp operator() (_Tp __t) const { return ~__t; } - }; - - template<typename _Tp> struct _Shift_left : unary_function<_Tp,_Tp> { - _Tp operator() (_Tp __x, _Tp __y) const { return __x << __y; } - }; - - template<typename _Tp> struct _Shift_right : unary_function<_Tp,_Tp> { - _Tp operator() (_Tp __x, _Tp __y) const { return __x >> __y; } - }; - + }; template<typename _Tp> - inline const _Tp& - valarray<_Tp>::operator[] (size_t __i) const - { return _M_data[__i]; } + inline const _Tp& + valarray<_Tp>::operator[](size_t __i) const + { return _M_data[__i]; } template<typename _Tp> - inline _Tp& - valarray<_Tp>::operator[] (size_t __i) - { return _M_data[__i]; } + inline _Tp& + valarray<_Tp>::operator[](size_t __i) + { return _M_data[__i]; } } // std:: -#include <bits/slice.h> #include <bits/slice_array.h> #include <bits/gslice.h> #include <bits/gslice_array.h> @@ -264,214 +239,227 @@ namespace std namespace std { template<typename _Tp> - inline valarray<_Tp>::valarray () : _M_size (0), _M_data (0) {} + inline + valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {} template<typename _Tp> - inline valarray<_Tp>::valarray (size_t __n) - : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) - { __valarray_default_construct(_M_data, _M_data + __n); } + inline + valarray<_Tp>::valarray(size_t __n) + : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) + { __valarray_default_construct(_M_data, _M_data + __n); } template<typename _Tp> - inline valarray<_Tp>::valarray (const _Tp& __t, size_t __n) - : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) - { __valarray_fill_construct (_M_data, _M_data + __n, __t); } + inline + valarray<_Tp>::valarray(const _Tp& __t, size_t __n) + : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) + { __valarray_fill_construct(_M_data, _M_data + __n, __t); } template<typename _Tp> - inline valarray<_Tp>::valarray (const _Tp* __restrict__ __p, size_t __n) - : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) - { __valarray_copy_construct (__p, __p + __n, _M_data); } + inline + valarray<_Tp>::valarray(const _Tp* __restrict__ __p, size_t __n) + : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n)) + { __valarray_copy_construct(__p, __p + __n, _M_data); } template<typename _Tp> - inline valarray<_Tp>::valarray (const valarray<_Tp>& __v) - : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size)) - { __valarray_copy_construct (__v._M_data, __v._M_data + _M_size, _M_data); } + inline + valarray<_Tp>::valarray(const valarray<_Tp>& __v) + : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size)) + { __valarray_copy_construct(__v._M_data, __v._M_data + _M_size, _M_data); } template<typename _Tp> - inline valarray<_Tp>::valarray (const slice_array<_Tp>& __sa) - : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz)) - { - __valarray_copy - (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data)); - } + inline + valarray<_Tp>::valarray(const slice_array<_Tp>& __sa) + : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz)) + { + __valarray_copy + (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data)); + } template<typename _Tp> - inline valarray<_Tp>::valarray (const gslice_array<_Tp>& __ga) - : _M_size(__ga._M_index.size()), - _M_data(__valarray_get_storage<_Tp>(_M_size)) - { - __valarray_copy - (__ga._M_array, _Array<size_t>(__ga._M_index), - _Array<_Tp>(_M_data), _M_size); - } + inline + valarray<_Tp>::valarray(const gslice_array<_Tp>& __ga) + : _M_size(__ga._M_index.size()), + _M_data(__valarray_get_storage<_Tp>(_M_size)) + { + __valarray_copy + (__ga._M_array, _Array<size_t>(__ga._M_index), + _Array<_Tp>(_M_data), _M_size); + } template<typename _Tp> - inline valarray<_Tp>::valarray (const mask_array<_Tp>& __ma) - : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz)) - { - __valarray_copy - (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size); - } + inline + valarray<_Tp>::valarray(const mask_array<_Tp>& __ma) + : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz)) + { + __valarray_copy + (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size); + } template<typename _Tp> - inline valarray<_Tp>::valarray (const indirect_array<_Tp>& __ia) - : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz)) - { - __valarray_copy - (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size); - } + inline + valarray<_Tp>::valarray(const indirect_array<_Tp>& __ia) + : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz)) + { + __valarray_copy + (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size); + } template<typename _Tp> template<class _Dom> - inline valarray<_Tp>::valarray (const _Expr<_Dom, _Tp>& __e) - : _M_size(__e.size ()), _M_data(__valarray_get_storage<_Tp>(_M_size)) - { __valarray_copy (__e, _M_size, _Array<_Tp>(_M_data)); } + inline + valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e) + : _M_size(__e.size()), _M_data(__valarray_get_storage<_Tp>(_M_size)) + { __valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); } template<typename _Tp> - inline valarray<_Tp>::~valarray () - { + inline + valarray<_Tp>::~valarray() + { __valarray_destroy_elements(_M_data, _M_data + _M_size); __valarray_release_memory(_M_data); - } + } template<typename _Tp> - inline valarray<_Tp>& - valarray<_Tp>::operator= (const valarray<_Tp>& __v) - { + inline valarray<_Tp>& + valarray<_Tp>::operator=(const valarray<_Tp>& __v) + { __valarray_copy(__v._M_data, _M_size, _M_data); return *this; - } + } template<typename _Tp> - inline valarray<_Tp>& - valarray<_Tp>::operator= (const _Tp& __t) - { - __valarray_fill (_M_data, _M_size, __t); + inline valarray<_Tp>& + valarray<_Tp>::operator=(const _Tp& __t) + { + __valarray_fill(_M_data, _M_size, __t); return *this; - } + } template<typename _Tp> - inline valarray<_Tp>& - valarray<_Tp>::operator= (const slice_array<_Tp>& __sa) - { - __valarray_copy (__sa._M_array, __sa._M_sz, - __sa._M_stride, _Array<_Tp>(_M_data)); + inline valarray<_Tp>& + valarray<_Tp>::operator=(const slice_array<_Tp>& __sa) + { + __valarray_copy(__sa._M_array, __sa._M_sz, + __sa._M_stride, _Array<_Tp>(_M_data)); return *this; - } + } template<typename _Tp> - inline valarray<_Tp>& - valarray<_Tp>::operator= (const gslice_array<_Tp>& __ga) - { - __valarray_copy (__ga._M_array, _Array<size_t>(__ga._M_index), - _Array<_Tp>(_M_data), _M_size); + inline valarray<_Tp>& + valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga) + { + __valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index), + _Array<_Tp>(_M_data), _M_size); return *this; - } + } template<typename _Tp> - inline valarray<_Tp>& - valarray<_Tp>::operator= (const mask_array<_Tp>& __ma) - { - __valarray_copy (__ma._M_array, __ma._M_mask, - _Array<_Tp>(_M_data), _M_size); + inline valarray<_Tp>& + valarray<_Tp>::operator=(const mask_array<_Tp>& __ma) + { + __valarray_copy(__ma._M_array, __ma._M_mask, + _Array<_Tp>(_M_data), _M_size); return *this; - } + } template<typename _Tp> - inline valarray<_Tp>& - valarray<_Tp>::operator= (const indirect_array<_Tp>& __ia) - { - __valarray_copy (__ia._M_array, __ia._M_index, - _Array<_Tp>(_M_data), _M_size); + inline valarray<_Tp>& + valarray<_Tp>::operator=(const indirect_array<_Tp>& __ia) + { + __valarray_copy(__ia._M_array, __ia._M_index, + _Array<_Tp>(_M_data), _M_size); return *this; - } + } template<typename _Tp> template<class _Dom> - inline valarray<_Tp>& - valarray<_Tp>::operator= (const _Expr<_Dom, _Tp>& __e) - { - __valarray_copy (__e, _M_size, _Array<_Tp>(_M_data)); - return *this; - } + inline valarray<_Tp>& + valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) + { + __valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); + return *this; + } template<typename _Tp> - inline _Expr<_SClos<_ValArray,_Tp>, _Tp> - valarray<_Tp>::operator[] (slice __s) const - { + inline _Expr<_SClos<_ValArray,_Tp>, _Tp> + valarray<_Tp>::operator[](slice __s) const + { typedef _SClos<_ValArray,_Tp> _Closure; - return _Expr<_Closure, _Tp> (_Closure (_Array<_Tp>(_M_data), __s)); - } + return _Expr<_Closure, _Tp>(_Closure (_Array<_Tp>(_M_data), __s)); + } template<typename _Tp> - inline slice_array<_Tp> - valarray<_Tp>::operator[] (slice __s) - { - return slice_array<_Tp> (_Array<_Tp>(_M_data), __s); - } + inline slice_array<_Tp> + valarray<_Tp>::operator[](slice __s) + { + return slice_array<_Tp>(_Array<_Tp>(_M_data), __s); + } template<typename _Tp> - inline _Expr<_GClos<_ValArray,_Tp>, _Tp> - valarray<_Tp>::operator[] (const gslice& __gs) const - { + inline _Expr<_GClos<_ValArray,_Tp>, _Tp> + valarray<_Tp>::operator[](const gslice& __gs) const + { typedef _GClos<_ValArray,_Tp> _Closure; return _Expr<_Closure, _Tp> - (_Closure (_Array<_Tp>(_M_data), __gs._M_index->_M_index)); - } + (_Closure(_Array<_Tp>(_M_data), __gs._M_index->_M_index)); + } template<typename _Tp> - inline gslice_array<_Tp> - valarray<_Tp>::operator[] (const gslice& __gs) - { + inline gslice_array<_Tp> + valarray<_Tp>::operator[](const gslice& __gs) + { return gslice_array<_Tp> - (_Array<_Tp>(_M_data), __gs._M_index->_M_index); - } + (_Array<_Tp>(_M_data), __gs._M_index->_M_index); + } template<typename _Tp> - inline valarray<_Tp> - valarray<_Tp>::operator[] (const valarray<bool>& __m) const - { - size_t __s (0); - size_t __e (__m.size ()); + inline valarray<_Tp> + valarray<_Tp>::operator[](const valarray<bool>& __m) const + { + size_t __s = 0; + size_t __e = __m.size(); for (size_t __i=0; __i<__e; ++__i) - if (__m[__i]) ++__s; - return valarray<_Tp> (mask_array<_Tp> (_Array<_Tp>(_M_data), __s, - _Array<bool> (__m))); - } + if (__m[__i]) ++__s; + return valarray<_Tp>(mask_array<_Tp>(_Array<_Tp>(_M_data), __s, + _Array<bool> (__m))); + } template<typename _Tp> - inline mask_array<_Tp> - valarray<_Tp>::operator[] (const valarray<bool>& __m) - { - size_t __s (0); - size_t __e (__m.size ()); + inline mask_array<_Tp> + valarray<_Tp>::operator[](const valarray<bool>& __m) + { + size_t __s = 0; + size_t __e = __m.size(); for (size_t __i=0; __i<__e; ++__i) - if (__m[__i]) ++__s; - return mask_array<_Tp> (_Array<_Tp>(_M_data), __s, _Array<bool> (__m)); - } + if (__m[__i]) ++__s; + return mask_array<_Tp>(_Array<_Tp>(_M_data), __s, _Array<bool>(__m)); + } template<typename _Tp> - inline _Expr<_IClos<_ValArray,_Tp>, _Tp> - valarray<_Tp>::operator[] (const valarray<size_t>& __i) const - { + inline _Expr<_IClos<_ValArray,_Tp>, _Tp> + valarray<_Tp>::operator[](const valarray<size_t>& __i) const + { typedef _IClos<_ValArray,_Tp> _Closure; - return _Expr<_Closure, _Tp> (_Closure (*this, __i)); - } + return _Expr<_Closure, _Tp>(_Closure(*this, __i)); + } template<typename _Tp> - inline indirect_array<_Tp> - valarray<_Tp>::operator[] (const valarray<size_t>& __i) - { - return indirect_array<_Tp> (_Array<_Tp>(_M_data), __i.size(), - _Array<size_t> (__i)); - } + inline indirect_array<_Tp> + valarray<_Tp>::operator[](const valarray<size_t>& __i) + { + return indirect_array<_Tp>(_Array<_Tp>(_M_data), __i.size(), + _Array<size_t>(__i)); + } template<class _Tp> - inline size_t valarray<_Tp>::size () const { return _M_size; } + inline size_t + valarray<_Tp>::size() const + { return _M_size; } template<class _Tp> - inline _Tp - valarray<_Tp>::sum () const - { + inline _Tp + valarray<_Tp>::sum() const + { return __valarray_sum(_M_data, _M_data + _M_size); - } + } // template<typename _Tp> // inline _Tp @@ -530,209 +518,172 @@ namespace std } template <class _Tp> - inline void - valarray<_Tp>::resize (size_t __n, _Tp __c) - { - // This complication is so to make valarray<valarray<T> > work - // even though it is not required by the standard. Nobody should - // be saying valarray<valarray<T> > anyway. See the specs. - __valarray_destroy_elements(_M_data, _M_data + _M_size); - if (_M_size != __n) - { - __valarray_release_memory(_M_data); - _M_size = __n; - _M_data = __valarray_get_storage<_Tp>(__n); - } - __valarray_fill_construct(_M_data, _M_data + __n, __c); - } + inline void + valarray<_Tp>::resize (size_t __n, _Tp __c) + { + // This complication is so to make valarray<valarray<T> > work + // even though it is not required by the standard. Nobody should + // be saying valarray<valarray<T> > anyway. See the specs. + __valarray_destroy_elements(_M_data, _M_data + _M_size); + if (_M_size != __n) + { + __valarray_release_memory(_M_data); + _M_size = __n; + _M_data = __valarray_get_storage<_Tp>(__n); + } + __valarray_fill_construct(_M_data, _M_data + __n, __c); + } template<typename _Tp> - inline _Tp - valarray<_Tp>::min() const - { + inline _Tp + valarray<_Tp>::min() const + { return *min_element (_M_data, _M_data+_M_size); - } + } template<typename _Tp> - inline _Tp - valarray<_Tp>::max() const - { + inline _Tp + valarray<_Tp>::max() const + { return *max_element (_M_data, _M_data+_M_size); - } + } template<class _Tp> - inline _Expr<_ValFunClos<_ValArray,_Tp>,_Tp> - valarray<_Tp>::apply (_Tp func (_Tp)) const - { + inline _Expr<_ValFunClos<_ValArray,_Tp>,_Tp> + valarray<_Tp>::apply(_Tp func(_Tp)) const + { typedef _ValFunClos<_ValArray,_Tp> _Closure; - return _Expr<_Closure,_Tp> (_Closure (*this, func)); - } + return _Expr<_Closure,_Tp>(_Closure(*this, func)); + } template<class _Tp> - inline _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> - valarray<_Tp>::apply (_Tp func (const _Tp &)) const - { + inline _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> + valarray<_Tp>::apply(_Tp func(const _Tp &)) const + { typedef _RefFunClos<_ValArray,_Tp> _Closure; - return _Expr<_Closure,_Tp> (_Closure (*this, func)); - } + return _Expr<_Closure,_Tp>(_Closure(*this, func)); + } #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \ template<typename _Tp> \ - inline _Expr<_UnClos<_Name,_ValArray,_Tp>, _Tp> \ + inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt \ valarray<_Tp>::operator _Op() const \ { \ - typedef _UnClos<_Name,_ValArray,_Tp> _Closure; \ - return _Expr<_Closure, _Tp> (_Closure (*this)); \ + typedef _UnClos<_Name,_ValArray,_Tp> _Closure; \ + typedef typename __fun<_Name, _Tp>::result_type _Rt; \ + return _Expr<_Closure, _Rt>(_Closure(*this)); \ } - _DEFINE_VALARRAY_UNARY_OPERATOR(+, _Unary_plus) - _DEFINE_VALARRAY_UNARY_OPERATOR(-, negate) - _DEFINE_VALARRAY_UNARY_OPERATOR(~, _Bitwise_not) + _DEFINE_VALARRAY_UNARY_OPERATOR(+, __unary_plus) + _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate) + _DEFINE_VALARRAY_UNARY_OPERATOR(~, __bitwise_not) + _DEFINE_VALARRAY_UNARY_OPERATOR (!, __logical_not) #undef _DEFINE_VALARRAY_UNARY_OPERATOR - - template<typename _Tp> - inline _Expr<_UnClos<logical_not,_ValArray,_Tp>, bool> - valarray<_Tp>::operator!() const - { - typedef _UnClos<logical_not,_ValArray,_Tp> _Closure; - return _Expr<_Closure, bool> (_Closure (*this)); - } #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \ template<class _Tp> \ - inline valarray<_Tp> & \ - valarray<_Tp>::operator _Op##= (const _Tp &__t) \ - { \ - _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, __t); \ + inline valarray<_Tp>& \ + valarray<_Tp>::operator _Op##=(const _Tp &__t) \ + { \ + _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \ return *this; \ - } \ + } \ \ template<class _Tp> \ - inline valarray<_Tp> & \ - valarray<_Tp>::operator _Op##= (const valarray<_Tp> &__v) \ - { \ - _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, \ - _Array<_Tp>(__v._M_data)); \ + inline valarray<_Tp>& \ + valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \ + { \ + _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \ + _Array<_Tp>(__v._M_data)); \ return *this; \ - } - -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, plus) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, minus) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, multiplies) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, divides) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, modulus) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, xor) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, and) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, or) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, shift_left) -_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, shift_right) + } + +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left) +_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right) #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT - -} // std:: - - -namespace std -{ - #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \ template<class _Tp> template<class _Dom> \ - inline valarray<_Tp> & \ - valarray<_Tp>::operator _Op##= (const _Expr<_Dom,_Tp> &__e) \ - { \ - _Array_augmented_##_Name (_Array<_Tp>(_M_data), __e, _M_size); \ + inline valarray<_Tp>& \ + valarray<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) \ + { \ + _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \ return *this; \ - } - -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, plus) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, minus) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, multiplies) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, divides) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, modulus) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, xor) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, and) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, or) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, shift_left) -_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, shift_right) + } + +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left) +_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right) #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \ template<typename _Tp> \ - inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \ - operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \ - { \ + inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, \ + typename __fun<_Name, _Tp>::result_type> \ + operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \ + { \ typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \ - return _Expr<_Closure, _Tp> (_Closure (__v, __w)); \ - } \ + typedef typename __fun<_Name, _Tp>::result_type _Rt; \ + return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \ + } \ \ template<typename _Tp> \ - inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \ - operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \ + inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>, \ + typename __fun<_Name, _Tp>::result_type> \ + operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \ { \ - typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \ - return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \ + typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \ + typedef typename __fun<_Name, _Tp>::result_type _Rt; \ + return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \ } \ \ template<typename _Tp> \ - inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,_Tp> \ - operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \ - { \ - typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \ - return _Expr<_Closure, _Tp> (_Closure (__t, __v)); \ - } - -_DEFINE_BINARY_OPERATOR(+, plus) -_DEFINE_BINARY_OPERATOR(-, minus) -_DEFINE_BINARY_OPERATOR(*, multiplies) -_DEFINE_BINARY_OPERATOR(/, divides) -_DEFINE_BINARY_OPERATOR(%, modulus) -_DEFINE_BINARY_OPERATOR(^, _Bitwise_xor) -_DEFINE_BINARY_OPERATOR(&, _Bitwise_and) -_DEFINE_BINARY_OPERATOR(|, _Bitwise_or) -_DEFINE_BINARY_OPERATOR(<<, _Shift_left) -_DEFINE_BINARY_OPERATOR(>>, _Shift_right) - -#undef _DEFINE_BINARY_OPERATOR - -#define _DEFINE_LOGICAL_OPERATOR(_Op, _Name) \ - template<typename _Tp> \ - inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>,bool> \ - operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \ - { \ - typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \ - return _Expr<_Closure, bool> (_Closure (__v, __w)); \ - } \ - \ - template<class _Tp> \ - inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,bool> \ - operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \ + inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>, \ + typename __fun<_Name, _Tp>::result_type> \ + operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \ { \ - typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \ - return _Expr<_Closure, bool> (_Closure (__v, __t)); \ - } \ - \ - template<class _Tp> \ - inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,bool> \ - operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \ - { \ - typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \ - return _Expr<_Closure, bool> (_Closure (__t, __v)); \ - } - -_DEFINE_LOGICAL_OPERATOR(&&, logical_and) -_DEFINE_LOGICAL_OPERATOR(||, logical_or) -_DEFINE_LOGICAL_OPERATOR(==, equal_to) -_DEFINE_LOGICAL_OPERATOR(!=, not_equal_to) -_DEFINE_LOGICAL_OPERATOR(<, less) -_DEFINE_LOGICAL_OPERATOR(>, greater) -_DEFINE_LOGICAL_OPERATOR(<=, less_equal) -_DEFINE_LOGICAL_OPERATOR(>=, greater_equal) - -#undef _DEFINE_LOGICAL_OPERATOR + typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \ + typedef typename __fun<_Name, _Tp>::result_type _Rt; \ + return _Expr<_Closure, _Tp>(_Closure(__t, __v)); \ + } + +_DEFINE_BINARY_OPERATOR(+, __plus) +_DEFINE_BINARY_OPERATOR(-, __minus) +_DEFINE_BINARY_OPERATOR(*, __multiplies) +_DEFINE_BINARY_OPERATOR(/, __divides) +_DEFINE_BINARY_OPERATOR(%, __modulus) +_DEFINE_BINARY_OPERATOR(^, __bitwise_xor) +_DEFINE_BINARY_OPERATOR(&, __bitwise_and) +_DEFINE_BINARY_OPERATOR(|, __bitwise_or) +_DEFINE_BINARY_OPERATOR(<<, __shift_left) +_DEFINE_BINARY_OPERATOR(>>, __shift_right) +_DEFINE_BINARY_OPERATOR(&&, __logical_and) +_DEFINE_BINARY_OPERATOR(||, __logical_or) +_DEFINE_BINARY_OPERATOR(==, __equal_to) +_DEFINE_BINARY_OPERATOR(!=, __not_equal_to) +_DEFINE_BINARY_OPERATOR(<, __less) +_DEFINE_BINARY_OPERATOR(>, __greater) +_DEFINE_BINARY_OPERATOR(<=, __less_equal) +_DEFINE_BINARY_OPERATOR(>=, __greater_equal) } // namespace std |