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
This commit is contained in:
Gabriel Dos Reis 2002-08-02 23:08:40 +00:00 committed by Gabriel Dos Reis
parent 55765de441
commit 971cfc6f10
5 changed files with 457 additions and 691 deletions

View File

@ -1,3 +1,24 @@
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>
* include/bits/valarray_meta.h (_UnFunBase<>): Remove.

View File

@ -603,16 +603,16 @@ _Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \
} \
}
_DEFINE_ARRAY_FUNCTION(+, plus)
_DEFINE_ARRAY_FUNCTION(-, minus)
_DEFINE_ARRAY_FUNCTION(*, multiplies)
_DEFINE_ARRAY_FUNCTION(/, divides)
_DEFINE_ARRAY_FUNCTION(%, modulus)
_DEFINE_ARRAY_FUNCTION(^, xor)
_DEFINE_ARRAY_FUNCTION(|, or)
_DEFINE_ARRAY_FUNCTION(&, and)
_DEFINE_ARRAY_FUNCTION(<<, shift_left)
_DEFINE_ARRAY_FUNCTION(>>, shift_right)
_DEFINE_ARRAY_FUNCTION(+, __plus)
_DEFINE_ARRAY_FUNCTION(-, __minus)
_DEFINE_ARRAY_FUNCTION(*, __multiplies)
_DEFINE_ARRAY_FUNCTION(/, __divides)
_DEFINE_ARRAY_FUNCTION(%, __modulus)
_DEFINE_ARRAY_FUNCTION(^, __bitwise_xor)
_DEFINE_ARRAY_FUNCTION(|, __bitwise_or)
_DEFINE_ARRAY_FUNCTION(&, __bitwise_and)
_DEFINE_ARRAY_FUNCTION(<<, __shift_left)
_DEFINE_ARRAY_FUNCTION(>>, __shift_right)
#undef _DEFINE_VALARRAY_FUNCTION

View File

@ -50,7 +50,6 @@ namespace std
// template nesting due to _Expr<>
//
// This class is NOT defined. It doesn't need to.
template<typename _Tp1, typename _Tp2> class _Constant;
@ -224,7 +223,7 @@ namespace std
{ return __x | __y; }
};
struct __shift__left
struct __shift_left
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
@ -380,222 +379,73 @@ namespace std
typedef bool result_type;
};
//
// 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
//
template<typename _Dom, typename _Arg> class _FunBase {
template<typename _Dom, typename _Arg>
class _FunBase
{
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))
: _M_expr (__e), _M_func (__f) {}
value_type operator[](size_t __i) const
{ return _M_func (_M_expr[__i]); }
value_type operator[] (size_t __i) const
{ return _M_func (_M_expr[__i]); }
size_t size() const { return _M_expr.size ();}
size_t size() const { return _M_expr.size ();}
private:
const _Dom& _M_expr;
value_type (*_M_func)(_Arg);
};
template<class _Dom>
struct _ValFunClos<_Expr,_Dom>
: _FunBase<_Dom, typename _Dom::value_type> {
typedef _FunBase<_Dom, typename _Dom::value_type> _Base;
typedef typename _Base::value_type value_type;
typedef value_type _Tp;
template<class _Dom>
struct _ValFunClos<_Expr,_Dom> : _FunBase<_Dom, typename _Dom::value_type>
{
typedef _FunBase<_Dom, typename _Dom::value_type> _Base;
typedef typename _Base::value_type value_type;
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>
struct _ValFunClos<_ValArray,_Tp>
: _FunBase<valarray<_Tp>, _Tp> {
typedef _FunBase<valarray<_Tp>, _Tp> _Base;
typedef _Tp value_type;
_ValFunClos (const valarray<_Tp>& __v, _Tp __f(_Tp))
: _Base (__v, __f) {}
template<typename _Tp>
struct _ValFunClos<_ValArray,_Tp> : _FunBase<valarray<_Tp>, _Tp>
{
typedef _FunBase<valarray<_Tp>, _Tp> _Base;
typedef _Tp value_type;
_ValFunClos(const valarray<_Tp>& __v, _Tp __f(_Tp)) : _Base(__v, __f) {}
};
template<class _Dom>
template<class _Dom>
struct _RefFunClos<_Expr,_Dom> :
_FunBase<_Dom, const typename _Dom::value_type&> {
typedef _FunBase<_Dom, const typename _Dom::value_type&> _Base;
typedef typename _Base::value_type value_type;
typedef value_type _Tp;
_RefFunClos (const _Dom& __e, _Tp __f (const _Tp&))
: _Base (__e, __f) {}
_FunBase<_Dom, const typename _Dom::value_type&>
{
typedef _FunBase<_Dom, const typename _Dom::value_type&> _Base;
typedef typename _Base::value_type value_type;
typedef value_type _Tp;
_RefFunClos(const _Dom& __e, _Tp __f(const _Tp&))
: _Base(__e, __f) {}
};
template<typename _Tp>
struct _RefFunClos<_ValArray,_Tp>
: _FunBase<valarray<_Tp>, const _Tp&> {
typedef _FunBase<valarray<_Tp>, const _Tp&> _Base;
typedef _Tp value_type;
_RefFunClos (const valarray<_Tp>& __v, _Tp __f(const _Tp&))
: _Base (__v, __f) {}
template<typename _Tp>
struct _RefFunClos<_ValArray,_Tp> : _FunBase<valarray<_Tp>, const _Tp&>
{
typedef _FunBase<valarray<_Tp>, const _Tp&> _Base;
typedef _Tp value_type;
_RefFunClos(const valarray<_Tp>& __v, _Tp __f(const _Tp&))
: _Base(__v, __f) {}
};
//
// Unary expression closure.
//
//
// Unary expression closure.
//
template<class _Oper, class _Arg>
class _UnBase
@ -636,160 +486,156 @@ namespace std
};
//
// Binary expression closure.
//
//
// Binary expression closure.
//
template<template<class> class _Oper,
typename _FirstArg, typename _SecondArg>
class _BinBase {
template<class _Oper, class _FirstArg, class _SecondArg>
class _BinBase
{
public:
typedef _Oper<typename _FirstArg::value_type> _Op;
typedef typename _Op::result_type value_type;
typedef typename _FirstArg::value_type _Vt;
typedef typename __fun<_Oper, _Vt>::result_type value_type;
_BinBase (const _FirstArg& __e1, const _SecondArg& __e2)
: _M_expr1 (__e1), _M_expr2 (__e2) {}
value_type operator[] (size_t) const;
size_t size () const { return _M_expr1.size (); }
_BinBase(const _FirstArg& __e1, const _SecondArg& __e2)
: _M_expr1(__e1), _M_expr2(__e2) {}
value_type operator[](size_t __i) const
{ return _Oper()(_M_expr1[__i], _M_expr2[__i]); }
size_t size() const { return _M_expr1.size(); }
private:
const _FirstArg& _M_expr1;
const _SecondArg& _M_expr2;
const _FirstArg& _M_expr1;
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>
class _BinBase2 {
template<class _Oper, class _Clos>
class _BinBase2
{
public:
typedef typename _Clos::value_type _Vt;
typedef _Oper<_Vt> _Op;
typedef typename _Op::result_type value_type;
typedef typename _Clos::value_type _Vt;
typedef typename __fun<_Oper, _Vt>::result_type value_type;
_BinBase2 (const _Clos& __e, const _Vt& __t)
: _M_expr1 (__e), _M_expr2 (__t) {}
value_type operator[] (size_t) const;
size_t size () const { return _M_expr1.size (); }
_BinBase2(const _Clos& __e, const _Vt& __t)
: _M_expr1(__e), _M_expr2(__t) {}
value_type operator[](size_t __i) const
{ return _Oper()(_M_expr1[__i], _M_expr2); }
size_t size() const { return _M_expr1.size(); }
private:
const _Clos& _M_expr1;
const _Vt& _M_expr2;
const _Clos& _M_expr1;
const _Vt& _M_expr2;
};
template<template<class> class _Oper, class _Clos>
inline typename _BinBase2<_Oper,_Clos>::value_type
_BinBase2<_Oper,_Clos>::operator[] (size_t __i) const
{ return _Op() (_M_expr1[__i], _M_expr2); }
template<template<class> class _Oper, class _Clos>
class _BinBase1 {
template<class _Oper, class _Clos>
class _BinBase1
{
public:
typedef typename _Clos::value_type _Vt;
typedef _Oper<_Vt> _Op;
typedef typename _Op::result_type value_type;
typedef typename _Clos::value_type _Vt;
typedef typename __fun<_Oper, _Vt>::result_type value_type;
_BinBase1 (const _Vt& __t, const _Clos& __e)
: _M_expr1 (__t), _M_expr2 (__e) {}
value_type operator[] (size_t) const;
size_t size () const { return _M_expr2.size (); }
_BinBase1(const _Vt& __t, const _Clos& __e)
: _M_expr1(__t), _M_expr2(__e) {}
value_type operator[](size_t __i) const
{ return _Oper()(_M_expr1, _M_expr2[__i]); }
size_t size() const { return _M_expr2.size(); }
private:
const _Vt& _M_expr1;
const _Clos& _M_expr2;
const _Vt& _M_expr1;
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>
struct _BinClos<_Oper, _Expr, _Expr, _Dom1, _Dom2>
: _BinBase<_Oper,_Dom1,_Dom2> {
typedef _BinBase<_Oper,_Dom1,_Dom2> _Base;
typedef typename _Base::value_type value_type;
template<class _Oper, class _Dom1, class _Dom2>
struct _BinClos<_Oper, _Expr, _Expr, _Dom1, _Dom2>
: _BinBase<_Oper,_Dom1,_Dom2>
{
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>
: _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > {
typedef _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > _Base;
typedef _Tp value_type;
: _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> >
{
typedef _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > _Base;
typedef _Tp value_type;
_BinClos (const valarray<_Tp>& __v, const valarray<_Tp>& __w)
: _Base (__v, __w) {}
_BinClos(const valarray<_Tp>& __v, const valarray<_Tp>& __w)
: _Base(__v, __w) {}
};
template<template<class> class _Oper, class _Dom>
struct _BinClos<_Oper,_Expr,_ValArray,_Dom,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 _Base::value_type value_type;
_BinClos(const _Dom& __e1, const valarray<_Tp>& __e2)
: _Base (__e1, __e2) {}
template<class _Oper, class _Dom>
struct _BinClos<_Oper,_Expr,_ValArray,_Dom,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 _Base::value_type value_type;
_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>
: _BinBase<_Oper,valarray<typename _Dom::value_type>,_Dom> {
typedef typename _Dom::value_type _Tp;
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) {}
: _BinBase<_Oper,valarray<typename _Dom::value_type>,_Dom>
{
typedef typename _Dom::value_type _Tp;
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) {}
};
template<template<class> class _Oper, class _Dom>
template<class _Oper, class _Dom>
struct _BinClos<_Oper,_Expr,_Constant,_Dom,typename _Dom::value_type>
: _BinBase2<_Oper,_Dom> {
typedef typename _Dom::value_type _Tp;
typedef _BinBase2<_Oper,_Dom> _Base;
typedef typename _Base::value_type value_type;
_BinClos (const _Dom& __e1, const _Tp& __e2) : _Base (__e1, __e2) {}
: _BinBase2<_Oper,_Dom>
{
typedef typename _Dom::value_type _Tp;
typedef _BinBase2<_Oper,_Dom> _Base;
typedef typename _Base::value_type value_type;
_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>
: _BinBase1<_Oper,_Dom> {
typedef typename _Dom::value_type _Tp;
typedef _BinBase1<_Oper,_Dom> _Base;
typedef typename _Base::value_type value_type;
_BinClos (const _Tp& __e1, const _Dom& __e2) : _Base (__e1, __e2) {}
: _BinBase1<_Oper,_Dom>
{
typedef typename _Dom::value_type _Tp;
typedef _BinBase1<_Oper,_Dom> _Base;
typedef typename _Base::value_type value_type;
_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>
: _BinBase2<_Oper,valarray<_Tp> > {
typedef _BinBase2<_Oper,valarray<_Tp> > _Base;
typedef typename _Base::value_type value_type;
_BinClos (const valarray<_Tp>& __v, const _Tp& __t)
: _Base (__v, __t) {}
: _BinBase2<_Oper,valarray<_Tp> >
{
typedef _BinBase2<_Oper,valarray<_Tp> > _Base;
typedef typename _Base::value_type value_type;
_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>
: _BinBase1<_Oper,valarray<_Tp> > {
typedef _BinBase1<_Oper,valarray<_Tp> > _Base;
typedef typename _Base::value_type value_type;
_BinClos (const _Tp& __t, const valarray<_Tp>& __v)
: _Base (__t, __v) {}
: _BinBase1<_Oper,valarray<_Tp> >
{
typedef _BinBase1<_Oper,valarray<_Tp> > _Base;
typedef typename _Base::value_type value_type;
_BinClos(const _Tp& __t, const valarray<_Tp>& __v) : _Base(__t, __v) {}
};
@ -1065,18 +911,18 @@ namespace std
inline _Expr<_UnClos<__logical_not,_Expr,_Dom>, bool>
_Expr<_Dom,_Tp>::operator!() const
{
typedef _UnClos<__logical_not,std::_Expr,_Dom> _Closure;
return _Expr<_Closure,_Tp>(_Closure(this->_M_closure));
typedef _UnClos<__logical_not,std::_Expr,_Dom> _Closure;
return _Expr<_Closure,_Tp>(_Closure(this->_M_closure));
}
#define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \
template<class _Dom, typename _Tp> \
inline _Expr<_UnClos<_Name,std::_Expr,_Dom>,_Tp> \
_Expr<_Dom,_Tp>::operator _Op() const \
{ \
typedef _UnClos<_Name,std::_Expr,_Dom> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(this->_M_closure)); \
}
#define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \
template<class _Dom, typename _Tp> \
inline _Expr<_UnClos<_Name,std::_Expr,_Dom>,_Tp> \
_Expr<_Dom,_Tp>::operator _Op() const \
{ \
typedef _UnClos<_Name,std::_Expr,_Dom> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(this->_M_closure)); \
}
_DEFINE_EXPR_UNARY_OPERATOR(+, __unary_plus)
_DEFINE_EXPR_UNARY_OPERATOR(-, __negate)
@ -1086,165 +932,104 @@ _Expr<_Dom,_Tp>::operator _Op() const \
#define _DEFINE_EXPR_BINARY_OPERATOR(_Op, _Name) \
template<class _Dom1, class _Dom2> \
inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, \
typename _Name<typename _Dom1::value_type>::result_type> \
operator _Op (const _Expr<_Dom1,typename _Dom1::value_type>& __v, \
const _Expr<_Dom2,typename _Dom2::value_type>& __w) \
{ \
template<class _Dom1, class _Dom2> \
inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, \
typename __fun<_Name, typename _Dom1::value_type>::result_type>\
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 typename _Name<_Arg>::result_type _Value; \
typedef typename __fun<_Name, _Arg>::result_type _Value; \
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> \
inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>,\
typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __v, \
const typename _Dom::value_type& __t) \
{ \
typedef typename _Dom::value_type _Arg; \
typedef typename __fun<_Name, _Arg>::result_type _Value; \
typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \
return _Expr<_Closure,_Value>(_Closure(__v(), __t)); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>, \
typename _Name<typename _Dom::value_type>::result_type> \
operator _Op (const _Expr<_Dom,typename _Dom::value_type>& __v, \
const typename _Dom::value_type& __t) \
inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>,\
typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op(const typename _Dom::value_type& __t, \
const _Expr<_Dom,typename _Dom::value_type>& __v) \
{ \
typedef typename _Dom::value_type _Arg; \
typedef typename _Name<_Arg>::result_type _Value; \
typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__v (), __t)); \
typedef typename _Dom::value_type _Arg; \
typedef typename __fun<_Name, _Arg>::result_type _Value; \
typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \
return _Expr<_Closure,_Value>(_Closure(__t, __v())); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>, \
typename _Name<typename _Dom::value_type>::result_type> \
operator _Op (const typename _Dom::value_type& __t, \
const _Expr<_Dom,typename _Dom::value_type>& __v) \
inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>,\
typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \
const valarray<typename _Dom::value_type>& __v) \
{ \
typedef typename _Dom::value_type _Arg; \
typedef typename _Name<_Arg>::result_type _Value; \
typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__t, __v ())); \
typedef typename _Dom::value_type _Arg; \
typedef typename __fun<_Name, _Arg>::result_type _Value; \
typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Arg> _Closure; \
return _Expr<_Closure,_Value>(_Closure(__e(), __v)); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>, \
typename _Name<typename _Dom::value_type>::result_type> \
operator _Op (const _Expr<_Dom,typename _Dom::value_type>& __e, \
const valarray<typename _Dom::value_type>& __v) \
inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>,\
typename __fun<_Name, typename _Dom::value_type>::result_type>\
operator _Op(const valarray<typename _Dom::value_type>& __v, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Arg; \
typedef typename _Name<_Arg>::result_type _Value; \
typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Arg> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__e (), __v)); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>, \
typename _Name<typename _Dom::value_type>::result_type> \
operator _Op (const valarray<typename _Dom::value_type>& __v, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef typename _Name<_Tp>::result_type _Value; \
typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__v, __e ())); \
typedef typename _Dom::value_type _Tp; \
typedef typename __fun<_Name, _Tp>::result_type _Value; \
typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Value> (_Closure (__v, __e ())); \
}
_DEFINE_EXPR_BINARY_OPERATOR(+, plus)
_DEFINE_EXPR_BINARY_OPERATOR(-, minus)
_DEFINE_EXPR_BINARY_OPERATOR(*, multiplies)
_DEFINE_EXPR_BINARY_OPERATOR(/, divides)
_DEFINE_EXPR_BINARY_OPERATOR(%, modulus)
_DEFINE_EXPR_BINARY_OPERATOR(^, _Bitwise_xor)
_DEFINE_EXPR_BINARY_OPERATOR(&, _Bitwise_and)
_DEFINE_EXPR_BINARY_OPERATOR(|, _Bitwise_or)
_DEFINE_EXPR_BINARY_OPERATOR(<<, _Shift_left)
_DEFINE_EXPR_BINARY_OPERATOR(>>, _Shift_right)
_DEFINE_EXPR_BINARY_OPERATOR(+, __plus)
_DEFINE_EXPR_BINARY_OPERATOR(-, __minus)
_DEFINE_EXPR_BINARY_OPERATOR(*, __multiplies)
_DEFINE_EXPR_BINARY_OPERATOR(/, __divides)
_DEFINE_EXPR_BINARY_OPERATOR(%, __modulus)
_DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
_DEFINE_EXPR_BINARY_OPERATOR(&, __bitwise_and)
_DEFINE_EXPR_BINARY_OPERATOR(|, __bitwise_or)
_DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)
_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
#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(cos)
@ -1263,93 +1048,89 @@ _Name(const valarray<_Tp>& __v) \
#undef _DEFINE_EXPR_UNARY_FUNCTION
#define _DEFINE_EXPR_BINARY_FUNCTION(_Name) \
template<class _Dom1, class _Dom2> \
inline _Expr<_BinFunClos<_Expr,_Expr,_Dom1,_Dom2>,typename _Dom1::value_type>\
_Name (const _Expr<_Dom1,typename _Dom1::value_type>& __e1, \
const _Expr<_Dom2,typename _Dom2::value_type>& __e2) \
{ \
typedef typename _Dom1::value_type _Tp; \
typedef _BinFunClos<_Expr,_Expr,_Dom1,_Dom2> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__e1 (), __e2 (), (_Tp(*)(_Tp, _Tp))(&_Name))); \
} \
\
template<class _Dom> \
inline _Expr<_BinFunClos<_Expr,_ValArray,_Dom,typename _Dom::value_type>, \
typename _Dom::value_type> \
_Name (const _Expr<_Dom,typename _Dom::value_type>& __e, \
const valarray<typename _Dom::value_type>& __v) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_Expr,_ValArray,_Dom,_Tp> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__e (), __v, (_Tp(*)(_Tp, _Tp))(&_Name))); \
} \
\
template<class _Dom> \
inline _Expr<_BinFunClos<_ValArray,_Expr,typename _Dom::value_type,_Dom>, \
typename _Dom::value_type> \
_Name (const valarray<typename _Dom::valarray>& __v, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_ValArray,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__v, __e (), (_Tp(*)(_Tp, _Tp))(&_Name))); \
} \
\
template<class _Dom> \
inline _Expr<_BinFunClos<_Expr,_Constant,_Dom,typename _Dom::value_type>, \
typename _Dom::value_type> \
_Name (const _Expr<_Dom, typename _Dom::value_type>& __e, \
const typename _Dom::value_type& __t) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_Expr,_Constant,_Dom,_Tp> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__e (), __t, (_Tp(*)(_Tp, _Tp))(&_Name))); \
} \
\
template<class _Dom> \
inline _Expr<_BinFunClos<_Constant,_Expr,typename _Dom::value_type,_Dom>, \
typename _Dom::value_type> \
_Name (const typename _Dom::value_type& __t, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinFunClos<_Constant,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__t, __e (), (_Tp(*)(_Tp, _Tp))(&_Name))); \
} \
\
template<typename _Tp> \
inline _Expr<_BinFunClos<_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
_Name (const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
{ \
typedef _BinFunClos<_ValArray,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__v, __w, (_Tp(*)(_Tp,_Tp))(&_Name))); \
} \
\
template<typename _Tp> \
inline _Expr<_BinFunClos<_ValArray,_Constant,_Tp,_Tp>,_Tp> \
_Name (const valarray<_Tp>& __v, const _Tp& __t) \
{ \
typedef _BinFunClos<_ValArray,_Constant,_Tp,_Tp> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__v, __t, (_Tp(*)(_Tp,_Tp))(&_Name))); \
} \
\
template<typename _Tp> \
inline _Expr<_BinFunClos<_Constant,_ValArray,_Tp,_Tp>,_Tp> \
_Name (const _Tp& __t, const valarray<_Tp>& __v) \
{ \
typedef _BinFunClos<_Constant,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure,_Tp> \
(_Closure (__t, __v, (_Tp(*)(_Tp,_Tp))(&_Name))); \
}
#define _DEFINE_EXPR_BINARY_FUNCTION(_Fun) \
template<class _Dom1, class _Dom2> \
inline _Expr<_BinClos<__##_Fun,_Expr,_Expr,_Dom1,_Dom2>, \
typename _Dom1::value_type> \
_Fun(const _Expr<_Dom1,typename _Dom1::value_type>& __e1, \
const _Expr<_Dom2,typename _Dom2::value_type>& __e2) \
{ \
typedef typename _Dom1::value_type _Tp; \
typedef _BinClos<__##_Fun,_Expr,_Expr,_Dom1,_Dom2> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__e1(), __e2())); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<__##_Fun, _Expr, _ValArray, _Dom, \
typename _Dom::value_type>, \
typename _Dom::value_type> \
_Fun(const _Expr<_Dom,typename _Dom::value_type>& __e, \
const valarray<typename _Dom::value_type>& __v) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinClos<__##_Fun, _Expr, _ValArray, _Dom, _Tp> _Closure;\
return _Expr<_Closure,_Tp>(_Closure(__e(), __v)); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<__##_Fun, _ValArray, _Expr, \
typename _Dom::value_type,_Dom>, \
typename _Dom::value_type> \
_Fun(const valarray<typename _Dom::valarray>& __v, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinClos<__##_Fun,_ValArray,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__v, __e())); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<__##_Fun,_Expr,_Constant,_Dom, \
typename _Dom::value_type>, \
typename _Dom::value_type> \
_Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \
const typename _Dom::value_type& __t) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinClos<__##_Fun,_Expr,_Constant,_Dom,_Tp> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__e(), __t)); \
} \
\
template<class _Dom> \
inline _Expr<_BinClos<__##_Fun,_Constant,_Expr, \
typename _Dom::value_type,_Dom>, \
typename _Dom::value_type> \
_Fun(const typename _Dom::value_type& __t, \
const _Expr<_Dom,typename _Dom::value_type>& __e) \
{ \
typedef typename _Dom::value_type _Tp; \
typedef _BinClos<__##_Fun, _Constant,_Expr,_Tp,_Dom> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__t, __e())); \
} \
\
template<typename _Tp> \
inline _Expr<_BinClos<__##_Fun,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
_Fun(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
{ \
typedef _BinClos<__##_Fun,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__v, __w)); \
} \
\
template<typename _Tp> \
inline _Expr<_BinClos<__##_Fun,_ValArray,_Constant,_Tp,_Tp>,_Tp> \
_Fun(const valarray<_Tp>& __v, const _Tp& __t) \
{ \
typedef _BinClos<__##_Fun,_ValArray,_Constant,_Tp,_Tp> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__v, __t)); \
} \
\
template<typename _Tp> \
inline _Expr<_BinClos<__##_Fun,_Constant,_ValArray,_Tp,_Tp>,_Tp> \
_Fun(const _Tp& __t, const valarray<_Tp>& __v) \
{ \
typedef _BinClos<__##_Fun,_Constant,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure,_Tp>(_Closure(__t, __v)); \
}
_DEFINE_EXPR_BINARY_FUNCTION(atan2)
_DEFINE_EXPR_BINARY_FUNCTION(pow)

View File

@ -45,7 +45,6 @@
#include <cmath>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <algorithm>
namespace std
@ -59,7 +58,7 @@ namespace std
template<class _Oper, template<class, class> class _Meta, class _Dom>
struct _UnClos;
template<template<class> class _Oper,
template<class _Oper,
template<class, class> class _Meta1,
template<class, class> class _Meta2,
class _Dom1, class _Dom2>
@ -80,12 +79,6 @@ namespace std
template<template<class, class> class _Meta, class _Dom>
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
class slice; // BLAS-like slice out of an array
template<class _Tp> class slice_array;
@ -224,27 +217,6 @@ namespace std
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>
inline const _Tp&
@ -486,7 +458,7 @@ namespace std
inline _Tp
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>
@ -611,138 +583,107 @@ namespace std
#define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
template<class _Tp> \
inline valarray<_Tp> & \
valarray<_Tp>::operator _Op##= (const _Tp &__t) \
{ \
_Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, __t); \
inline valarray<_Tp>& \
valarray<_Tp>::operator _Op##=(const _Tp &__t) \
{ \
_Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \
return *this; \
} \
} \
\
template<class _Tp> \
inline valarray<_Tp> & \
valarray<_Tp>::operator _Op##= (const valarray<_Tp> &__v) \
{ \
_Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, \
_Array<_Tp>(__v._M_data)); \
inline valarray<_Tp>& \
valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \
{ \
_Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \
_Array<_Tp>(__v._M_data)); \
return *this; \
}
}
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, plus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, minus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, multiplies)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, divides)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, modulus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, xor)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, and)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, or)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, shift_left)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, shift_right)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left)
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right)
#undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
} // std::
namespace std
{
#define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
template<class _Tp> template<class _Dom> \
inline valarray<_Tp> & \
valarray<_Tp>::operator _Op##= (const _Expr<_Dom,_Tp> &__e) \
{ \
_Array_augmented_##_Name (_Array<_Tp>(_M_data), __e, _M_size); \
inline valarray<_Tp>& \
valarray<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) \
{ \
_Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \
return *this; \
}
}
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, plus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, minus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, multiplies)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, divides)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, modulus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, xor)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, and)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, or)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, shift_left)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, shift_right)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
#undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
#define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
template<typename _Tp> \
inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
{ \
inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, \
typename __fun<_Name, _Tp>::result_type> \
operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
{ \
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> \
inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>, \
typename __fun<_Name, _Tp>::result_type> \
operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \
{ \
typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
typedef typename __fun<_Name, _Tp>::result_type _Rt; \
return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \
} \
\
template<typename _Tp> \
inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \
operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \
inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>, \
typename __fun<_Name, _Tp>::result_type> \
operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \
{ \
typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \
} \
\
template<typename _Tp> \
inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,_Tp> \
operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \
{ \
typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
return _Expr<_Closure, _Tp> (_Closure (__t, __v)); \
typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
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_LOGICAL_OPERATOR(||, logical_or)
_DEFINE_LOGICAL_OPERATOR(==, equal_to)
_DEFINE_LOGICAL_OPERATOR(!=, not_equal_to)
_DEFINE_LOGICAL_OPERATOR(<, less)
_DEFINE_LOGICAL_OPERATOR(>, greater)
_DEFINE_LOGICAL_OPERATOR(<=, less_equal)
_DEFINE_LOGICAL_OPERATOR(>=, greater_equal)
#undef _DEFINE_LOGICAL_OPERATOR
_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)
_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

View File

@ -116,4 +116,27 @@ int main()
v = log(u);
v = log10(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);
}