Commit ffcec5c8 by Jerry Quinn

codecvt.h, [...]: Document.

2003-01-26  Jerry Quinn  <jlquinn@optonline.net>

	* include/bits/codecvt.h, include/bits/locale_facets.h,
	include/bits/postypes.h, include/bits/stl_bvector.h,
	include/bits/stl_multiset.h, include/bits/stl_set.h,
	include/bits/stream_iterator.h, include/bits/streambuf_iterator.h,
	include/std/std_complex.h:  Document.

From-SVN: r76688
parent 1c62e7b2
// Locale support (codecvt) -*- C++ -*-
// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
// Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
......@@ -44,6 +44,7 @@
#pragma GCC system_header
// 22.2.1.5 Template class codecvt
/// Base class for codecvt facet providing conversion result enum.
class codecvt_base
{
public:
......@@ -60,6 +61,15 @@
// NB: An abstract base class that fills in the public inlines, so
// that the specializations don't have to re-copy the public
// interface.
/**
* @brief Common base for codecvt facet
*
* This template class provides implementations of the public functions
* that forward to the protected virtual functions.
*
* This template also provides abstract stubs for the protected virtual
* functions.
*/
template<typename _InternT, typename _ExternT, typename _StateT>
class __codecvt_abstract_base
: public locale::facet, public codecvt_base
......@@ -72,6 +82,41 @@
typedef _StateT state_type;
// 22.2.1.5.1 codecvt members
/**
* @brief Convert from internal to external character set.
*
* Converts input string of intern_type to output string of
* extern_type. This is analogous to wcsrtombs. It does this by
* calling codecvt::do_out.
*
* The source and destination character sets are determined by the
* facet's locale, internal and external types.
*
* The characters in [from,from_end) are converted and written to
* [to,to_end). from_next and to_next are set to point to the
* character following the last successfully converted character,
* respectively. If the result needed no conversion, from_next and
* to_next are not affected.
*
* The @a state argument should be intialized if the input is at the
* beginning and carried from a previous call if continuing
* conversion. There are no guarantees about how @a state is used.
*
* The result returned is a member of codecvt_base::result. If all the
* input is converted, returns codecvt_base::ok. If no conversion is
* necessary, returns codecvt_base::noconv. If the input ends early or
* there is insufficient space in the output, returns codecvt_base::partial.
* Otherwise the conversion failed and codecvt_base::error is returned.
*
* @param state Persistent conversion state data.
* @param from Start of input.
* @param from_end End of input.
* @param from_next Returns start of unconverted data.
* @param to Start of output buffer.
* @param to_end End of output buffer.
* @param to_next Returns start of unused output area.
* @return codecvt_base::result.
*/
result
out(state_type& __state, const intern_type* __from,
const intern_type* __from_end, const intern_type*& __from_next,
......@@ -82,11 +127,75 @@
__to, __to_end, __to_next);
}
/**
* @brief Reset conversion state.
*
* Writes characters to output that would restore @a state to initial
* conditions. The idea is that if a partial conversion occurs, then
* the converting the characters written by this function would leave
* the state in initial conditions, rather than partial conversion
* state. It does this by calling codecvt::do_unshift().
*
* For example, if 4 external characters always converted to 1 internal
* character, and input to in() had 6 external characters with state
* saved, this function would write two characters to the output and
* set the state to initialized conditions.
*
* The source and destination character sets are determined by the
* facet's locale, internal and external types.
*
* The result returned is a member of codecvt_base::result. If the
* state could be reset and data written, returns codecvt_base::ok. If
* no conversion is necessary, returns codecvt_base::noconv. If the
* output has insufficient space, returns codecvt_base::partial.
* Otherwise the reset failed and codecvt_base::error is returned.
*
* @param state Persistent conversion state data.
* @param to Start of output buffer.
* @param to_end End of output buffer.
* @param to_next Returns start of unused output area.
* @return codecvt_base::result.
*/
result
unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
extern_type*& __to_next) const
{ return this->do_unshift(__state, __to,__to_end,__to_next); }
/**
* @brief Convert from external to internal character set.
*
* Converts input string of extern_type to output string of
* intern_type. This is analogous to mbsrtowcs. It does this by
* calling codecvt::do_in.
*
* The source and destination character sets are determined by the
* facet's locale, internal and external types.
*
* The characters in [from,from_end) are converted and written to
* [to,to_end). from_next and to_next are set to point to the
* character following the last successfully converted character,
* respectively. If the result needed no conversion, from_next and
* to_next are not affected.
*
* The @a state argument should be intialized if the input is at the
* beginning and carried from a previous call if continuing
* conversion. There are no guarantees about how @a state is used.
*
* The result returned is a member of codecvt_base::result. If all the
* input is converted, returns codecvt_base::ok. If no conversion is
* necessary, returns codecvt_base::noconv. If the input ends early or
* there is insufficient space in the output, returns codecvt_base::partial.
* Otherwise the conversion failed and codecvt_base::error is returned.
*
* @param state Persistent conversion state data.
* @param from Start of input.
* @param from_end End of input.
* @param from_next Returns start of unconverted data.
* @param to Start of output buffer.
* @param to_end End of output buffer.
* @param to_next Returns start of unused output area.
* @return codecvt_base::result.
*/
result
in(state_type& __state, const extern_type* __from,
const extern_type* __from_end, const extern_type*& __from_next,
......@@ -121,6 +230,13 @@
virtual
~__codecvt_abstract_base() { }
/**
* @brief Convert from internal to external character set.
*
* Converts input string of intern_type to output string of
* extern_type. This function is a hook for derived classes to change
* the value returned. @see out for more information.
*/
virtual result
do_out(state_type& __state, const intern_type* __from,
const intern_type* __from_end, const intern_type*& __from_next,
......
......@@ -4462,6 +4462,8 @@ namespace std
// NB: These are inline because, when used in a loop, some compilers
// can hoist the body out of the loop; then it's just as fast as the
// C is*() function.
//@{
/// Convenience interface to ctype.is().
template<typename _CharT>
inline bool
isspace(_CharT __c, const locale& __loc)
......@@ -4525,6 +4527,7 @@ namespace std
inline _CharT
tolower(_CharT __c, const locale& __loc)
{ return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
//@}
} // namespace std
#endif
// Position types -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -64,6 +64,7 @@ namespace std
typedef long long __streamoff_base_type;
#endif
/// Integral type for I/O operation counts and buffer sizes.
typedef ptrdiff_t streamsize; // Signed integral type
template<typename _StateT>
......@@ -127,19 +128,30 @@ namespace std
}
};
// In clauses 21.1.3.1 and 27.4.1 streamoff is described as an
// implementation defined type. In this implementation it is a
// distinct class type.
// Note: In versions of GCC up to and including GCC 3.3, streamoff
// was typedef long.
/**
* @brief Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
*
* @if maint
* In clauses 21.1.3.1 and 27.4.1 streamoff is described as an
* implementation defined type. In this implementation it is a
* distinct class type.
* Note: In versions of GCC up to and including GCC 3.3, streamoff
* was typedef long.
* @endif
*/
typedef class streamoff streamoff;
// The standard fails to place any requiremens on the template
// argument StateT. In this implementation StateT must be
// DefaultConstructible, CopyConstructible and Assignable. The
// standard only requires that fpos should contain a member of type
// StateT. In this implementation it also contains an offset stored
// as a signed integer.
/**
* @brief Class representing stream positions.
*
* The standard places no requirements upon the template parameter StateT.
* In this implementation StateT must be DefaultConstructible,
* CopyConstructible and Assignable. The standard only requires that fpos
* should contain a member of type StateT. In this implementation it also
* contains an offset stored as a signed integer.
*
* @param StateT Type passed to and returned from state().
*/
template<typename _StateT>
class fpos
{
......@@ -161,6 +173,7 @@ namespace std
// fpos, but gives no meaningful semantics for this
// conversion. In this implementation this constructor stores
// the integer as the offset and default constructs the state.
/// Construct position from integer.
fpos(__streamoff_base_type __off)
: _M_off(__off), _M_state() { }
......@@ -170,13 +183,16 @@ namespace std
// implementation implicit conversion is also allowed, and this
// constructor stores the streamoff as the offset and default
// constructs the state.
/// Construct position from offset.
fpos(const streamoff& __off)
: _M_off(__off), _M_state() { }
/// Remember the value of @a st.
void
state(_StateT __st)
{ _M_state = __st; }
/// Return the last set value of @a st.
_StateT
state() const
{ return _M_state; }
......@@ -185,10 +201,12 @@ namespace std
// equivalence relation. In this implementation two fpos<StateT>
// objects belong to the same equivalence class if the contained
// offsets compare equal.
/// Test if equivalent to another position.
bool
operator==(const fpos& __other) const
{ return _M_off == __other._M_off; }
/// Test if not equivalent to another position.
bool
operator!=(const fpos& __other) const
{ return _M_off != __other._M_off; }
......@@ -196,6 +214,7 @@ namespace std
// The standard requires that this operator must be defined, but
// gives no semantics. In this implemenation it just adds it's
// argument to the stored offset and returns *this.
/// Add offset to this position.
fpos&
operator+=(const streamoff& __off)
{
......@@ -206,6 +225,7 @@ namespace std
// The standard requires that this operator must be defined, but
// gives no semantics. In this implemenation it just subtracts
// it's argument from the stored offset and returns *this.
/// Subtract offset from this position.
fpos&
operator-=(const streamoff& __off)
{
......@@ -218,6 +238,7 @@ namespace std
// implementation it constructs a copy of *this, adds the
// argument to that copy using operator+= and then returns the
// copy.
/// Add position and offset.
fpos
operator+(const streamoff& __off) const
{
......@@ -231,6 +252,7 @@ namespace std
// implementation it constructs a copy of *this, subtracts the
// argument from that copy using operator-= and then returns the
// copy.
/// Subtract offset from position.
fpos
operator-(const streamoff& __off) const
{
......@@ -243,11 +265,13 @@ namespace std
// defines it's semantics only in terms of operator+. In this
// implementation it returns the difference between the offset
// stored in *this and in the argument.
/// Subtract position to return offset.
streamoff
operator-(const fpos& __other) const
{ return _M_off - __other._M_off; }
};
/// Construct offset from position.
template<typename _StateT>
inline
streamoff::streamoff(const fpos<_StateT>& __pos)
......@@ -256,7 +280,9 @@ namespace std
// Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos
// as implementation defined types, but clause 27.2 requires that
// they must both be typedefs for fpos<mbstate_t>
/// File position for char streams.
typedef fpos<mbstate_t> streampos;
/// File position for wchar_t streams.
typedef fpos<mbstate_t> wstreampos;
} // namespace std
......
// bit_vector and vector<bool> specialization -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
......@@ -296,6 +296,24 @@ protected:
#include <bits/stl_vector.h>
namespace __gnu_norm
{
/**
* @brief A specialization of vector for booleans which offers fixed time
* access to individual elements in any order.
*
* Note that vector<bool> does not actually meet the requirements for being
* a container. This is because the reference and pointer types are not
* really references and pointers to bool. See DR96 for details. @see
* vector for function documentation.
*
* @ingroup Containers
* @ingroup Sequences
*
* In some terminology a %vector can be described as a dynamic C-style array,
* it offers fast and efficient access to individual elements in any order
* and saves the user from worrying about memory and size allocation.
* Subscripting ( @c [] ) access is also provided as with C-style arrays.
*/
template <typename _Alloc>
class vector<bool, _Alloc> : public _Bvector_base<_Alloc>
{
......
// Stream iterators
// Copyright (C) 2001 Free Software Foundation, Inc.
// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
......@@ -41,6 +41,7 @@
namespace std
{
/// Provides input iterator semantics for streams.
template<typename _Tp, typename _CharT = char,
typename _Traits = char_traits<_CharT>, typename _Dist = ptrdiff_t>
class istream_iterator
......@@ -56,9 +57,11 @@ namespace std
_Tp _M_value;
bool _M_ok;
public:
public:
/// Construct end of input stream iterator.
istream_iterator() : _M_stream(0), _M_ok(false) {}
/// Construct start of input stream iterator.
istream_iterator(istream_type& __s) : _M_stream(&__s) { _M_read(); }
istream_iterator(const istream_iterator& __obj)
......@@ -116,12 +119,14 @@ namespace std
}
};
/// Return true if x and y are both end or not end, or x and y are the same.
template<typename _Tp, typename _CharT, typename _Traits, typename _Dist>
inline bool
operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y)
{ return __x._M_equal(__y); }
/// Return false if x and y are both end or not end, or x and y are the same.
template <class _Tp, class _CharT, class _Traits, class _Dist>
inline bool
operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
......@@ -129,29 +134,57 @@ namespace std
{ return !__x._M_equal(__y); }
/**
* @brief Provides output iterator semantics for streams.
*
* This class provides an iterator to write to an ostream. The type Tp is
* the only type written by this iterator and there must be an
* operator<<(Tp) defined.
*
* @param Tp The type to write to the ostream.
* @param CharT The ostream char_type.
* @param Traits The ostream char_traits.
*/
template<typename _Tp, typename _CharT = char,
typename _Traits = char_traits<_CharT> >
class ostream_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
public:
//@{
/// Public typedef
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
//@}
private:
ostream_type* _M_stream;
const _CharT* _M_string;
public:
/// Construct from an ostream.
ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {}
/**
* Construct from an ostream.
*
* The delimiter string @a c is written to the stream after every Tp
* written to the stream. The delimiter is not copied, and thus must
* not be destroyed while this iterator is in use.
*
* @param s Underlying ostream to write to.
* @param c CharT delimiter string to insert.
*/
ostream_iterator(ostream_type& __s, const _CharT* __c)
: _M_stream(&__s), _M_string(__c) { }
/// Copy constructor.
ostream_iterator(const ostream_iterator& __obj)
: _M_stream(__obj._M_stream), _M_string(__obj._M_string) { }
/// Writes @a value to underlying ostream using operator<<. If
/// constructed with delimiter string, writes delimiter to ostream.
ostream_iterator&
operator=(const _Tp& __value)
{
......
// Streambuf iterators
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// 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
......@@ -46,6 +46,7 @@
namespace std
{
// 24.5.3 Template class istreambuf_iterator
/// Provides input iterator semantics for streambufs.
template<typename _CharT, typename _Traits>
class istreambuf_iterator
: public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
......@@ -53,11 +54,14 @@ namespace std
{
public:
// Types:
//@{
/// Public typedefs
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename _Traits::int_type int_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_istream<_CharT, _Traits> istream_type;
//@}
private:
// 24.5.3 istreambuf_iterator
......@@ -71,16 +75,21 @@ namespace std
int_type _M_c;
public:
/// Construct end of input stream iterator.
istreambuf_iterator() throw()
: _M_sbuf(0), _M_c(traits_type::eof()) { }
/// Construct start of input stream iterator.
istreambuf_iterator(istream_type& __s) throw()
: _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
/// Construct start of streambuf iterator.
istreambuf_iterator(streambuf_type* __s) throw()
: _M_sbuf(__s), _M_c(traits_type::eof()) { }
// NB: The result of operator*() on an end of stream is undefined.
/// Return the current character pointed to by iterator. This returns
/// streambuf.sgetc(). It cannot be assigned. NB: The result of
/// operator*() on an end of stream is undefined.
char_type
operator*() const
{
......@@ -93,7 +102,8 @@ namespace std
#endif
return traits_type::to_char_type(_M_get());
}
/// Advance the iterator. Calls streambuf.sbumpc().
istreambuf_iterator&
operator++()
{
......@@ -108,6 +118,7 @@ namespace std
return *this;
}
/// Advance the iterator. Calls streambuf.sbumpc().
istreambuf_iterator
operator++(int)
{
......@@ -129,6 +140,7 @@ namespace std
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 110 istreambuf_iterator::equal not const
// NB: there is also number 111 (NAD, Future) pending on this function.
/// Return true both iterators are end or both are not end.
bool
equal(const istreambuf_iterator& __b) const
{
......@@ -174,28 +186,35 @@ namespace std
const istreambuf_iterator<_CharT, _Traits>& __b)
{ return !__a.equal(__b); }
/// Provides output iterator semantics for streambufs.
template<typename _CharT, typename _Traits>
class ostreambuf_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
public:
// Types:
//@{
/// Public typedefs
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
//@}
private:
streambuf_type* _M_sbuf;
bool _M_failed;
public:
/// Construct output iterator from ostream.
ostreambuf_iterator(ostream_type& __s) throw ()
: _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
/// Construct output iterator from streambuf.
ostreambuf_iterator(streambuf_type* __s) throw ()
: _M_sbuf(__s), _M_failed(!_M_sbuf) { }
/// Write character to streambuf. Calls streambuf.sputc().
ostreambuf_iterator&
operator=(_CharT __c)
{
......@@ -205,18 +224,22 @@ namespace std
return *this;
}
/// Return *this.
ostreambuf_iterator&
operator*()
{ return *this; }
/// Return *this.
ostreambuf_iterator&
operator++(int)
{ return *this; }
/// Return *this.
ostreambuf_iterator&
operator++()
{ return *this; }
/// Return true if previous operator=() failed.
bool
failed() const throw()
{ return _M_failed; }
......
......@@ -58,67 +58,113 @@ namespace std
template<> class complex<double>;
template<> class complex<long double>;
/// Return magnitude of @a z.
template<typename _Tp> _Tp abs(const complex<_Tp>&);
/// Return phase angle of @a z.
template<typename _Tp> _Tp arg(const complex<_Tp>&);
/// Return @a z magnitude squared.
template<typename _Tp> _Tp norm(const complex<_Tp>&);
/// Return complex conjugate of @a z.
template<typename _Tp> complex<_Tp> conj(const complex<_Tp>&);
/// Return complex with magnitude @a rho and angle @a theta.
template<typename _Tp> complex<_Tp> polar(const _Tp&, const _Tp& = 0);
// Transcendentals:
/// Return complex cosine of @a z.
template<typename _Tp> complex<_Tp> cos(const complex<_Tp>&);
/// Return complex hyperbolic cosine of @a z.
template<typename _Tp> complex<_Tp> cosh(const complex<_Tp>&);
/// Return complex base e exponential of @a z.
template<typename _Tp> complex<_Tp> exp(const complex<_Tp>&);
/// Return complex natural logarithm of @a z.
template<typename _Tp> complex<_Tp> log(const complex<_Tp>&);
/// Return complex base 10 logarithm of @a z.
template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&);
/// Return complex cosine of @a z.
template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int);
/// Return @a x to the @a y'th power.
template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&);
/// Return @a x to the @a y'th power.
template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&,
const complex<_Tp>&);
/// Return @a x to the @a y'th power.
template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&);
/// Return complex sine of @a z.
template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&);
/// Return complex hyperbolic sine of @a z.
template<typename _Tp> complex<_Tp> sinh(const complex<_Tp>&);
/// Return complex square root of @a z.
template<typename _Tp> complex<_Tp> sqrt(const complex<_Tp>&);
/// Return complex tangent of @a z.
template<typename _Tp> complex<_Tp> tan(const complex<_Tp>&);
/// Return complex hyperbolic tangent of @a z.
template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&);
//@}
// 26.2.2 Primary template class complex
/**
* Template to represent complex numbers.
*
* Specializations for float, double, and long double are part of the
* library. Results with any other type are not guaranteed.
*
* @param Tp Type of real and imaginary values.
*/
template<typename _Tp>
class complex
{
public:
/// Value typedef.
typedef _Tp value_type;
/// Default constructor. First parameter is x, second parameter is y.
/// Unspecified parameters default to 0.
complex(const _Tp& = _Tp(), const _Tp & = _Tp());
// Let's the compiler synthetize the copy constructor
// Lets the compiler synthesize the copy constructor
// complex (const complex<_Tp>&);
/// Copy constructor.
template<typename _Up>
complex(const complex<_Up>&);
/// Return real part of complex number.
_Tp& real();
/// Return real part of complex number.
const _Tp& real() const;
/// Return imaginary part of complex number.
_Tp& imag();
/// Return imaginary part of complex number.
const _Tp& imag() const;
/// Assign this complex number to scalar @a t.
complex<_Tp>& operator=(const _Tp&);
/// Add @a t to this complex number.
complex<_Tp>& operator+=(const _Tp&);
/// Subtract @a t from this complex number.
complex<_Tp>& operator-=(const _Tp&);
/// Multiply this complex number by @a t.
complex<_Tp>& operator*=(const _Tp&);
/// Divide this complex number by @a t.
complex<_Tp>& operator/=(const _Tp&);
// Let's the compiler synthetize the
// Lets the compiler synthesize the
// copy and assignment operator
// complex<_Tp>& operator= (const complex<_Tp>&);
/// Assign this complex number to complex @a z.
template<typename _Up>
complex<_Tp>& operator=(const complex<_Up>&);
/// Add @a z to this complex number.
template<typename _Up>
complex<_Tp>& operator+=(const complex<_Up>&);
/// Subtract @a z from this complex number.
template<typename _Up>
complex<_Tp>& operator-=(const complex<_Up>&);
/// Multiply this complex number by @a z.
template<typename _Up>
complex<_Tp>& operator*=(const complex<_Up>&);
/// Divide this complex number by @a z.
template<typename _Up>
complex<_Tp>& operator/=(const complex<_Up>&);
......@@ -261,6 +307,8 @@ namespace std
}
// Operators:
//@{
/// Return new complex value @a x plus @a y.
template<typename _Tp>
inline complex<_Tp>
operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
......@@ -287,7 +335,10 @@ namespace std
__r.real() += __x;
return __r;
}
//@}
//@{
/// Return new complex value @a x minus @a y.
template<typename _Tp>
inline complex<_Tp>
operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
......@@ -314,7 +365,10 @@ namespace std
__r.real() -= __y.real();
return __r;
}
//@}
//@{
/// Return new complex value @a x times @a y.
template<typename _Tp>
inline complex<_Tp>
operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
......@@ -341,7 +395,10 @@ namespace std
__r *= __x;
return __r;
}
//@}
//@{
/// Return new complex value @a x divided by @a y.
template<typename _Tp>
inline complex<_Tp>
operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
......@@ -368,17 +425,22 @@ namespace std
__r /= __y;
return __r;
}
//@}
/// Return @a x.
template<typename _Tp>
inline complex<_Tp>
operator+(const complex<_Tp>& __x)
{ return __x; }
/// Return complex negation of @a x.
template<typename _Tp>
inline complex<_Tp>
operator-(const complex<_Tp>& __x)
{ return complex<_Tp>(-__x.real(), -__x.imag()); }
//@{
/// Return true if @a x is equal to @a y.
template<typename _Tp>
inline bool
operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
......@@ -393,7 +455,10 @@ namespace std
inline bool
operator==(const _Tp& __x, const complex<_Tp>& __y)
{ return __x == __y.real() && _Tp() == __y.imag(); }
//@}
//@{
/// Return false if @a x is equal to @a y.
template<typename _Tp>
inline bool
operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
......@@ -408,7 +473,9 @@ namespace std
inline bool
operator!=(const _Tp& __x, const complex<_Tp>& __y)
{ return __x != __y.real() || _Tp() != __y.imag(); }
//@}
/// Extraction operator for complex values.
template<typename _Tp, typename _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
......@@ -441,6 +508,7 @@ namespace std
return __is;
}
/// Insertion operator for complex values.
template<typename _Tp, typename _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
......
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