+2000-08-18 Gabriel Dos Reis <gdr@codesourcery.com>
+
+ * bits/valarray_meta.h (_Expr<>::min, _Expr<>::max): Implement.
+
+ * bits/valarray_array.h (__valarray_min, __valarray_max): New
+ function.
+
2000-08-17 Mark Mitchell <mark@codesourcery.com>
* bits/localefwd.h (std::locale): Use explicit `class' specified
while (__f != __l) __r = __r * *__f++;
return __r;
}
+
+ // Compute the min/max of an array-expression
+ template<typename _Ta>
+ 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<typename _Ta>
+ 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.
valarray<value_type> shift (int) const;
valarray<value_type> 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>
return __s;
}
}
-
- template<class _Dom, typename _Tp>
- 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<class _Dom, typename _Tp>
- 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<class _Clos, typename _Tp>
+ inline _Tp
+ _Expr<_Clos, _Tp>::min() const
+ { return __valarray_min(_M_closure); }
+
+ template<class _Close, typename _Tp>
+ inline _Tp
+ _Expr<_Clos, _Tp>::max() const
+ { return __valarray_max(_M_closure); }
template<class _Dom, typename _Tp>
inline _Expr<_UnClos<logical_not,_Expr,_Dom>, bool>