This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

V3 PATCH: Tidy std::complex<>


This tidies up our implementation of std::complex<>.  This was sitting
in one of my local trees for a year -- before I went to the Santa Cruz
meeting (for precisely that issue).  

Another patch that fixes a PR will followup on this one. 

-- Gaby
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/ChangeLog,v
retrieving revision 1.2207
diff -p -r1.2207 ChangeLog
*** ChangeLog	10 Jan 2004 20:09:25 -0000	1.2207
--- ChangeLog	11 Jan 2004 16:10:58 -0000
***************
*** 1,3 ****
--- 1,16 ----
+ 2004-01-11  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+ 
+ 	* include/std/std_complex.h (std::complex<>::real): Return a
+ 	reference. Add non-const overload.
+ 	(std::complex<>::real): Likewise.
+ 	(std::real): Likewise.
+ 	(std::imag): Likewise.
+ 	(std::operator+): Tidy.
+ 	(std::operator-): Likewise.
+ 	(std::operator*): Likewise.
+ 	(std::operator/): Likewise.
+ 	(std::operator>>): Likewise.
+ 
  2004-01-10  Paolo Carlini  <pcarlini@suse.de>
  
  	* docs/html/ext/lwg-active.html, docs/html/ext/lwg-defects.html:
Index: include/std/std_complex.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_complex.h,v
retrieving revision 1.10
diff -p -r1.10 std_complex.h
*** include/std/std_complex.h	23 Jul 2003 15:28:43 -0000	1.10
--- include/std/std_complex.h	11 Jan 2004 16:10:58 -0000
***************
*** 1,6 ****
  // The template and inlines for the -*- C++ -*- complex number classes.
  
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
  // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
--- 1,6 ----
  // The template and inlines for the -*- C++ -*- complex number classes.
  
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
  // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
*************** namespace std
*** 96,104 ****
        // complex (const complex<_Tp>&);
        template<typename _Up>
          complex(const complex<_Up>&);
!         
!       _Tp real() const;
!       _Tp imag() const;
  
        complex<_Tp>& operator=(const _Tp&);
        complex<_Tp>& operator+=(const _Tp&);
--- 96,106 ----
        // complex (const complex<_Tp>&);
        template<typename _Up>
          complex(const complex<_Up>&);
! 
!       _Tp& real(); 
!       const _Tp& real() const;
!       _Tp& imag();
!       const _Tp& imag() const;
  
        complex<_Tp>& operator=(const _Tp&);
        complex<_Tp>& operator+=(const _Tp&);
*************** namespace std
*** 121,135 ****
          complex<_Tp>& operator/=(const complex<_Up>&);
  
      private:
!       _Tp _M_real, _M_imag;
      };
  
    template<typename _Tp>
!     inline _Tp
      complex<_Tp>::real() const { return _M_real; }
  
    template<typename _Tp>
!     inline _Tp
      complex<_Tp>::imag() const { return _M_imag; }
  
    template<typename _Tp>
--- 123,146 ----
          complex<_Tp>& operator/=(const complex<_Up>&);
  
      private:
!       _Tp _M_real;
!       _Tp _M_imag;
      };
  
    template<typename _Tp>
!     inline _Tp&
!     complex<_Tp>::real() { return _M_real; }
! 
!   template<typename _Tp>
!     inline const _Tp&
      complex<_Tp>::real() const { return _M_real; }
  
    template<typename _Tp>
!     inline _Tp&
!     complex<_Tp>::imag() { return _M_imag; }
! 
!   template<typename _Tp>
!     inline const _Tp&
      complex<_Tp>::imag() const { return _M_imag; }
  
    template<typename _Tp>
*************** namespace std
*** 253,314 ****
    template<typename _Tp>
      inline complex<_Tp>
      operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__x) += __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator+(const complex<_Tp>& __x, const _Tp& __y)
!     { return complex<_Tp> (__x) += __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator+(const _Tp& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__y) += __x; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__x) -= __y; }
      
    template<typename _Tp>
      inline complex<_Tp>
      operator-(const complex<_Tp>& __x, const _Tp& __y)
!     { return complex<_Tp> (__x) -= __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator-(const _Tp& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__x) -= __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__x) *= __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator*(const complex<_Tp>& __x, const _Tp& __y)
!     { return complex<_Tp> (__x) *= __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator*(const _Tp& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__y) *= __x; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__x) /= __y; }
      
    template<typename _Tp>
      inline complex<_Tp>
      operator/(const complex<_Tp>& __x, const _Tp& __y)
!     { return complex<_Tp> (__x) /= __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator/(const _Tp& __x, const complex<_Tp>& __y)
!     { return complex<_Tp> (__x) /= __y; }
  
    template<typename _Tp>
      inline complex<_Tp>
--- 264,373 ----
    template<typename _Tp>
      inline complex<_Tp>
      operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r += __y;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator+(const complex<_Tp>& __x, const _Tp& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r.real() += __y;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator+(const _Tp& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r = __y;
!       __r.real() += __x;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r -= __y;
!       return __r;
!     }
      
    template<typename _Tp>
      inline complex<_Tp>
      operator-(const complex<_Tp>& __x, const _Tp& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r.real() -= __y;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator-(const _Tp& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r(__x, -__y.imag());
!       __r.real() -= __y.real();
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r *= __y;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator*(const complex<_Tp>& __x, const _Tp& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r *= __y;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator*(const _Tp& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r = __y;
!       __r *= __x;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r /= __y;
!       return __r;
!     }
      
    template<typename _Tp>
      inline complex<_Tp>
      operator/(const complex<_Tp>& __x, const _Tp& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r /= __y;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
      operator/(const _Tp& __x, const complex<_Tp>& __y)
!     {
!       complex<_Tp> __r = __x;
!       __r /= __y;
!       return __r;
!     }
  
    template<typename _Tp>
      inline complex<_Tp>
*************** namespace std
*** 369,375 ****
  		__is.setstate(ios_base::failbit);
  	    }
  	  else if (__ch == ')') 
! 	    __x = complex<_Tp>(__re_x, _Tp(0));
  	  else
  	    __is.setstate(ios_base::failbit);
  	}
--- 428,434 ----
  		__is.setstate(ios_base::failbit);
  	    }
  	  else if (__ch == ')') 
! 	    __x = __re_x;
  	  else
  	    __is.setstate(ios_base::failbit);
  	}
*************** namespace std
*** 377,383 ****
  	{
  	  __is.putback(__ch);
  	  __is >> __re_x;
! 	  __x = complex<_Tp>(__re_x, _Tp(0));
  	}
        return __is;
      }
--- 436,442 ----
  	{
  	  __is.putback(__ch);
  	  __is >> __re_x;
! 	  __x = __re_x;
  	}
        return __is;
      }
*************** namespace std
*** 396,407 ****
  
    // Values
    template<typename _Tp>
!     inline _Tp
      real(const complex<_Tp>& __z)
      { return __z.real(); }
      
    template<typename _Tp>
!     inline _Tp
      imag(const complex<_Tp>& __z)
      { return __z.imag(); }
  
--- 455,476 ----
  
    // Values
    template<typename _Tp>
!     inline _Tp&
!     real(complex<_Tp>& __z)
!     { return __z.real(); }
!     
!   template<typename _Tp>
!     inline const _Tp&
      real(const complex<_Tp>& __z)
      { return __z.real(); }
      
    template<typename _Tp>
!     inline _Tp&
!     imag(complex<_Tp>& __z)
!     { return __z.imag(); }
!     
!   template<typename _Tp>
!     inline const _Tp&
      imag(const complex<_Tp>& __z)
      { return __z.imag(); }
  
*************** namespace std
*** 605,612 ****
      explicit complex(const complex<double>&);
      explicit complex(const complex<long double>&);
  
!     float real() const;
!     float imag() const;
  
      complex<float>& operator=(float);
      complex<float>& operator+=(float);
--- 674,683 ----
      explicit complex(const complex<double>&);
      explicit complex(const complex<long double>&);
  
!     float& real();
!     const float& real() const;
!     float& imag();
!     const float& imag() const;
  
      complex<float>& operator=(float);
      complex<float>& operator+=(float);
*************** namespace std
*** 638,648 ****
      friend class complex<long double>;
    };
  
!   inline float
    complex<float>::real() const
    { return __real__ _M_value; }
  
!   inline float
    complex<float>::imag() const
    { return __imag__ _M_value; }
  
--- 709,727 ----
      friend class complex<long double>;
    };
  
!   inline float&
!   complex<float>::real()
!   { return __real__ _M_value; }
! 
!   inline const float&
    complex<float>::real() const
    { return __real__ _M_value; }
  
!   inline float&
!   complex<float>::imag()
!   { return __imag__ _M_value; }
! 
!   inline const float&
    complex<float>::imag() const
    { return __imag__ _M_value; }
  
*************** namespace std
*** 751,759 ****
  #endif
      complex(const complex<float>&);
      explicit complex(const complex<long double>&);
!         
!     double real() const;
!     double imag() const;
          
      complex<double>& operator=(double);
      complex<double>& operator+=(double);
--- 830,840 ----
  #endif
      complex(const complex<float>&);
      explicit complex(const complex<long double>&);
! 
!     double& real();
!     const double& real() const;
!     double& imag();
!     const double& imag() const;
          
      complex<double>& operator=(double);
      complex<double>& operator+=(double);
*************** namespace std
*** 784,794 ****
      friend class complex<long double>;
    };
  
!   inline double
    complex<double>::real() const
    { return __real__ _M_value; }
  
!   inline double
    complex<double>::imag() const
    { return __imag__ _M_value; }
  
--- 865,883 ----
      friend class complex<long double>;
    };
  
!   inline double&
!   complex<double>::real()
!   { return __real__ _M_value; }
! 
!   inline const double&
    complex<double>::real() const
    { return __real__ _M_value; }
  
!   inline double&
!   complex<double>::imag()
!   { return __imag__ _M_value; }
! 
!   inline const double&
    complex<double>::imag() const
    { return __imag__ _M_value; }
  
*************** namespace std
*** 898,905 ****
      complex(const complex<float>&);
      complex(const complex<double>&);
  
!     long double real() const;
!     long double imag() const;
  
      complex<long double>& operator= (long double);
      complex<long double>& operator+= (long double);
--- 987,996 ----
      complex(const complex<float>&);
      complex(const complex<double>&);
  
!     long double& real();
!     const long double& real() const;
!     long double& imag();
!     const long double& imag() const;
  
      complex<long double>& operator= (long double);
      complex<long double>& operator+= (long double);
*************** namespace std
*** 937,947 ****
      __imag__ _M_value = __i;
    }
  
!   inline long double
    complex<long double>::real() const
    { return __real__ _M_value; }
  
!   inline long double
    complex<long double>::imag() const
    { return __imag__ _M_value; }
  
--- 1028,1046 ----
      __imag__ _M_value = __i;
    }
  
!   inline long double&
!   complex<long double>::real()
!   { return __real__ _M_value; }
! 
!   inline const long double&
    complex<long double>::real() const
    { return __real__ _M_value; }
  
!   inline long double&
!   complex<long double>::imag()
!   { return __imag__ _M_value; }
! 
!   inline const long double&
    complex<long double>::imag() const
    { return __imag__ _M_value; }
  


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