2
0
mirror of git://gcc.gnu.org/git/gcc.git synced 2024-12-22 16:09:56 +08:00

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
This commit is contained in:
Gabriel Dos Reis 2000-08-18 10:40:23 +00:00 committed by Gabriel Dos Reis
parent f5c979243f
commit e3b4d2e9a6
3 changed files with 52 additions and 22 deletions

View File

@ -1,3 +1,10 @@
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

View File

@ -293,7 +293,39 @@ namespace std
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.

View File

@ -669,6 +669,9 @@ namespace std {
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>
@ -729,28 +732,16 @@ namespace std {
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>