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>