Commit e3b4d2e9 by Gabriel Dos Reis Committed by Gabriel Dos Reis

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
parent f5c97924
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> 2000-08-17 Mark Mitchell <mark@codesourcery.com>
* bits/localefwd.h (std::locale): Use explicit `class' specified * bits/localefwd.h (std::locale): Use explicit `class' specified
......
...@@ -293,7 +293,39 @@ namespace std ...@@ -293,7 +293,39 @@ namespace std
while (__f != __l) __r = __r * *__f++; while (__f != __l) __r = __r * *__f++;
return __r; 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. // Helper class _Array, first layer of valarray abstraction.
......
...@@ -669,6 +669,9 @@ namespace std { ...@@ -669,6 +669,9 @@ namespace std {
valarray<value_type> shift (int) const; valarray<value_type> shift (int) const;
valarray<value_type> cshift (int) const; valarray<value_type> cshift (int) const;
value_type min() const;
value_type max() const;
// _Meta<_ApplyFunctionWithValue<_Expr>, value_type> // _Meta<_ApplyFunctionWithValue<_Expr>, value_type>
// apply (value_type _M_func (value_type)) const; // apply (value_type _M_func (value_type)) const;
// _Meta<_ApplyFunctionWithConstRef<_Expr>, value_type> // _Meta<_ApplyFunctionWithConstRef<_Expr>, value_type>
...@@ -729,28 +732,16 @@ namespace std { ...@@ -729,28 +732,16 @@ namespace std {
return __s; return __s;
} }
} }
template<class _Dom, typename _Tp> template<class _Clos, typename _Tp>
inline _Tp inline _Tp
min (const _Expr<_Dom,_Tp>& __e) _Expr<_Clos, _Tp>::min() const
{ { return __valarray_min(_M_closure); }
size_t __s = __e.size ();
_Tp __m = __e[0]; template<class _Close, typename _Tp>
for (size_t __i=1; __i<__s; ++__i) inline _Tp
if (__m > __e[__i]) __m = __e[__i]; _Expr<_Clos, _Tp>::max() const
return __m; { return __valarray_max(_M_closure); }
}
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 _Dom, typename _Tp> template<class _Dom, typename _Tp>
inline _Expr<_UnClos<logical_not,_Expr,_Dom>, bool> inline _Expr<_UnClos<logical_not,_Expr,_Dom>, bool>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment