From e3b4d2e9a6291d9f483fca967c6c57ced98a59b2 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Fri, 18 Aug 2000 10:40:23 +0000 Subject: [PATCH] valarray_meta.h (_Expr<>::min, [...]): Implement. * bits/valarray_meta.h (_Expr<>::min, _Expr<>::max): Implement. * bits/valarray_array.h (__valarray_min, __valarray_max): New function. From-SVN: r35783 --- libstdc++-v3/ChangeLog | 7 ++++++ libstdc++-v3/bits/valarray_array.h | 32 +++++++++++++++++++++++++++ libstdc++-v3/bits/valarray_meta.h | 35 +++++++++++------------------- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d104533fb3f..829722b7a1a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2000-08-18 Gabriel Dos Reis + + * bits/valarray_meta.h (_Expr<>::min, _Expr<>::max): Implement. + + * bits/valarray_array.h (__valarray_min, __valarray_max): New + function. + 2000-08-17 Mark Mitchell * bits/localefwd.h (std::locale): Use explicit `class' specified diff --git a/libstdc++-v3/bits/valarray_array.h b/libstdc++-v3/bits/valarray_array.h index 4eb2eb868dd..de8a3bf20aa 100644 --- a/libstdc++-v3/bits/valarray_array.h +++ b/libstdc++-v3/bits/valarray_array.h @@ -293,7 +293,39 @@ namespace std while (__f != __l) __r = __r * *__f++; return __r; } + + // Compute the min/max of an array-expression + template + inline typename _Ta::value_array + __valarray_min(const _Ta& __a) + { + size_t __s = __a.size(); + typedef typename _Ta::value_type _Value_type; + _Value_type __r = __s == 0 ? _Value_type() : __a[0]; + for (size_t __i = 1; __i < __s; ++__i) + { + _Value_type __t = __a[__i]; + if (__t < __r) + __r = __t; + } + return __r; + } + template + inline typename _Ta::value_array + __valarray_max(const _Ta& __a) + { + size_t __s = __a.size(); + typedef typename _Ta::value_type _Value_type; + _Value_type __r = __s == 0 ? _Value_type() : __a[0]; + for (size_t __i = 1; __i < __s; ++__i) + { + _Value_type __t = __a[__i]; + if (__t > __r) + __r = __t; + } + return __r; + } // // Helper class _Array, first layer of valarray abstraction. diff --git a/libstdc++-v3/bits/valarray_meta.h b/libstdc++-v3/bits/valarray_meta.h index c203d421e05..f52ddbfd2f5 100644 --- a/libstdc++-v3/bits/valarray_meta.h +++ b/libstdc++-v3/bits/valarray_meta.h @@ -669,6 +669,9 @@ namespace std { valarray shift (int) const; valarray cshift (int) const; + + value_type min() const; + value_type max() const; // _Meta<_ApplyFunctionWithValue<_Expr>, value_type> // apply (value_type _M_func (value_type)) const; // _Meta<_ApplyFunctionWithConstRef<_Expr>, value_type> @@ -729,28 +732,16 @@ namespace std { return __s; } } - - template - inline _Tp - min (const _Expr<_Dom,_Tp>& __e) - { - size_t __s = __e.size (); - _Tp __m = __e[0]; - for (size_t __i=1; __i<__s; ++__i) - if (__m > __e[__i]) __m = __e[__i]; - return __m; - } - - template - inline _Tp - max (const _Expr<_Dom,_Tp>& __e) - { - size_t __s = __e.size(); - _Tp __m = __e[0]; - for (size_t __i=1; __i<__s; ++__i) - if (__m < __e[__i]) __m = __e[__i]; - return __m; - } + + template + inline _Tp + _Expr<_Clos, _Tp>::min() const + { return __valarray_min(_M_closure); } + + template + inline _Tp + _Expr<_Clos, _Tp>::max() const + { return __valarray_max(_M_closure); } template inline _Expr<_UnClos, bool>