Commit 971cfc6f by Gabriel Dos Reis Committed by Gabriel Dos Reis

valarray_array.h (_DEFINE_ARRAY_FUNCTION): Use our object function surrogates.

	* include/bits/valarray_array.h (_DEFINE_ARRAY_FUNCTION): Use our
	object function surrogates.
	* include/bits/valarray_meta.h (__shift_left): Fix typo.
	(_BinFunClos<>): Remove.
	(_BinFunBase<>): Likewise.
	(_BinFunBase1<>):Likewise.
	(_BinFunBase2<>): Likewise.
	(_DEFINE_EXPR_RELATIONAL_OPERATOR): Likewise.
	(_DEFINE_EXPR_UNARY_OPERATOR): Adjust definition.
	(_DEFINE_EXPR_BINARY_OPERATOR): Likewise.
	(_DEFINE_EXPR_BINARY_FUNCTION): Likewise.
	* include/std/std_valarray.h: Dont #include <functional> anymore.
	(_Bitwise_or<>, _Bitwise_and<>, _Bitwise_xor<>, _Shift_left<>,
	_Shift_right<>): Remove.
	(_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT): Adjust instantiation.
	(_DEFINE_BINARY_OPERATOR): Tweak definition.
	(_DEFINE_LOGICAL_OPERATOR): Remove.
	* testsuite/26_numerics/valarray_name_lookup.C (main): Add more tests.

From-SVN: r56001
parent 55765de4
2002-08-03 Gabriel Dos Reis <gdr@nerim.net>
* include/bits/valarray_array.h (_DEFINE_ARRAY_FUNCTION): Use our
object function surrogates.
* include/bits/valarray_meta.h (__shift_left): Fix typo.
(_BinFunClos<>): Remove.
(_BinFunBase<>): Likewise.
(_BinFunBase1<>):Likewise.
(_BinFunBase2<>): Likewise.
(_DEFINE_EXPR_RELATIONAL_OPERATOR): Likewise.
(_DEFINE_EXPR_UNARY_OPERATOR): Adjust definition.
(_DEFINE_EXPR_BINARY_OPERATOR): Likewise.
(_DEFINE_EXPR_BINARY_FUNCTION): Likewise.
* include/std/std_valarray.h: Dont #include <functional> anymore.
(_Bitwise_or<>, _Bitwise_and<>, _Bitwise_xor<>, _Shift_left<>,
_Shift_right<>): Remove.
(_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT): Adjust instantiation.
(_DEFINE_BINARY_OPERATOR): Tweak definition.
(_DEFINE_LOGICAL_OPERATOR): Remove.
* testsuite/26_numerics/valarray_name_lookup.C (main): Add more tests.
2002-08-02 Gabriel Dos Reis <gdr@nerim.net> 2002-08-02 Gabriel Dos Reis <gdr@nerim.net>
* include/bits/valarray_meta.h (_UnFunBase<>): Remove. * include/bits/valarray_meta.h (_UnFunBase<>): Remove.
......
...@@ -603,16 +603,16 @@ _Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \ ...@@ -603,16 +603,16 @@ _Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \
} \ } \
} }
_DEFINE_ARRAY_FUNCTION(+, plus) _DEFINE_ARRAY_FUNCTION(+, __plus)
_DEFINE_ARRAY_FUNCTION(-, minus) _DEFINE_ARRAY_FUNCTION(-, __minus)
_DEFINE_ARRAY_FUNCTION(*, multiplies) _DEFINE_ARRAY_FUNCTION(*, __multiplies)
_DEFINE_ARRAY_FUNCTION(/, divides) _DEFINE_ARRAY_FUNCTION(/, __divides)
_DEFINE_ARRAY_FUNCTION(%, modulus) _DEFINE_ARRAY_FUNCTION(%, __modulus)
_DEFINE_ARRAY_FUNCTION(^, xor) _DEFINE_ARRAY_FUNCTION(^, __bitwise_xor)
_DEFINE_ARRAY_FUNCTION(|, or) _DEFINE_ARRAY_FUNCTION(|, __bitwise_or)
_DEFINE_ARRAY_FUNCTION(&, and) _DEFINE_ARRAY_FUNCTION(&, __bitwise_and)
_DEFINE_ARRAY_FUNCTION(<<, shift_left) _DEFINE_ARRAY_FUNCTION(<<, __shift_left)
_DEFINE_ARRAY_FUNCTION(>>, shift_right) _DEFINE_ARRAY_FUNCTION(>>, __shift_right)
#undef _DEFINE_VALARRAY_FUNCTION #undef _DEFINE_VALARRAY_FUNCTION
......
...@@ -50,7 +50,6 @@ namespace std ...@@ -50,7 +50,6 @@ namespace std
// template nesting due to _Expr<> // template nesting due to _Expr<>
// //
// This class is NOT defined. It doesn't need to. // This class is NOT defined. It doesn't need to.
template<typename _Tp1, typename _Tp2> class _Constant; template<typename _Tp1, typename _Tp2> class _Constant;
...@@ -224,7 +223,7 @@ namespace std ...@@ -224,7 +223,7 @@ namespace std
{ return __x | __y; } { return __x | __y; }
}; };
struct __shift__left struct __shift_left
{ {
template<typename _Tp> template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const _Tp operator()(const _Tp& __x, const _Tp& __y) const
...@@ -381,221 +380,72 @@ namespace std ...@@ -381,221 +380,72 @@ namespace std
}; };
// //
// Binary function application closure.
//
template<template<class, class> class _Meta1,
template<class, class> class Meta2,
class _Dom1, class _Dom2> class _BinFunClos;
template<class _Dom1, class _Dom2> class _BinFunBase {
public:
typedef typename _Dom1::value_type value_type;
typedef value_type _Vt;
_BinFunBase (const _Dom1& __e1, const _Dom2& __e2,
_Vt __f (_Vt, _Vt))
: _M_expr1 (__e1), _M_expr2 (__e2), _M_func (__f) {}
value_type operator[] (size_t __i) const
{ return _M_func (_M_expr1[__i], _M_expr2[__i]); }
size_t size () const { return _M_expr1.size (); }
private:
const _Dom1& _M_expr1;
const _Dom2& _M_expr2;
_Vt (*_M_func)(_Vt, _Vt);
};
template<class _Dom> class _BinFunBase1 {
public:
typedef typename _Dom::value_type value_type ;
typedef value_type _Vt;
_BinFunBase1 (const _Vt& __c, const _Dom& __e, _Vt __f(_Vt, _Vt))
: _M_expr1 (__c), _M_expr2 (__e), _M_func (__f) {}
value_type operator[] (size_t __i) const
{ return _M_func (_M_expr1, _M_expr2[__i]); }
size_t size () const { return _M_expr2.size (); }
private:
const _Vt& _M_expr1;
const _Dom& _M_expr2;
_Vt (*_M_func)(_Vt, _Vt);
};
template<class _Dom> class _BinFunBase2 {
public:
typedef typename _Dom::value_type value_type;
typedef value_type _Vt;
_BinFunBase2 (const _Dom& __e, const _Vt& __c, _Vt __f(_Vt, _Vt))
: _M_expr1 (__e), _M_expr2 (__c), _M_func (__f) {}
value_type operator[] (size_t __i) const
{ return _M_func (_M_expr1[__i], _M_expr2); }
size_t size () const { return _M_expr1.size (); }
private:
const _Dom& _M_expr1;
const _Vt& _M_expr2;
_Vt (*_M_func)(_Vt, _Vt);
};
template<class _Dom1, class _Dom2>
struct _BinFunClos<_Expr,_Expr,_Dom1,_Dom2> : _BinFunBase<_Dom1,_Dom2> {
typedef _BinFunBase<_Dom1,_Dom2> _Base;
typedef typename _Base::value_type value_type;
typedef value_type _Tp;
_BinFunClos (const _Dom1& __e1, const _Dom2& __e2,
_Tp __f(_Tp, _Tp))
: _Base (__e1, __e2, __f) {}
};
template<typename _Tp>
struct _BinFunClos<_ValArray,_ValArray,_Tp,_Tp>
: _BinFunBase<valarray<_Tp>, valarray<_Tp> > {
typedef _BinFunBase<valarray<_Tp>, valarray<_Tp> > _Base;
typedef _Tp value_type;
_BinFunClos (const valarray<_Tp>& __v, const valarray<_Tp>& __w,
_Tp __f(_Tp, _Tp))
: _Base (__v, __w, __f) {}
};
template<class _Dom>
struct _BinFunClos<_Expr,_ValArray,_Dom,typename _Dom::value_type>
: _BinFunBase<_Dom,valarray<typename _Dom::value_type> > {
typedef typename _Dom::value_type _Tp;
typedef _BinFunBase<_Dom,valarray<_Tp> > _Base;
typedef _Tp value_type;
_BinFunClos (const _Dom& __e, const valarray<_Tp>& __v,
_Tp __f(_Tp, _Tp))
: _Base (__e, __v, __f) {}
};
template<class _Dom>
struct _BinFunClos<_ValArray,_Expr,typename _Dom::value_type,_Dom>
: _BinFunBase<valarray<typename _Dom::value_type>,_Dom> {
typedef typename _Dom::value_type _Tp;
typedef _BinFunBase<_Dom,valarray<_Tp> > _Base;
typedef _Tp value_type;
_BinFunClos (const valarray<_Tp>& __v, const _Dom& __e,
_Tp __f(_Tp, _Tp))
: _Base (__v, __e, __f) {}
};
template<class _Dom>
struct _BinFunClos<_Expr,_Constant,_Dom,typename _Dom::value_type>
: _BinFunBase2<_Dom> {
typedef typename _Dom::value_type _Tp;
typedef _Tp value_type;
typedef _BinFunBase2<_Dom> _Base;
_BinFunClos (const _Dom& __e, const _Tp& __t, _Tp __f (_Tp, _Tp))
: _Base (__e, __t, __f) {}
};
template<class _Dom>
struct _BinFunClos<_Constant,_Expr,_Dom,typename _Dom::value_type>
: _BinFunBase1<_Dom> {
typedef typename _Dom::value_type _Tp;
typedef _Tp value_type;
typedef _BinFunBase1<_Dom> _Base;
_BinFunClos (const _Tp& __t, const _Dom& __e, _Tp __f (_Tp, _Tp))
: _Base (__t, __e, __f) {}
};
template<typename _Tp>
struct _BinFunClos<_ValArray,_Constant,_Tp,_Tp>
: _BinFunBase2<valarray<_Tp> > {
typedef _BinFunBase2<valarray<_Tp> > _Base;
typedef _Tp value_type;
_BinFunClos (const valarray<_Tp>& __v, const _Tp& __t,
_Tp __f(_Tp, _Tp))
: _Base (__v, __t, __f) {}
};
template<typename _Tp>
struct _BinFunClos<_Constant,_ValArray,_Tp,_Tp>
: _BinFunBase1<valarray<_Tp> > {
typedef _BinFunBase1<valarray<_Tp> > _Base;
typedef _Tp value_type;
_BinFunClos (const _Tp& __t, const valarray<_Tp>& __v,
_Tp __f (_Tp, _Tp))
: _Base (__t, __v, __f) {}
};
//
// Apply function taking a value/const reference closure // Apply function taking a value/const reference closure
// //
template<typename _Dom, typename _Arg> class _FunBase { template<typename _Dom, typename _Arg>
class _FunBase
{
public: public:
typedef typename _Dom::value_type value_type; typedef typename _Dom::value_type value_type;
_FunBase(const _Dom& __e, value_type __f(_Arg))
: _M_expr(__e), _M_func(__f) {}
_FunBase (const _Dom& __e, value_type __f(_Arg)) value_type operator[](size_t __i) const
: _M_expr (__e), _M_func (__f) {} { return _M_func (_M_expr[__i]); }
value_type operator[] (size_t __i) const size_t size() const { return _M_expr.size ();}
{ return _M_func (_M_expr[__i]); }
size_t size() const { return _M_expr.size ();}
private: private:
const _Dom& _M_expr; const _Dom& _M_expr;
value_type (*_M_func)(_Arg); value_type (*_M_func)(_Arg);
}; };
template<class _Dom> template<class _Dom>
struct _ValFunClos<_Expr,_Dom> struct _ValFunClos<_Expr,_Dom> : _FunBase<_Dom, typename _Dom::value_type>
: _FunBase<_Dom, typename _Dom::value_type> { {
typedef _FunBase<_Dom, typename _Dom::value_type> _Base; typedef _FunBase<_Dom, typename _Dom::value_type> _Base;
typedef typename _Base::value_type value_type; typedef typename _Base::value_type value_type;
typedef value_type _Tp; typedef value_type _Tp;
_ValFunClos (const _Dom& __e, _Tp __f (_Tp)) : _Base (__e, __f) {} _ValFunClos(const _Dom& __e, _Tp __f(_Tp)) : _Base(__e, __f) {}
}; };
template<typename _Tp> template<typename _Tp>
struct _ValFunClos<_ValArray,_Tp> struct _ValFunClos<_ValArray,_Tp> : _FunBase<valarray<_Tp>, _Tp>
: _FunBase<valarray<_Tp>, _Tp> { {
typedef _FunBase<valarray<_Tp>, _Tp> _Base; typedef _FunBase<valarray<_Tp>, _Tp> _Base;
typedef _Tp value_type; typedef _Tp value_type;
_ValFunClos (const valarray<_Tp>& __v, _Tp __f(_Tp)) _ValFunClos(const valarray<_Tp>& __v, _Tp __f(_Tp)) : _Base(__v, __f) {}
: _Base (__v, __f) {}
}; };
template<class _Dom> template<class _Dom>
struct _RefFunClos<_Expr,_Dom> : struct _RefFunClos<_Expr,_Dom> :
_FunBase<_Dom, const typename _Dom::value_type&> { _FunBase<_Dom, const typename _Dom::value_type&>
typedef _FunBase<_Dom, const typename _Dom::value_type&> _Base; {
typedef typename _Base::value_type value_type; typedef _FunBase<_Dom, const typename _Dom::value_type&> _Base;
typedef value_type _Tp; typedef typename _Base::value_type value_type;
typedef value_type _Tp;
_RefFunClos (const _Dom& __e, _Tp __f (const _Tp&))
: _Base (__e, __f) {} _RefFunClos(const _Dom& __e, _Tp __f(const _Tp&))
: _Base(__e, __f) {}
}; };
template<typename _Tp> template<typename _Tp>
struct _RefFunClos<_ValArray,_Tp> struct _RefFunClos<_ValArray,_Tp> : _FunBase<valarray<_Tp>, const _Tp&>
: _FunBase<valarray<_Tp>, const _Tp&> { {
typedef _FunBase<valarray<_Tp>, const _Tp&> _Base; typedef _FunBase<valarray<_Tp>, const _Tp&> _Base;
typedef _Tp value_type; typedef _Tp value_type;
_RefFunClos (const valarray<_Tp>& __v, _Tp __f(const _Tp&)) _RefFunClos(const valarray<_Tp>& __v, _Tp __f(const _Tp&))
: _Base (__v, __f) {} : _Base(__v, __f) {}
}; };
// //
// Unary expression closure. // Unary expression closure.
// //
template<class _Oper, class _Arg> template<class _Oper, class _Arg>
class _UnBase class _UnBase
...@@ -636,160 +486,156 @@ namespace std ...@@ -636,160 +486,156 @@ namespace std
}; };
// //
// Binary expression closure. // Binary expression closure.
// //
template<template<class> class _Oper, template<class _Oper, class _FirstArg, class _SecondArg>
typename _FirstArg, typename _SecondArg> class _BinBase
class _BinBase { {
public: public:
typedef _Oper<typename _FirstArg::value_type> _Op; typedef typename _FirstArg::value_type _Vt;
typedef typename _Op::result_type value_type; typedef typename __fun<_Oper, _Vt>::result_type value_type;
_BinBase (const _FirstArg& __e1, const _SecondArg& __e2) _BinBase(const _FirstArg& __e1, const _SecondArg& __e2)
: _M_expr1 (__e1), _M_expr2 (__e2) {} : _M_expr1(__e1), _M_expr2(__e2) {}
value_type operator[] (size_t) const;
size_t size () const { return _M_expr1.size (); } value_type operator[](size_t __i) const
{ return _Oper()(_M_expr1[__i], _M_expr2[__i]); }
size_t size() const { return _M_expr1.size(); }
private: private:
const _FirstArg& _M_expr1; const _FirstArg& _M_expr1;
const _SecondArg& _M_expr2; const _SecondArg& _M_expr2;
}; };
template<template<class> class _Oper,
typename _FirstArg, typename _SecondArg>
inline typename _BinBase<_Oper,_FirstArg,_SecondArg>::value_type
_BinBase<_Oper,_FirstArg,_SecondArg>::operator[] (size_t __i) const
{ return _Op() (_M_expr1[__i], _M_expr2[__i]); }
template<template<class> class _Oper, class _Clos> template<class _Oper, class _Clos>
class _BinBase2 { class _BinBase2
{
public: public:
typedef typename _Clos::value_type _Vt; typedef typename _Clos::value_type _Vt;
typedef _Oper<_Vt> _Op; typedef typename __fun<_Oper, _Vt>::result_type value_type;
typedef typename _Op::result_type value_type;
_BinBase2 (const _Clos& __e, const _Vt& __t) _BinBase2(const _Clos& __e, const _Vt& __t)
: _M_expr1 (__e), _M_expr2 (__t) {} : _M_expr1(__e), _M_expr2(__t) {}
value_type operator[] (size_t) const;
size_t size () const { return _M_expr1.size (); }
private: value_type operator[](size_t __i) const
const _Clos& _M_expr1; { return _Oper()(_M_expr1[__i], _M_expr2); }
const _Vt& _M_expr2;
};
template<template<class> class _Oper, class _Clos> size_t size() const { return _M_expr1.size(); }
inline typename _BinBase2<_Oper,_Clos>::value_type
_BinBase2<_Oper,_Clos>::operator[] (size_t __i) const
{ return _Op() (_M_expr1[__i], _M_expr2); }
private:
const _Clos& _M_expr1;
const _Vt& _M_expr2;
};
template<template<class> class _Oper, class _Clos> template<class _Oper, class _Clos>
class _BinBase1 { class _BinBase1
{
public: public:
typedef typename _Clos::value_type _Vt; typedef typename _Clos::value_type _Vt;
typedef _Oper<_Vt> _Op; typedef typename __fun<_Oper, _Vt>::result_type value_type;
typedef typename _Op::result_type value_type;
_BinBase1(const _Vt& __t, const _Clos& __e)
: _M_expr1(__t), _M_expr2(__e) {}
_BinBase1 (const _Vt& __t, const _Clos& __e) value_type operator[](size_t __i) const
: _M_expr1 (__t), _M_expr2 (__e) {} { return _Oper()(_M_expr1, _M_expr2[__i]); }
value_type operator[] (size_t) const;
size_t size () const { return _M_expr2.size (); } size_t size() const { return _M_expr2.size(); }
private: private:
const _Vt& _M_expr1; const _Vt& _M_expr1;
const _Clos& _M_expr2; const _Clos& _M_expr2;
}; };
template<template<class> class _Oper, class _Clos>
inline typename
_BinBase1<_Oper,_Clos>::value_type
_BinBase1<_Oper,_Clos>:: operator[] (size_t __i) const
{ return _Op() (_M_expr1, _M_expr2[__i]); }
template<template<class> class _Oper, class _Dom1, class _Dom2> template<class _Oper, class _Dom1, class _Dom2>
struct _BinClos<_Oper, _Expr, _Expr, _Dom1, _Dom2> struct _BinClos<_Oper, _Expr, _Expr, _Dom1, _Dom2>
: _BinBase<_Oper,_Dom1,_Dom2> { : _BinBase<_Oper,_Dom1,_Dom2>
typedef _BinBase<_Oper,_Dom1,_Dom2> _Base; {
typedef typename _Base::value_type value_type; typedef _BinBase<_Oper,_Dom1,_Dom2> _Base;
typedef typename _Base::value_type value_type;
_BinClos(const _Dom1& __e1, const _Dom2& __e2) : _Base(__e1, __e2) {} _BinClos(const _Dom1& __e1, const _Dom2& __e2) : _Base(__e1, __e2) {}
}; };
template<template<class> class _Oper, typename _Tp> template<class _Oper, typename _Tp>
struct _BinClos<_Oper,_ValArray,_ValArray,_Tp,_Tp> struct _BinClos<_Oper,_ValArray,_ValArray,_Tp,_Tp>
: _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > { : _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> >
typedef _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > _Base; {
typedef _Tp value_type; typedef _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > _Base;
typedef _Tp value_type;
_BinClos (const valarray<_Tp>& __v, const valarray<_Tp>& __w) _BinClos(const valarray<_Tp>& __v, const valarray<_Tp>& __w)
: _Base (__v, __w) {} : _Base(__v, __w) {}
}; };
template<template<class> class _Oper, class _Dom> template<class _Oper, class _Dom>
struct _BinClos<_Oper,_Expr,_ValArray,_Dom,typename _Dom::value_type> struct _BinClos<_Oper,_Expr,_ValArray,_Dom,typename _Dom::value_type>
: _BinBase<_Oper,_Dom,valarray<typename _Dom::value_type> > { : _BinBase<_Oper,_Dom,valarray<typename _Dom::value_type> >
typedef typename _Dom::value_type _Tp; {
typedef _BinBase<_Oper,_Dom,valarray<_Tp> > _Base; typedef typename _Dom::value_type _Tp;
typedef typename _Base::value_type value_type; typedef _BinBase<_Oper,_Dom,valarray<_Tp> > _Base;
typedef typename _Base::value_type value_type;
_BinClos(const _Dom& __e1, const valarray<_Tp>& __e2)
: _Base (__e1, __e2) {} _BinClos(const _Dom& __e1, const valarray<_Tp>& __e2)
: _Base(__e1, __e2) {}
}; };
template<template<class> class _Oper, class _Dom> template<class _Oper, class _Dom>
struct _BinClos<_Oper,_ValArray,_Expr,typename _Dom::value_type,_Dom> struct _BinClos<_Oper,_ValArray,_Expr,typename _Dom::value_type,_Dom>
: _BinBase<_Oper,valarray<typename _Dom::value_type>,_Dom> { : _BinBase<_Oper,valarray<typename _Dom::value_type>,_Dom>
typedef typename _Dom::value_type _Tp; {
typedef _BinBase<_Oper,valarray<_Tp>,_Dom> _Base; typedef typename _Dom::value_type _Tp;
typedef typename _Base::value_type value_type; typedef _BinBase<_Oper,valarray<_Tp>,_Dom> _Base;
typedef typename _Base::value_type value_type;
_BinClos (const valarray<_Tp>& __e1, const _Dom& __e2)
: _Base (__e1, __e2) {} _BinClos(const valarray<_Tp>& __e1, const _Dom& __e2)
: _Base(__e1, __e2) {}
}; };
template<template<class> class _Oper, class _Dom> template<class _Oper, class _Dom>
struct _BinClos<_Oper,_Expr,_Constant,_Dom,typename _Dom::value_type> struct _BinClos<_Oper,_Expr,_Constant,_Dom,typename _Dom::value_type>
: _BinBase2<_Oper,_Dom> { : _BinBase2<_Oper,_Dom>
typedef typename _Dom::value_type _Tp; {
typedef _BinBase2<_Oper,_Dom> _Base; typedef typename _Dom::value_type _Tp;
typedef typename _Base::value_type value_type; typedef _BinBase2<_Oper,_Dom> _Base;
typedef typename _Base::value_type value_type;
_BinClos (const _Dom& __e1, const _Tp& __e2) : _Base (__e1, __e2) {}
_BinClos(const _Dom& __e1, const _Tp& __e2) : _Base(__e1, __e2) {}
}; };
template<template<class> class _Oper, class _Dom> template<class _Oper, class _Dom>
struct _BinClos<_Oper,_Constant,_Expr,typename _Dom::value_type,_Dom> struct _BinClos<_Oper,_Constant,_Expr,typename _Dom::value_type,_Dom>
: _BinBase1<_Oper,_Dom> { : _BinBase1<_Oper,_Dom>
typedef typename _Dom::value_type _Tp; {
typedef _BinBase1<_Oper,_Dom> _Base; typedef typename _Dom::value_type _Tp;
typedef typename _Base::value_type value_type; typedef _BinBase1<_Oper,_Dom> _Base;
typedef typename _Base::value_type value_type;
_BinClos (const _Tp& __e1, const _Dom& __e2) : _Base (__e1, __e2) {}
_BinClos(const _Tp& __e1, const _Dom& __e2) : _Base(__e1, __e2) {}
}; };
template<template<class> class _Oper, typename _Tp> template<class _Oper, typename _Tp>
struct _BinClos<_Oper,_ValArray,_Constant,_Tp,_Tp> struct _BinClos<_Oper,_ValArray,_Constant,_Tp,_Tp>
: _BinBase2<_Oper,valarray<_Tp> > { : _BinBase2<_Oper,valarray<_Tp> >
typedef _BinBase2<_Oper,valarray<_Tp> > _Base; {
typedef typename _Base::value_type value_type; typedef _BinBase2<_Oper,valarray<_Tp> > _Base;
typedef typename _Base::value_type value_type;
_BinClos (const valarray<_Tp>& __v, const _Tp& __t)
: _Base (__v, __t) {} _BinClos(const valarray<_Tp>& __v, const _Tp& __t) : _Base(__v, __t) {}
}; };
template<template<class> class _Oper, typename _Tp> template<class _Oper, typename _Tp>
struct _BinClos<_Oper,_Constant,_ValArray,_Tp,_Tp> struct _BinClos<_Oper,_Constant,_ValArray,_Tp,_Tp>
: _BinBase1<_Oper,valarray<_Tp> > { : _BinBase1<_Oper,valarray<_Tp> >
typedef _BinBase1<_Oper,valarray<_Tp> > _Base; {
typedef typename _Base::value_type value_type; typedef _BinBase1<_Oper,valarray<_Tp> > _Base;
typedef typename _Base::value_type value_type;
_BinClos (const _Tp& __t, const valarray<_Tp>& __v)
: _Base (__t, __v) {} _BinClos(const _Tp& __t, const valarray<_Tp>& __v) : _Base(__t, __v) {}
}; };
...@@ -1065,18 +911,18 @@ namespace std ...@@ -1065,18 +911,18 @@ namespace std
inline _Expr<_UnClos<__logical_not,_Expr,_Dom>, bool> inline _Expr<_UnClos<__logical_not,_Expr,_Dom>, bool>
_Expr<_Dom,_Tp>::operator!() const _Expr<_Dom,_Tp>::operator!() const
{ {
typedef _UnClos<__logical_not,std::_Expr,_Dom> _Closure; typedef _UnClos<__logical_not,std::_Expr,_Dom> _Closure;
return _Expr<_Closure,_Tp>(_Closure(this->_M_closure)); return _Expr<_Closure,_Tp>(_Closure(this->_M_closure));
} }
#define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \ #define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \
template<class _Dom, typename _Tp> \ template<class _Dom, typename _Tp> \
inline _Expr<_UnClos<_Name,std::_Expr,_Dom>,_Tp> \ inline _Expr<_UnClos<_Name,std::_Expr,_Dom>,_Tp> \
_Expr<_Dom,_Tp>::operator _Op() const \ _Expr<_Dom,_Tp>::operator _Op() const \
{ \ { \
typedef _UnClos<_Name,std::_Expr,_Dom> _Closure; \ typedef _UnClos<_Name,std::_Expr,_Dom> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(this->_M_closure)); \ return _Expr<_Closure,_Tp>(_Closure(this->_M_closure)); \
} }
_DEFINE_EXPR_UNARY_OPERATOR(+, __unary_plus) _DEFINE_EXPR_UNARY_OPERATOR(+, __unary_plus)
_DEFINE_EXPR_UNARY_OPERATOR(-, __negate) _DEFINE_EXPR_UNARY_OPERATOR(-, __negate)
...@@ -1086,165 +932,104 @@ _Expr<_Dom,_Tp>::operator _Op() const \ ...@@ -1086,165 +932,104 @@ _Expr<_Dom,_Tp>::operator _Op() const \
#define _DEFINE_EXPR_BINARY_OPERATOR(_Op, _Name) \ #define _DEFINE_EXPR_BINARY_OPERATOR(_Op, _Name) \
template<class _Dom1, class _Dom2> \ template<class _Dom1, class _Dom2> \
inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, \ inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, \
typename _Name<typename _Dom1::value_type>::result_type> \ typename __fun<_Name, typename _Dom1::value_type>::result_type>\
operator _Op (const _Expr<_Dom1,typename _Dom1::value_type>& __v, \ operator _Op(const _Expr<_Dom1,typename _Dom1::value_type>& __v, \
const _Expr<_Dom2,typename _Dom2::value_type>& __w) \ const _Expr<_Dom2,typename _Dom2::value_type>& __w) \
{ \ { \
typedef typename _Dom1::value_type _Arg; \ typedef typename _Dom1::value_type _Arg; \
typedef typename _Name<_Arg>::result_type _Value; \ typedef typename __fun<_Name, _Arg>::result_type _Value; \
typedef _BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2> _Closure; \ typedef _BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__v (), __w ())); \ return _Expr<_Closure,_Value>(_Closure(__v(), __w())); \
} \ } \
\ \
template<class _Dom> \ template<class _Dom> \
inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>, \ inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>,\
typename _Name<typename _Dom::value_type>::result_type> \ typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op (const _Expr<_Dom,typename _Dom::value_type>& __v, \ operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __v, \
const typename _Dom::value_type& __t) \ const typename _Dom::value_type& __t) \
{ \ { \
typedef typename _Dom::value_type _Arg; \ typedef typename _Dom::value_type _Arg; \
typedef typename _Name<_Arg>::result_type _Value; \ typedef typename __fun<_Name, _Arg>::result_type _Value; \
typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \ typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__v (), __t)); \ return _Expr<_Closure,_Value>(_Closure(__v(), __t)); \
} \ } \
\ \
template<class _Dom> \ template<class _Dom> \
inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>, \ inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>,\
typename _Name<typename _Dom::value_type>::result_type> \ typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op (const typename _Dom::value_type& __t, \ operator _Op(const typename _Dom::value_type& __t, \
const _Expr<_Dom,typename _Dom::value_type>& __v) \ const _Expr<_Dom,typename _Dom::value_type>& __v) \
{ \ { \
typedef typename _Dom::value_type _Arg; \ typedef typename _Dom::value_type _Arg; \
typedef typename _Name<_Arg>::result_type _Value; \ typedef typename __fun<_Name, _Arg>::result_type _Value; \
typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \ typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__t, __v ())); \ return _Expr<_Closure,_Value>(_Closure(__t, __v())); \
} \ } \
\ \
template<class _Dom> \ template<class _Dom> \
inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>, \ inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>,\
typename _Name<typename _Dom::value_type>::result_type> \ typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op (const _Expr<_Dom,typename _Dom::value_type>& __e, \ operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \
const valarray<typename _Dom::value_type>& __v) \ const valarray<typename _Dom::value_type>& __v) \
{ \ { \
typedef typename _Dom::value_type _Arg; \ typedef typename _Dom::value_type _Arg; \
typedef typename _Name<_Arg>::result_type _Value; \ typedef typename __fun<_Name, _Arg>::result_type _Value; \
typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Arg> _Closure; \ typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Arg> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__e (), __v)); \ return _Expr<_Closure,_Value>(_Closure(__e(), __v)); \
} \ } \
\ \
template<class _Dom> \ template<class _Dom> \
inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>, \ inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>,\
typename _Name<typename _Dom::value_type>::result_type> \ typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op (const valarray<typename _Dom::value_type>& __v, \ operator _Op(const valarray<typename _Dom::value_type>& __v, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \ const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \ { \
typedef typename _Dom::value_type _Tp; \ typedef typename _Dom::value_type _Tp; \
typedef typename _Name<_Tp>::result_type _Value; \ typedef typename __fun<_Name, _Tp>::result_type _Value; \
typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \ typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__v, __e ())); \ return _Expr<_Closure,_Value> (_Closure (__v, __e ())); \
} }
_DEFINE_EXPR_BINARY_OPERATOR(+, plus) _DEFINE_EXPR_BINARY_OPERATOR(+, __plus)
_DEFINE_EXPR_BINARY_OPERATOR(-, minus) _DEFINE_EXPR_BINARY_OPERATOR(-, __minus)
_DEFINE_EXPR_BINARY_OPERATOR(*, multiplies) _DEFINE_EXPR_BINARY_OPERATOR(*, __multiplies)
_DEFINE_EXPR_BINARY_OPERATOR(/, divides) _DEFINE_EXPR_BINARY_OPERATOR(/, __divides)
_DEFINE_EXPR_BINARY_OPERATOR(%, modulus) _DEFINE_EXPR_BINARY_OPERATOR(%, __modulus)
_DEFINE_EXPR_BINARY_OPERATOR(^, _Bitwise_xor) _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
_DEFINE_EXPR_BINARY_OPERATOR(&, _Bitwise_and) _DEFINE_EXPR_BINARY_OPERATOR(&, __bitwise_and)
_DEFINE_EXPR_BINARY_OPERATOR(|, _Bitwise_or) _DEFINE_EXPR_BINARY_OPERATOR(|, __bitwise_or)
_DEFINE_EXPR_BINARY_OPERATOR(<<, _Shift_left) _DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)
_DEFINE_EXPR_BINARY_OPERATOR(>>, _Shift_right) _DEFINE_EXPR_BINARY_OPERATOR(>>, __shift_right)
_DEFINE_EXPR_BINARY_OPERATOR(&&, __logical_and)
_DEFINE_EXPR_BINARY_OPERATOR(||, __logical_or)
_DEFINE_EXPR_BINARY_OPERATOR(==, __equal_to)
_DEFINE_EXPR_BINARY_OPERATOR(!=, __not_equal_to)
_DEFINE_EXPR_BINARY_OPERATOR(<, __less)
_DEFINE_EXPR_BINARY_OPERATOR(>, __greater)
_DEFINE_EXPR_BINARY_OPERATOR(<=, __less_equal)
_DEFINE_EXPR_BINARY_OPERATOR(>=, __greater_equal)
#undef _DEFINE_EXPR_BINARY_OPERATOR #undef _DEFINE_EXPR_BINARY_OPERATOR
#define _DEFINE_EXPR_RELATIONAL_OPERATOR(_Op, _Name) \
template<class _Dom1, class _Dom2> \
inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, bool> \
operator _Op (const _Expr<_Dom1,typename _Dom1::value_type>& __v, \
const _Expr<_Dom2,typename _Dom2::value_type>& __w) \
{ \
typedef typename _Dom1::value_type _Arg; \
typedef _BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2> _Closure; \
return _Expr<_Closure,bool> (_Closure (__v (), __w ())); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>, \
bool> \
operator _Op (const _Expr<_Dom,typename _Dom::value_type>& __v, \
const typename _Dom::value_type& __t) \
{ \
typedef typename _Dom::value_type _Arg; \
typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \
return _Expr<_Closure,bool> (_Closure (__v (), __t)); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>, \
bool> \
operator _Op (const typename _Dom::value_type& __t, \
const _Expr<_Dom,typename _Dom::value_type>& __v) \
{ \
typedef typename _Dom::value_type _Arg; \
typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \
return _Expr<_Closure,bool> (_Closure (__t, __v ())); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>, \
bool> \
operator _Op (const _Expr<_Dom,typename _Dom::value_type>& __e, \
const valarray<typename _Dom::value_type>& __v) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Tp> _Closure; \
return _Expr<_Closure,bool> (_Closure (__e (), __v)); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>, \
bool> \
operator _Op (const valarray<typename _Dom::value_type>& __v, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,bool> (_Closure (__v, __e ())); \
}
_DEFINE_EXPR_RELATIONAL_OPERATOR(&&, logical_and)
_DEFINE_EXPR_RELATIONAL_OPERATOR(||, logical_or)
_DEFINE_EXPR_RELATIONAL_OPERATOR(==, equal_to)
_DEFINE_EXPR_RELATIONAL_OPERATOR(!=, not_equal_to)
_DEFINE_EXPR_RELATIONAL_OPERATOR(<, less)
_DEFINE_EXPR_RELATIONAL_OPERATOR(>, greater)
_DEFINE_EXPR_RELATIONAL_OPERATOR(<=, less_equal)
_DEFINE_EXPR_RELATIONAL_OPERATOR(>=, greater_equal)
#undef _DEFINE_EXPR_RELATIONAL_OPERATOR
#define _DEFINE_EXPR_UNARY_FUNCTION(_Name) \
template<class _Dom> \
inline _Expr<_UnClos<__##_Name,_Expr,_Dom>,typename _Dom::value_type> \
_Name(const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _UnClos<__##_Name,_Expr,_Dom> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__e())); \
} \
\
template<typename _Tp> \
inline _Expr<_UnClos<__##_Name,_ValArray,_Tp>,_Tp> \
_Name(const valarray<_Tp>& __v) \
{ \
typedef _UnClos<__##_Name,_ValArray,_Tp> _Closure; \
return _Expr<_Closure,_Tp>(_Closure (__v)); \
}
#define _DEFINE_EXPR_UNARY_FUNCTION(_Name) \
template<class _Dom> \
inline _Expr<_UnClos<__##_Name,_Expr,_Dom>,typename _Dom::value_type>\
_Name(const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _UnClos<__##_Name,_Expr,_Dom> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__e())); \
} \
\
template<typename _Tp> \
inline _Expr<_UnClos<__##_Name,_ValArray,_Tp>,_Tp> \
_Name(const valarray<_Tp>& __v) \
{ \
typedef _UnClos<__##_Name,_ValArray,_Tp> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__v)); \
}
_DEFINE_EXPR_UNARY_FUNCTION(abs) _DEFINE_EXPR_UNARY_FUNCTION(abs)
_DEFINE_EXPR_UNARY_FUNCTION(cos) _DEFINE_EXPR_UNARY_FUNCTION(cos)
...@@ -1263,93 +1048,89 @@ _Name(const valarray<_Tp>& __v) \ ...@@ -1263,93 +1048,89 @@ _Name(const valarray<_Tp>& __v) \
#undef _DEFINE_EXPR_UNARY_FUNCTION #undef _DEFINE_EXPR_UNARY_FUNCTION
#define _DEFINE_EXPR_BINARY_FUNCTION(_Fun) \
#define _DEFINE_EXPR_BINARY_FUNCTION(_Name) \ template<class _Dom1, class _Dom2> \
template<class _Dom1, class _Dom2> \ inline _Expr<_BinClos<__##_Fun,_Expr,_Expr,_Dom1,_Dom2>, \
inline _Expr<_BinFunClos<_Expr,_Expr,_Dom1,_Dom2>,typename _Dom1::value_type>\ typename _Dom1::value_type> \
_Name (const _Expr<_Dom1,typename _Dom1::value_type>& __e1, \ _Fun(const _Expr<_Dom1,typename _Dom1::value_type>& __e1, \
const _Expr<_Dom2,typename _Dom2::value_type>& __e2) \ const _Expr<_Dom2,typename _Dom2::value_type>& __e2) \
{ \ { \
typedef typename _Dom1::value_type _Tp; \ typedef typename _Dom1::value_type _Tp; \
typedef _BinFunClos<_Expr,_Expr,_Dom1,_Dom2> _Closure; \ typedef _BinClos<__##_Fun,_Expr,_Expr,_Dom1,_Dom2> _Closure; \
return _Expr<_Closure,_Tp> \ return _Expr<_Closure,_Tp>(_Closure(__e1(), __e2())); \
(_Closure (__e1 (), __e2 (), (_Tp(*)(_Tp, _Tp))(&_Name))); \ } \
} \ \
\ template<class _Dom> \
template<class _Dom> \ inline _Expr<_BinClos<__##_Fun, _Expr, _ValArray, _Dom, \
inline _Expr<_BinFunClos<_Expr,_ValArray,_Dom,typename _Dom::value_type>, \ typename _Dom::value_type>, \
typename _Dom::value_type> \ typename _Dom::value_type> \
_Name (const _Expr<_Dom,typename _Dom::value_type>& __e, \ _Fun(const _Expr<_Dom,typename _Dom::value_type>& __e, \
const valarray<typename _Dom::value_type>& __v) \ const valarray<typename _Dom::value_type>& __v) \
{ \ { \
typedef typename _Dom::value_type _Tp; \ typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_Expr,_ValArray,_Dom,_Tp> _Closure; \ typedef _BinClos<__##_Fun, _Expr, _ValArray, _Dom, _Tp> _Closure;\
return _Expr<_Closure,_Tp> \ return _Expr<_Closure,_Tp>(_Closure(__e(), __v)); \
(_Closure (__e (), __v, (_Tp(*)(_Tp, _Tp))(&_Name))); \ } \
} \ \
\ template<class _Dom> \
template<class _Dom> \ inline _Expr<_BinClos<__##_Fun, _ValArray, _Expr, \
inline _Expr<_BinFunClos<_ValArray,_Expr,typename _Dom::value_type,_Dom>, \ typename _Dom::value_type,_Dom>, \
typename _Dom::value_type> \ typename _Dom::value_type> \
_Name (const valarray<typename _Dom::valarray>& __v, \ _Fun(const valarray<typename _Dom::valarray>& __v, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \ const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \ { \
typedef typename _Dom::value_type _Tp; \ typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_ValArray,_Expr,_Tp,_Dom> _Closure; \ typedef _BinClos<__##_Fun,_ValArray,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Tp> \ return _Expr<_Closure,_Tp>(_Closure(__v, __e())); \
(_Closure (__v, __e (), (_Tp(*)(_Tp, _Tp))(&_Name))); \ } \
} \ \
\ template<class _Dom> \
template<class _Dom> \ inline _Expr<_BinClos<__##_Fun,_Expr,_Constant,_Dom, \
inline _Expr<_BinFunClos<_Expr,_Constant,_Dom,typename _Dom::value_type>, \ typename _Dom::value_type>, \
typename _Dom::value_type> \ typename _Dom::value_type> \
_Name (const _Expr<_Dom, typename _Dom::value_type>& __e, \ _Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \
const typename _Dom::value_type& __t) \ const typename _Dom::value_type& __t) \
{ \ { \
typedef typename _Dom::value_type _Tp; \ typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_Expr,_Constant,_Dom,_Tp> _Closure; \ typedef _BinClos<__##_Fun,_Expr,_Constant,_Dom,_Tp> _Closure; \
return _Expr<_Closure,_Tp> \ return _Expr<_Closure,_Tp>(_Closure(__e(), __t)); \
(_Closure (__e (), __t, (_Tp(*)(_Tp, _Tp))(&_Name))); \ } \
} \ \
\ template<class _Dom> \
template<class _Dom> \ inline _Expr<_BinClos<__##_Fun,_Constant,_Expr, \
inline _Expr<_BinFunClos<_Constant,_Expr,typename _Dom::value_type,_Dom>, \ typename _Dom::value_type,_Dom>, \
typename _Dom::value_type> \ typename _Dom::value_type> \
_Name (const typename _Dom::value_type& __t, \ _Fun(const typename _Dom::value_type& __t, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \ const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \ { \
typedef typename _Dom::value_type _Tp; \ typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_Constant,_Expr,_Tp,_Dom> _Closure; \ typedef _BinClos<__##_Fun, _Constant,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Tp> \ return _Expr<_Closure,_Tp>(_Closure(__t, __e())); \
(_Closure (__t, __e (), (_Tp(*)(_Tp, _Tp))(&_Name))); \ } \
} \ \
\ template<typename _Tp> \
template<typename _Tp> \ inline _Expr<_BinClos<__##_Fun,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
inline _Expr<_BinFunClos<_ValArray,_ValArray,_Tp,_Tp>, _Tp> \ _Fun(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
_Name (const valarray<_Tp>& __v, const valarray<_Tp>& __w) \ { \
{ \ typedef _BinClos<__##_Fun,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
typedef _BinFunClos<_ValArray,_ValArray,_Tp,_Tp> _Closure; \ return _Expr<_Closure,_Tp>(_Closure(__v, __w)); \
return _Expr<_Closure,_Tp> \ } \
(_Closure (__v, __w, (_Tp(*)(_Tp,_Tp))(&_Name))); \ \
} \ template<typename _Tp> \
\ inline _Expr<_BinClos<__##_Fun,_ValArray,_Constant,_Tp,_Tp>,_Tp> \
template<typename _Tp> \ _Fun(const valarray<_Tp>& __v, const _Tp& __t) \
inline _Expr<_BinFunClos<_ValArray,_Constant,_Tp,_Tp>,_Tp> \ { \
_Name (const valarray<_Tp>& __v, const _Tp& __t) \ typedef _BinClos<__##_Fun,_ValArray,_Constant,_Tp,_Tp> _Closure; \
{ \ return _Expr<_Closure,_Tp>(_Closure(__v, __t)); \
typedef _BinFunClos<_ValArray,_Constant,_Tp,_Tp> _Closure; \ } \
return _Expr<_Closure,_Tp> \ \
(_Closure (__v, __t, (_Tp(*)(_Tp,_Tp))(&_Name))); \ template<typename _Tp> \
} \ inline _Expr<_BinClos<__##_Fun,_Constant,_ValArray,_Tp,_Tp>,_Tp> \
\ _Fun(const _Tp& __t, const valarray<_Tp>& __v) \
template<typename _Tp> \ { \
inline _Expr<_BinFunClos<_Constant,_ValArray,_Tp,_Tp>,_Tp> \ typedef _BinClos<__##_Fun,_Constant,_ValArray,_Tp,_Tp> _Closure; \
_Name (const _Tp& __t, const valarray<_Tp>& __v) \ return _Expr<_Closure,_Tp>(_Closure(__t, __v)); \
{ \ }
typedef _BinFunClos<_Constant,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__t, __v, (_Tp(*)(_Tp,_Tp))(&_Name))); \
}
_DEFINE_EXPR_BINARY_FUNCTION(atan2) _DEFINE_EXPR_BINARY_FUNCTION(atan2)
_DEFINE_EXPR_BINARY_FUNCTION(pow) _DEFINE_EXPR_BINARY_FUNCTION(pow)
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <numeric> #include <numeric>
#include <functional>
#include <algorithm> #include <algorithm>
namespace std namespace std
...@@ -59,7 +58,7 @@ namespace std ...@@ -59,7 +58,7 @@ namespace std
template<class _Oper, template<class, class> class _Meta, class _Dom> template<class _Oper, template<class, class> class _Meta, class _Dom>
struct _UnClos; struct _UnClos;
template<template<class> class _Oper, template<class _Oper,
template<class, class> class _Meta1, template<class, class> class _Meta1,
template<class, class> class _Meta2, template<class, class> class _Meta2,
class _Dom1, class _Dom2> class _Dom1, class _Dom2>
...@@ -80,12 +79,6 @@ namespace std ...@@ -80,12 +79,6 @@ namespace std
template<template<class, class> class _Meta, class _Dom> template<template<class, class> class _Meta, class _Dom>
class _RefFunClos; class _RefFunClos;
template<class _Tp> struct _Bitwise_and;
template<class _Tp> struct _Bitwise_or;
template<class _Tp> struct _Bitwise_xor;
template<class _Tp> struct _Shift_left;
template<class _Tp> struct _Shift_right;
template<class _Tp> class valarray; // An array of type _Tp template<class _Tp> class valarray; // An array of type _Tp
class slice; // BLAS-like slice out of an array class slice; // BLAS-like slice out of an array
template<class _Tp> class slice_array; template<class _Tp> class slice_array;
...@@ -224,27 +217,6 @@ namespace std ...@@ -224,27 +217,6 @@ namespace std
friend class _Array<_Tp>; friend class _Array<_Tp>;
}; };
template<typename _Tp> struct _Bitwise_and : binary_function<_Tp,_Tp,_Tp> {
_Tp operator() (_Tp __x, _Tp __y) const { return __x & __y; }
};
template<typename _Tp> struct _Bitwise_or : binary_function<_Tp,_Tp,_Tp> {
_Tp operator() (_Tp __x, _Tp __y) const { return __x | __y; }
};
template<typename _Tp> struct _Bitwise_xor : binary_function<_Tp,_Tp,_Tp> {
_Tp operator() (_Tp __x, _Tp __y) const { return __x ^ __y; }
};
template<typename _Tp> struct _Shift_left : unary_function<_Tp,_Tp> {
_Tp operator() (_Tp __x, _Tp __y) const { return __x << __y; }
};
template<typename _Tp> struct _Shift_right : unary_function<_Tp,_Tp> {
_Tp operator() (_Tp __x, _Tp __y) const { return __x >> __y; }
};
template<typename _Tp> template<typename _Tp>
inline const _Tp& inline const _Tp&
...@@ -486,7 +458,7 @@ namespace std ...@@ -486,7 +458,7 @@ namespace std
inline _Tp inline _Tp
valarray<_Tp>::sum() const valarray<_Tp>::sum() const
{ {
return __valarray_sum(_M_data, _M_data + _M_size); return __valarray_sum(_M_data, _M_data + _M_size);
} }
// template<typename _Tp> // template<typename _Tp>
...@@ -611,138 +583,107 @@ namespace std ...@@ -611,138 +583,107 @@ namespace std
#define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \ #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
template<class _Tp> \ template<class _Tp> \
inline valarray<_Tp> & \ inline valarray<_Tp>& \
valarray<_Tp>::operator _Op##= (const _Tp &__t) \ valarray<_Tp>::operator _Op##=(const _Tp &__t) \
{ \ { \
_Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, __t); \ _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \
return *this; \ return *this; \
} \ } \
\ \
template<class _Tp> \ template<class _Tp> \
inline valarray<_Tp> & \ inline valarray<_Tp>& \
valarray<_Tp>::operator _Op##= (const valarray<_Tp> &__v) \ valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \
{ \ { \
_Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, \ _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \
_Array<_Tp>(__v._M_data)); \ _Array<_Tp>(__v._M_data)); \
return *this; \ return *this; \
} }
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, plus) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, minus) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, multiplies) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, divides) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, modulus) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, xor) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, and) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, or) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, shift_left) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, shift_right) _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right)
#undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
} // std::
namespace std
{
#define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \ #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
template<class _Tp> template<class _Dom> \ template<class _Tp> template<class _Dom> \
inline valarray<_Tp> & \ inline valarray<_Tp>& \
valarray<_Tp>::operator _Op##= (const _Expr<_Dom,_Tp> &__e) \ valarray<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) \
{ \ { \
_Array_augmented_##_Name (_Array<_Tp>(_M_data), __e, _M_size); \ _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \
return *this; \ return *this; \
} }
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, plus) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, minus) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, multiplies) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, divides) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, modulus) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, xor) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, and) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, or) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, shift_left) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, shift_right) _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
#undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
#define _DEFINE_BINARY_OPERATOR(_Op, _Name) \ #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
template<typename _Tp> \ template<typename _Tp> \
inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \ inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, \
operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \ typename __fun<_Name, _Tp>::result_type> \
{ \ operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
{ \
typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \ typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure, _Tp> (_Closure (__v, __w)); \ typedef typename __fun<_Name, _Tp>::result_type _Rt; \
} \ return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \
} \
\ \
template<typename _Tp> \ template<typename _Tp> \
inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \ inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>, \
operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \ typename __fun<_Name, _Tp>::result_type> \
operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \
{ \ { \
typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \ typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \ typedef typename __fun<_Name, _Tp>::result_type _Rt; \
return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \
} \ } \
\ \
template<typename _Tp> \ template<typename _Tp> \
inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,_Tp> \ inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>, \
operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \ typename __fun<_Name, _Tp>::result_type> \
operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \
{ \ { \
typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \ typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure, _Tp> (_Closure (__t, __v)); \ typedef typename __fun<_Name, _Tp>::result_type _Rt; \
} return _Expr<_Closure, _Tp>(_Closure(__t, __v)); \
_DEFINE_BINARY_OPERATOR(+, plus)
_DEFINE_BINARY_OPERATOR(-, minus)
_DEFINE_BINARY_OPERATOR(*, multiplies)
_DEFINE_BINARY_OPERATOR(/, divides)
_DEFINE_BINARY_OPERATOR(%, modulus)
_DEFINE_BINARY_OPERATOR(^, _Bitwise_xor)
_DEFINE_BINARY_OPERATOR(&, _Bitwise_and)
_DEFINE_BINARY_OPERATOR(|, _Bitwise_or)
_DEFINE_BINARY_OPERATOR(<<, _Shift_left)
_DEFINE_BINARY_OPERATOR(>>, _Shift_right)
#undef _DEFINE_BINARY_OPERATOR
#define _DEFINE_LOGICAL_OPERATOR(_Op, _Name) \
template<typename _Tp> \
inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>,bool> \
operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
{ \
typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure, bool> (_Closure (__v, __w)); \
} \
\
template<class _Tp> \
inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,bool> \
operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \
{ \
typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
return _Expr<_Closure, bool> (_Closure (__v, __t)); \
} \
\
template<class _Tp> \
inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,bool> \
operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \
{ \
typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure, bool> (_Closure (__t, __v)); \
} }
_DEFINE_LOGICAL_OPERATOR(&&, logical_and) _DEFINE_BINARY_OPERATOR(+, __plus)
_DEFINE_LOGICAL_OPERATOR(||, logical_or) _DEFINE_BINARY_OPERATOR(-, __minus)
_DEFINE_LOGICAL_OPERATOR(==, equal_to) _DEFINE_BINARY_OPERATOR(*, __multiplies)
_DEFINE_LOGICAL_OPERATOR(!=, not_equal_to) _DEFINE_BINARY_OPERATOR(/, __divides)
_DEFINE_LOGICAL_OPERATOR(<, less) _DEFINE_BINARY_OPERATOR(%, __modulus)
_DEFINE_LOGICAL_OPERATOR(>, greater) _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
_DEFINE_LOGICAL_OPERATOR(<=, less_equal) _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
_DEFINE_LOGICAL_OPERATOR(>=, greater_equal) _DEFINE_BINARY_OPERATOR(|, __bitwise_or)
_DEFINE_BINARY_OPERATOR(<<, __shift_left)
#undef _DEFINE_LOGICAL_OPERATOR _DEFINE_BINARY_OPERATOR(>>, __shift_right)
_DEFINE_BINARY_OPERATOR(&&, __logical_and)
_DEFINE_BINARY_OPERATOR(||, __logical_or)
_DEFINE_BINARY_OPERATOR(==, __equal_to)
_DEFINE_BINARY_OPERATOR(!=, __not_equal_to)
_DEFINE_BINARY_OPERATOR(<, __less)
_DEFINE_BINARY_OPERATOR(>, __greater)
_DEFINE_BINARY_OPERATOR(<=, __less_equal)
_DEFINE_BINARY_OPERATOR(>=, __greater_equal)
} // namespace std } // namespace std
......
...@@ -116,4 +116,27 @@ int main() ...@@ -116,4 +116,27 @@ int main()
v = log(u); v = log(u);
v = log10(u); v = log10(u);
v = sqrt(u); v = sqrt(u);
Array w = u + v;
w = u - v;
w = u * v;
w = u / v;
w = u % v;
w = u ^ v;
w = u & v;
w = u | v;
w = u << v;
w = u >> v;
z = u == v;
z = u != v;
z = u < v;
z = u <= v;
z = u > v;
z = u >= v;
w = atan2(u, v);
w = pow(u, v);
} }
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