This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Valarray PATCH: Fix 7215


This patchlet fixes PR/7215.  The same treatment should be applied to
the binary functions.  Patch to that effect will come later.

Bootstrapped and tested on an i686-pc-linux-gnu.
Applied to mainline.

-- Gaby

2002-07-10  Gabriel Dos Reis  <gdr@nerim.net>

	* include/bits/valarray_meta.h (_UnFunBase): Take a second
	template parameter. Remove _M_func data member.
	(_UnFunClos): Take a third template parameter.
	(__abs, __cos, __acos, __cosh, __sin, __asin, __sinh, __tan,
	__atan, __tanh, __exp, __log, __log10, __sqrt): New classes.
	(_DEFINE_EXPR_UNARY_OPERATOR): Adjust definition.

Index: include/bits/valarray_meta.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/valarray_meta.h,v
retrieving revision 1.7
diff -p -r1.7 valarray_meta.h
*** include/bits/valarray_meta.h	16 Jan 2002 19:57:31 -0000	1.7
--- include/bits/valarray_meta.h	10 Jul 2002 11:57:06 -0000
*************** namespace std
*** 58,98 ****
      //
      // Unary function application closure.
      //
!     template<class _Dom> class _UnFunBase {
      public:
!         typedef typename _Dom::value_type value_type;
!         typedef value_type _Vt;
!         
!         _UnFunBase (const _Dom& __e, _Vt __f(_Vt))
!                 : _M_expr(__e), _M_func(__f) {}
!         
!         _Vt operator[] (size_t __i) const { return _M_func(_M_expr[__i]); }
!         size_t size () const { return _M_expr.size(); }
!         
!     private:
!         const _Dom& _M_expr;
!         _Vt (*_M_func)(_Vt);
!     };
  
!     template<template<class, class> class _Meta, class _Dom>
!         class _UnFunClos;
      
!     template<class _Dom>
!     struct _UnFunClos<_Expr,_Dom> : _UnFunBase<_Dom> {
!         typedef _UnFunBase<_Dom> _Base;
!         typedef typename _Base::value_type value_type;
!         
!         _UnFunClos (const _Dom& __e, value_type __f(value_type))
!                 : _Base (__e, __f) {}
      };
      
!     template<typename _Tp>
!     struct _UnFunClos<_ValArray,_Tp> : _UnFunBase<valarray<_Tp> > {
!         typedef _UnFunBase<valarray<_Tp> > _Base;
!         typedef typename _Base::value_type value_type;
!         
!         _UnFunClos (const valarray<_Tp>& __v, _Tp __f(_Tp))
!                 : _Base (__v, __f) {}
      };
  
      //
--- 58,189 ----
      //
      // Unary function application closure.
      //
!     template<class _Dom, typename _Op> class _UnFunBase
!     {
      public:
!       typedef typename _Dom::value_type value_type;
!       typedef value_type _Vt;
!       
!       explicit _UnFunBase (const _Dom& __e) : _M_expr(__e) {}
!       
!       _Vt operator[] (size_t __i) const { return _Op()(_M_expr[__i]); }
!       size_t size () const { return _M_expr.size(); }
!       
!     private:
!       const _Dom& _M_expr;
!     };
! 
!   // Implementations of unary functions applied to valarray<>s.
!   // I use hard-coded object functions here instead of a generic
!   // approach like pointers to function:
!   //    1) correctness: some functions take references, others values.
!   //       we can't deduce the correct type afterwards.
!   //    2) efficiency -- object functions can be easily inlined
!   //    3) be Koenig-lookup-friendly
! 
!   struct __abs
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return abs(__t); }
!   };
! 
!   struct __cos
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return cos(__t); }
!   };
! 
!   struct __acos
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return acos(__t); }
!   };
! 
!   struct __cosh
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return cosh(__t); }
!   };
! 
!   struct __sin
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return sin(__t); }
!   };
! 
!   struct __asin
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return asin(__t); }
!   };
! 
!   struct __sinh
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return sinh(__t); }
!   };
! 
!   struct __tan
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return tan(__t); }
!   };
  
!   struct __atan
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return atan(__t); }
!   };
! 
!   struct __tanh
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return tanh(__t); }
!   };
! 
!   struct __exp
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return exp(__t); }
!   };
! 
!   struct __log
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return log(__t); }
!   };
! 
!   struct __log10
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return log10(__t); }
!   };
! 
!   struct __sqrt
!   {
!     template<typename _Tp>
!       _Tp operator()(const _Tp& __t) const { return sqrt(__t); }
!   };
! 
!   template<template<class, class> class _Meta, class _Dom, typename _Op>
!     class _UnFunClos;
      
!   template<class _Dom, typename _Op>
!     struct _UnFunClos<_Expr,_Dom, _Op> : _UnFunBase<_Dom, _Op>
!     {
!       typedef _UnFunBase<_Dom, _Op> _Base;
!       typedef typename _Base::value_type value_type;
! 
!       explicit _UnFunClos (const _Dom& __e) : _Base (__e) {}
      };
      
!   template<typename _Tp, typename _Op>
!     struct _UnFunClos<_ValArray,_Tp, _Op> : _UnFunBase<valarray<_Tp>, _Op>
!     {
!       typedef _UnFunBase<valarray<_Tp>, _Op> _Base;
!       typedef typename _Base::value_type value_type;
! 
!       explicit _UnFunClos (const valarray<_Tp>& __v) : _Base (__v) {}
      };
  
      //
*************** operator _Op (const valarray<typename _D
*** 938,957 ****
  
  #define _DEFINE_EXPR_UNARY_FUNCTION(_Name)                              \
  template<class _Dom>                                                    \
! inline _Expr<_UnFunClos<_Expr,_Dom>,typename _Dom::value_type>          \
  _Name(const _Expr<_Dom,typename _Dom::value_type>& __e)                 \
  {                                                                       \
      typedef typename _Dom::value_type _Tp;                              \
!     typedef _UnFunClos<_Expr,_Dom> _Closure;                            \
!     return _Expr<_Closure,_Tp>(_Closure(__e(), (_Tp(*)(_Tp))(&_Name))); \
  }                                                                       \
                                                                          \
  template<typename _Tp>                                                  \
! inline _Expr<_UnFunClos<_ValArray,_Tp>,_Tp>                             \
  _Name(const valarray<_Tp>& __v)                                         \
  {                                                                       \
!     typedef _UnFunClos<_ValArray,_Tp> _Closure;                         \
!     return _Expr<_Closure,_Tp> (_Closure (__v, (_Tp(*)(_Tp))(&_Name))); \
  }
  
  
--- 1029,1048 ----
  
  #define _DEFINE_EXPR_UNARY_FUNCTION(_Name)                              \
  template<class _Dom>                                                    \
! inline _Expr<_UnFunClos<_Expr,_Dom,__##_Name>,typename _Dom::value_type>\
  _Name(const _Expr<_Dom,typename _Dom::value_type>& __e)                 \
  {                                                                       \
      typedef typename _Dom::value_type _Tp;                              \
!     typedef _UnFunClos<_Expr,_Dom,__##_Name> _Closure;                  \
!     return _Expr<_Closure,_Tp>(_Closure(__e()));                        \
  }                                                                       \
                                                                          \
  template<typename _Tp>                                                  \
! inline _Expr<_UnFunClos<_ValArray,_Tp,__##_Name>,_Tp>                   \
  _Name(const valarray<_Tp>& __v)                                         \
  {                                                                       \
!     typedef _UnFunClos<_ValArray,_Tp,__##_Name> _Closure;               \
!     return _Expr<_Closure,_Tp>(_Closure (__v));                         \
  }
  
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]