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++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#pragma GCC system_header #pragma GCC system_header
// 22.2.1.5 Template class codecvt // 22.2.1.5 Template class codecvt
/// Base class for codecvt facet providing conversion result enum.
class codecvt_base class codecvt_base
{ {
public: public:
...@@ -60,6 +61,15 @@ ...@@ -60,6 +61,15 @@
// NB: An abstract base class that fills in the public inlines, so // NB: An abstract base class that fills in the public inlines, so
// that the specializations don't have to re-copy the public // that the specializations don't have to re-copy the public
// interface. // 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> template<typename _InternT, typename _ExternT, typename _StateT>
class __codecvt_abstract_base class __codecvt_abstract_base
: public locale::facet, public codecvt_base : public locale::facet, public codecvt_base
...@@ -72,6 +82,41 @@ ...@@ -72,6 +82,41 @@
typedef _StateT state_type; typedef _StateT state_type;
// 22.2.1.5.1 codecvt members // 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 result
out(state_type& __state, const intern_type* __from, out(state_type& __state, const intern_type* __from,
const intern_type* __from_end, const intern_type*& __from_next, const intern_type* __from_end, const intern_type*& __from_next,
...@@ -82,11 +127,75 @@ ...@@ -82,11 +127,75 @@
__to, __to_end, __to_next); __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 result
unshift(state_type& __state, extern_type* __to, extern_type* __to_end, unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
extern_type*& __to_next) const extern_type*& __to_next) const
{ return this->do_unshift(__state, __to,__to_end,__to_next); } { 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 result
in(state_type& __state, const extern_type* __from, in(state_type& __state, const extern_type* __from,
const extern_type* __from_end, const extern_type*& __from_next, const extern_type* __from_end, const extern_type*& __from_next,
...@@ -121,6 +230,13 @@ ...@@ -121,6 +230,13 @@
virtual virtual
~__codecvt_abstract_base() { } ~__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 virtual result
do_out(state_type& __state, const intern_type* __from, do_out(state_type& __state, const intern_type* __from,
const intern_type* __from_end, const intern_type*& __from_next, const intern_type* __from_end, const intern_type*& __from_next,
......
...@@ -4462,6 +4462,8 @@ namespace std ...@@ -4462,6 +4462,8 @@ namespace std
// NB: These are inline because, when used in a loop, some compilers // 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 // can hoist the body out of the loop; then it's just as fast as the
// C is*() function. // C is*() function.
//@{
/// Convenience interface to ctype.is().
template<typename _CharT> template<typename _CharT>
inline bool inline bool
isspace(_CharT __c, const locale& __loc) isspace(_CharT __c, const locale& __loc)
...@@ -4525,6 +4527,7 @@ namespace std ...@@ -4525,6 +4527,7 @@ namespace std
inline _CharT inline _CharT
tolower(_CharT __c, const locale& __loc) tolower(_CharT __c, const locale& __loc)
{ return use_facet<ctype<_CharT> >(__loc).tolower(__c); } { return use_facet<ctype<_CharT> >(__loc).tolower(__c); }
//@}
} // namespace std } // namespace std
#endif #endif
// Position types -*- C++ -*- // Position types -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004
// Free Software Foundation, Inc. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -64,6 +64,7 @@ namespace std ...@@ -64,6 +64,7 @@ namespace std
typedef long long __streamoff_base_type; typedef long long __streamoff_base_type;
#endif #endif
/// Integral type for I/O operation counts and buffer sizes.
typedef ptrdiff_t streamsize; // Signed integral type typedef ptrdiff_t streamsize; // Signed integral type
template<typename _StateT> template<typename _StateT>
...@@ -127,19 +128,30 @@ namespace std ...@@ -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 * @brief Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
// distinct class type. *
// Note: In versions of GCC up to and including GCC 3.3, streamoff * @if maint
// was typedef long. * 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; typedef class streamoff streamoff;
// The standard fails to place any requiremens on the template /**
// argument StateT. In this implementation StateT must be * @brief Class representing stream positions.
// DefaultConstructible, CopyConstructible and Assignable. The *
// standard only requires that fpos should contain a member of type * The standard places no requirements upon the template parameter StateT.
// StateT. In this implementation it also contains an offset stored * In this implementation StateT must be DefaultConstructible,
// as a signed integer. * 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> template<typename _StateT>
class fpos class fpos
{ {
...@@ -161,6 +173,7 @@ namespace std ...@@ -161,6 +173,7 @@ namespace std
// fpos, but gives no meaningful semantics for this // fpos, but gives no meaningful semantics for this
// conversion. In this implementation this constructor stores // conversion. In this implementation this constructor stores
// the integer as the offset and default constructs the state. // the integer as the offset and default constructs the state.
/// Construct position from integer.
fpos(__streamoff_base_type __off) fpos(__streamoff_base_type __off)
: _M_off(__off), _M_state() { } : _M_off(__off), _M_state() { }
...@@ -170,13 +183,16 @@ namespace std ...@@ -170,13 +183,16 @@ namespace std
// implementation implicit conversion is also allowed, and this // implementation implicit conversion is also allowed, and this
// constructor stores the streamoff as the offset and default // constructor stores the streamoff as the offset and default
// constructs the state. // constructs the state.
/// Construct position from offset.
fpos(const streamoff& __off) fpos(const streamoff& __off)
: _M_off(__off), _M_state() { } : _M_off(__off), _M_state() { }
/// Remember the value of @a st.
void void
state(_StateT __st) state(_StateT __st)
{ _M_state = __st; } { _M_state = __st; }
/// Return the last set value of @a st.
_StateT _StateT
state() const state() const
{ return _M_state; } { return _M_state; }
...@@ -185,10 +201,12 @@ namespace std ...@@ -185,10 +201,12 @@ namespace std
// equivalence relation. In this implementation two fpos<StateT> // equivalence relation. In this implementation two fpos<StateT>
// objects belong to the same equivalence class if the contained // objects belong to the same equivalence class if the contained
// offsets compare equal. // offsets compare equal.
/// Test if equivalent to another position.
bool bool
operator==(const fpos& __other) const operator==(const fpos& __other) const
{ return _M_off == __other._M_off; } { return _M_off == __other._M_off; }
/// Test if not equivalent to another position.
bool bool
operator!=(const fpos& __other) const operator!=(const fpos& __other) const
{ return _M_off != __other._M_off; } { return _M_off != __other._M_off; }
...@@ -196,6 +214,7 @@ namespace std ...@@ -196,6 +214,7 @@ namespace std
// The standard requires that this operator must be defined, but // The standard requires that this operator must be defined, but
// gives no semantics. In this implemenation it just adds it's // gives no semantics. In this implemenation it just adds it's
// argument to the stored offset and returns *this. // argument to the stored offset and returns *this.
/// Add offset to this position.
fpos& fpos&
operator+=(const streamoff& __off) operator+=(const streamoff& __off)
{ {
...@@ -206,6 +225,7 @@ namespace std ...@@ -206,6 +225,7 @@ namespace std
// The standard requires that this operator must be defined, but // The standard requires that this operator must be defined, but
// gives no semantics. In this implemenation it just subtracts // gives no semantics. In this implemenation it just subtracts
// it's argument from the stored offset and returns *this. // it's argument from the stored offset and returns *this.
/// Subtract offset from this position.
fpos& fpos&
operator-=(const streamoff& __off) operator-=(const streamoff& __off)
{ {
...@@ -218,6 +238,7 @@ namespace std ...@@ -218,6 +238,7 @@ namespace std
// implementation it constructs a copy of *this, adds the // implementation it constructs a copy of *this, adds the
// argument to that copy using operator+= and then returns the // argument to that copy using operator+= and then returns the
// copy. // copy.
/// Add position and offset.
fpos fpos
operator+(const streamoff& __off) const operator+(const streamoff& __off) const
{ {
...@@ -231,6 +252,7 @@ namespace std ...@@ -231,6 +252,7 @@ namespace std
// implementation it constructs a copy of *this, subtracts the // implementation it constructs a copy of *this, subtracts the
// argument from that copy using operator-= and then returns the // argument from that copy using operator-= and then returns the
// copy. // copy.
/// Subtract offset from position.
fpos fpos
operator-(const streamoff& __off) const operator-(const streamoff& __off) const
{ {
...@@ -243,11 +265,13 @@ namespace std ...@@ -243,11 +265,13 @@ namespace std
// defines it's semantics only in terms of operator+. In this // defines it's semantics only in terms of operator+. In this
// implementation it returns the difference between the offset // implementation it returns the difference between the offset
// stored in *this and in the argument. // stored in *this and in the argument.
/// Subtract position to return offset.
streamoff streamoff
operator-(const fpos& __other) const operator-(const fpos& __other) const
{ return _M_off - __other._M_off; } { return _M_off - __other._M_off; }
}; };
/// Construct offset from position.
template<typename _StateT> template<typename _StateT>
inline inline
streamoff::streamoff(const fpos<_StateT>& __pos) streamoff::streamoff(const fpos<_StateT>& __pos)
...@@ -256,7 +280,9 @@ namespace std ...@@ -256,7 +280,9 @@ namespace std
// Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos // Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos
// as implementation defined types, but clause 27.2 requires that // as implementation defined types, but clause 27.2 requires that
// they must both be typedefs for fpos<mbstate_t> // they must both be typedefs for fpos<mbstate_t>
/// File position for char streams.
typedef fpos<mbstate_t> streampos; typedef fpos<mbstate_t> streampos;
/// File position for wchar_t streams.
typedef fpos<mbstate_t> wstreampos; typedef fpos<mbstate_t> wstreampos;
} // namespace std } // namespace std
......
// bit_vector and vector<bool> specialization -*- C++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -296,6 +296,24 @@ protected: ...@@ -296,6 +296,24 @@ protected:
#include <bits/stl_vector.h> #include <bits/stl_vector.h>
namespace __gnu_norm 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> template <typename _Alloc>
class vector<bool, _Alloc> : public _Bvector_base<_Alloc> class vector<bool, _Alloc> : public _Bvector_base<_Alloc>
{ {
......
// Multiset implementation -*- C++ -*- // Multiset implementation -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -80,181 +80,451 @@ template <class _Key, class _Compare, class _Alloc> ...@@ -80,181 +80,451 @@ template <class _Key, class _Compare, class _Alloc>
inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y); const multiset<_Key,_Compare,_Alloc>& __y);
template <class _Key, class _Compare, class _Alloc> /**
class multiset * @brief A standard container made up of elements, which can be retrieved
{ * in logarithmic time.
// concept requirements *
__glibcxx_class_requires(_Key, _SGIAssignableConcept) * @ingroup Containers
__glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) * @ingroup Assoc_containers
*
public: * Meets the requirements of a <a href="tables.html#65">container</a>, a
* <a href="tables.html#66">reversible container</a>, and an
// typedefs: * <a href="tables.html#69">associative container</a> (using equivalent
* keys). For a @c multiset<Key> the key_type and value_type are Key.
typedef _Key key_type; *
typedef _Key value_type; * Multisets support bidirectional iterators.
typedef _Compare key_compare; *
typedef _Compare value_compare; * @if maint
private: * The private tree data is declared exactly the same way for set and
typedef _Rb_tree<key_type, value_type, * multiset; the distinction is made entirely in how the tree functions are
_Identity<value_type>, key_compare, _Alloc> _Rep_type; * called (*_unique versus *_equal, same as the standard).
_Rep_type _M_t; // red-black tree representing multiset * @endif
public: */
typedef typename _Alloc::pointer pointer; template <class _Key, class _Compare, class _Alloc>
typedef typename _Alloc::const_pointer const_pointer; class multiset
typedef typename _Alloc::reference reference; {
typedef typename _Alloc::const_reference const_reference; // concept requirements
typedef typename _Rep_type::const_iterator iterator; __glibcxx_class_requires(_Key, _SGIAssignableConcept)
typedef typename _Rep_type::const_iterator const_iterator; __glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept)
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; public:
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type; // typedefs:
typedef typename _Rep_type::allocator_type allocator_type;
typedef _Key key_type;
// allocation/deallocation typedef _Key value_type;
typedef _Compare key_compare;
multiset() : _M_t(_Compare(), allocator_type()) {} typedef _Compare value_compare;
explicit multiset(const _Compare& __comp,
const allocator_type& __a = allocator_type()) private:
: _M_t(__comp, __a) {} /// @if maint This turns a red-black tree into a [multi]set. @endif
typedef _Rb_tree<key_type, value_type,
template <class _InputIterator> _Identity<value_type>, key_compare, _Alloc> _Rep_type;
multiset(_InputIterator __first, _InputIterator __last) /// @if maint The actual tree structure. @endif
: _M_t(_Compare(), allocator_type()) _Rep_type _M_t;
public:
typedef typename _Alloc::pointer pointer;
typedef typename _Alloc::const_pointer const_pointer;
typedef typename _Alloc::reference reference;
typedef typename _Alloc::const_reference const_reference;
typedef typename _Rep_type::const_iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation
/**
* @brief Default constructor creates no elements.
*/
multiset() : _M_t(_Compare(), allocator_type()) {}
explicit multiset(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
/**
* @brief Builds a %multiset from a range.
* @param first An input iterator.
* @param last An input iterator.
*
* Create a %multiset consisting of copies of the elements from
* [first,last). This is linear in N if the range is already sorted,
* and NlogN otherwise (where N is distance(first,last)).
*/
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); } { _M_t.insert_equal(__first, __last); }
template <class _InputIterator> /**
multiset(_InputIterator __first, _InputIterator __last, * @brief Builds a %multiset from a range.
const _Compare& __comp, * @param first An input iterator.
const allocator_type& __a = allocator_type()) * @param last An input iterator.
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); } * @param comp A comparison functor.
* @param a An allocator object.
multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {} *
* Create a %multiset consisting of copies of the elements from
multiset<_Key,_Compare,_Alloc>& * [first,last). This is linear in N if the range is already sorted,
operator=(const multiset<_Key,_Compare,_Alloc>& __x) { * and NlogN otherwise (where N is distance(first,last)).
_M_t = __x._M_t; */
return *this; template <class _InputIterator>
} multiset(_InputIterator __first, _InputIterator __last,
const _Compare& __comp,
// accessors: const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return _M_t.key_comp(); } /**
allocator_type get_allocator() const { return _M_t.get_allocator(); } * @brief %Multiset copy constructor.
* @param x A %multiset of identical element and allocator types.
iterator begin() const { return _M_t.begin(); } *
iterator end() const { return _M_t.end(); } * The newly-created %multiset uses a copy of the allocation object used
reverse_iterator rbegin() const { return _M_t.rbegin(); } * by @a x.
reverse_iterator rend() const { return _M_t.rend(); } */
bool empty() const { return _M_t.empty(); } multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); } /**
void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); } * @brief %Multiset assignment operator.
* @param x A %multiset of identical element and allocator types.
// insert/erase *
iterator insert(const value_type& __x) { * All the elements of @a x are copied, but unlike the copy constructor,
return _M_t.insert_equal(__x); * the allocator object is not copied.
} */
iterator insert(iterator __position, const value_type& __x) { multiset<_Key,_Compare,_Alloc>&
typedef typename _Rep_type::iterator _Rep_iterator; operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
return _M_t.insert_equal((_Rep_iterator&)__position, __x); _M_t = __x._M_t;
} return *this;
}
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) { // accessors:
_M_t.insert_equal(__first, __last);
} /// Returns the comparison object.
void erase(iterator __position) { key_compare key_comp() const { return _M_t.key_comp(); }
typedef typename _Rep_type::iterator _Rep_iterator; /// Returns the comparison object.
_M_t.erase((_Rep_iterator&)__position); value_compare value_comp() const { return _M_t.key_comp(); }
} /// Returns the memory allocation object.
size_type erase(const key_type& __x) { allocator_type get_allocator() const { return _M_t.get_allocator(); }
return _M_t.erase(__x);
} /**
void erase(iterator __first, iterator __last) { * Returns a read/write iterator that points to the first element in the
typedef typename _Rep_type::iterator _Rep_iterator; * %multiset. Iteration is done in ascending order according to the
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); * keys.
} */
void clear() { _M_t.clear(); } iterator begin() const { return _M_t.begin(); }
// multiset operations: /**
* Returns a read/write iterator that points one past the last element in
size_type count(const key_type& __x) const { return _M_t.count(__x); } * the %multiset. Iteration is done in ascending order according to the
* keys.
// _GLIBCXX_RESOLVE_LIB_DEFECTS */
// 214. set::find() missing const overload iterator end() const { return _M_t.end(); }
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); } /**
iterator lower_bound(const key_type& __x) { * Returns a read/write reverse iterator that points to the last element
return _M_t.lower_bound(__x); * in the %multiset. Iteration is done in descending order according to
} * the keys.
const_iterator lower_bound(const key_type& __x) const { */
return _M_t.lower_bound(__x); reverse_iterator rbegin() const { return _M_t.rbegin(); }
}
iterator upper_bound(const key_type& __x) { /**
return _M_t.upper_bound(__x); * Returns a read/write reverse iterator that points to the last element
} * in the %multiset. Iteration is done in descending order according to
const_iterator upper_bound(const key_type& __x) const { * the keys.
return _M_t.upper_bound(__x); */
} reverse_iterator rend() const { return _M_t.rend(); }
pair<iterator,iterator> equal_range(const key_type& __x) {
return _M_t.equal_range(__x); /// Returns true if the %set is empty.
} bool empty() const { return _M_t.empty(); }
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x); /// Returns the size of the %set.
} size_type size() const { return _M_t.size(); }
template <class _K1, class _C1, class _A1> /// Returns the maximum size of the %set.
friend bool operator== (const multiset<_K1,_C1,_A1>&, size_type max_size() const { return _M_t.max_size(); }
const multiset<_K1,_C1,_A1>&);
template <class _K1, class _C1, class _A1> /**
friend bool operator< (const multiset<_K1,_C1,_A1>&, * @brief Swaps data with another %multiset.
const multiset<_K1,_C1,_A1>&); * @param x A %multiset of the same element and allocator types.
}; *
* This exchanges the elements between two multisets in constant time.
template <class _Key, class _Compare, class _Alloc> * (It is only swapping a pointer, an integer, and an instance of the @c
inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x, * Compare type (which itself is often stateless and empty), so it should
const multiset<_Key,_Compare,_Alloc>& __y) { * be quite fast.)
return __x._M_t == __y._M_t; * Note that the global std::swap() function is specialized such that
} * std::swap(s1,s2) will feed to this function.
*/
template <class _Key, class _Compare, class _Alloc> void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) { // insert/erase
return __x._M_t < __y._M_t; /**
} * @brief Inserts an element into the %multiset.
* @param x Element to be inserted.
template <class _Key, class _Compare, class _Alloc> * @return An iterator that points to the inserted element.
inline bool operator!=(const multiset<_Key,_Compare,_Alloc>& __x, *
const multiset<_Key,_Compare,_Alloc>& __y) { * This function inserts an element into the %multiset. Contrary
return !(__x == __y); * to a std::set the %multiset does not rely on unique keys and thus
} * multiple copies of the same element can be inserted.
*
template <class _Key, class _Compare, class _Alloc> * Insertion requires logarithmic time.
inline bool operator>(const multiset<_Key,_Compare,_Alloc>& __x, */
const multiset<_Key,_Compare,_Alloc>& __y) { iterator insert(const value_type& __x) {
return __y < __x; return _M_t.insert_equal(__x);
} }
template <class _Key, class _Compare, class _Alloc> /**
inline bool operator<=(const multiset<_Key,_Compare,_Alloc>& __x, * @brief Inserts an element into the %multiset.
const multiset<_Key,_Compare,_Alloc>& __y) { * @param position An iterator that serves as a hint as to where the
return !(__y < __x); * element should be inserted.
} * @param x Element to be inserted.
* @return An iterator that points to the inserted element.
template <class _Key, class _Compare, class _Alloc> *
inline bool operator>=(const multiset<_Key,_Compare,_Alloc>& __x, * This function inserts an element into the %multiset. Contrary
const multiset<_Key,_Compare,_Alloc>& __y) { * to a std::set the %multiset does not rely on unique keys and thus
return !(__x < __y); * multiple copies of the same element can be inserted.
} *
* Note that the first parameter is only a hint and can potentially
template <class _Key, class _Compare, class _Alloc> * improve the performance of the insertion process. A bad hint would
inline void swap(multiset<_Key,_Compare,_Alloc>& __x, * cause no gains in efficiency.
multiset<_Key,_Compare,_Alloc>& __y) { *
__x.swap(__y); * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
} * for more on "hinting".
*
* Insertion requires logarithmic time (if the hint is not taken).
*/
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_equal((_Rep_iterator&)__position, __x);
}
/**
* @brief A template function that attemps to insert a range of elements.
* @param first Iterator pointing to the start of the range to be
* inserted.
* @param last Iterator pointing to the end of the range.
*
* Complexity similar to that of the range constructor.
*/
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
/**
* @brief Erases an element from a %multiset.
* @param position An iterator pointing to the element to be erased.
*
* This function erases an element, pointed to by the given iterator,
* from a %multiset. Note that this function only erases the element,
* and that if the element is itself a pointer, the pointed-to memory is
* not touched in any way. Managing the pointer is the user's
* responsibilty.
*/
void erase(iterator __position) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__position);
}
/**
* @brief Erases elements according to the provided key.
* @param x Key of element to be erased.
* @return The number of elements erased.
*
* This function erases all elements located by the given key from a
* %multiset.
* Note that this function only erases the element, and that if
* the element is itself a pointer, the pointed-to memory is not touched
* in any way. Managing the pointer is the user's responsibilty.
*/
size_type erase(const key_type& __x) {
return _M_t.erase(__x);
}
/**
* @brief Erases a [first,last) range of elements from a %multiset.
* @param first Iterator pointing to the start of the range to be erased.
* @param last Iterator pointing to the end of the range to be erased.
*
* This function erases a sequence of elements from a %multiset.
* Note that this function only erases the elements, and that if
* the elements themselves are pointers, the pointed-to memory is not
* touched in any way. Managing the pointer is the user's responsibilty.
*/
void erase(iterator __first, iterator __last) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
/**
* Erases all elements in a %multiset. Note that this function only
* erases the elements, and that if the elements themselves are pointers,
* the pointed-to memory is not touched in any way. Managing the pointer
* is the user's responsibilty.
*/
void clear() { _M_t.clear(); }
// multiset operations:
/**
* @brief Finds the number of elements with given key.
* @param x Key of elements to be located.
* @return Number of elements with specified key.
*/
size_type count(const key_type& __x) const { return _M_t.count(__x); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 214. set::find() missing const overload
//@{
/**
* @brief Tries to locate an element in a %set.
* @param x Element to be located.
* @return Iterator pointing to sought-after element, or end() if not
* found.
*
* This function takes a key and tries to locate the element with which
* the key matches. If successful the function returns an iterator
* pointing to the sought after element. If unsuccessful it returns the
* past-the-end ( @c end() ) iterator.
*/
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
//@}
//@{
/**
* @brief Finds the beginning of a subsequence matching given key.
* @param x Key to be located.
* @return Iterator pointing to first element equal to or greater
* than key, or end().
*
* This function returns the first element of a subsequence of elements
* that matches the given key. If unsuccessful it returns an iterator
* pointing to the first element that has a greater value than given key
* or end() if no such element exists.
*/
iterator lower_bound(const key_type& __x) {
return _M_t.lower_bound(__x);
}
const_iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
//@}
//@{
/**
* @brief Finds the end of a subsequence matching given key.
* @param x Key to be located.
* @return Iterator pointing to the first element
* greater than key, or end().
*/
iterator upper_bound(const key_type& __x) {
return _M_t.upper_bound(__x);
}
const_iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
//@}
//@{
/**
* @brief Finds a subsequence matching given key.
* @param x Key to be located.
* @return Pair of iterators that possibly points to the subsequence
* matching given key.
*
* This function is equivalent to
* @code
* std::make_pair(c.lower_bound(val),
* c.upper_bound(val))
* @endcode
* (but is faster than making the calls separately).
*
* This function probably only makes sense for multisets.
*/
pair<iterator,iterator> equal_range(const key_type& __x) {
return _M_t.equal_range(__x);
}
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
template <class _K1, class _C1, class _A1>
friend bool operator== (const multiset<_K1,_C1,_A1>&,
const multiset<_K1,_C1,_A1>&);
template <class _K1, class _C1, class _A1>
friend bool operator< (const multiset<_K1,_C1,_A1>&,
const multiset<_K1,_C1,_A1>&);
};
/**
* @brief Multiset equality comparison.
* @param x A %multiset.
* @param y A %multiset of the same type as @a x.
* @return True iff the size and elements of the multisets are equal.
*
* This is an equivalence relation. It is linear in the size of the multisets.
* Multisets are considered equivalent if their sizes are equal, and if
* corresponding elements compare equal.
*/
template <class _Key, class _Compare, class _Alloc>
inline bool
operator==(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y)
{ return __x._M_t == __y._M_t; }
/**
* @brief Multiset ordering relation.
* @param x A %multiset.
* @param y A %multiset of the same type as @a x.
* @return True iff @a x is lexicographically less than @a y.
*
* This is a total ordering relation. It is linear in the size of the
* maps. The elements must be comparable with @c <.
*
* See std::lexicographical_compare() for how the determination is made.
*/
template <class _Key, class _Compare, class _Alloc>
inline bool
operator<(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y)
{ return __x._M_t < __y._M_t; }
/// Returns !(x == y).
template <class _Key, class _Compare, class _Alloc>
inline bool
operator!=(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y)
{ return !(__x == __y); }
/// Returns y < x.
template <class _Key, class _Compare, class _Alloc>
inline bool
operator>(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y)
{ return __y < __x; }
/// Returns !(y < x)
template <class _Key, class _Compare, class _Alloc>
inline bool
operator<=(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y)
{ return !(__y < __x); }
/// Returns !(x < y)
template <class _Key, class _Compare, class _Alloc>
inline bool
operator>=(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y)
{ return !(__x < __y); }
/// See std::multiset::swap().
template <class _Key, class _Compare, class _Alloc>
inline void
swap(multiset<_Key,_Compare,_Alloc>& __x,
multiset<_Key,_Compare,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm } // namespace __gnu_norm
......
// Set implementation -*- C++ -*- // Set implementation -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -80,6 +80,29 @@ namespace __gnu_norm ...@@ -80,6 +80,29 @@ namespace __gnu_norm
operator<(const set<_Key,_Compare,_Alloc>& __x, operator<(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y); const set<_Key,_Compare,_Alloc>& __y);
/**
* @brief A standard container made up of unique keys, which can be
* retrieved in logarithmic time.
*
* @ingroup Containers
* @ingroup Assoc_containers
*
* Meets the requirements of a <a href="tables.html#65">container</a>, a
* <a href="tables.html#66">reversible container</a>, and an
* <a href="tables.html#69">associative container</a> (using unique keys).
*
* Sets support bidirectional iterators.
*
* @param Key Type of key objects.
* @param Compare Comparison function object type, defaults to less<Key>.
* @param Alloc Allocator type, defaults to allocator<Key>.
*
* @if maint
* The private tree data is declared exactly the same way for set and
* multiset; the distinction is made entirely in how the tree functions are
* called (*_unique versus *_equal, same as the standard).
* @endif
*/
template<class _Key, class _Compare, class _Alloc> template<class _Key, class _Compare, class _Alloc>
class set class set
{ {
...@@ -89,168 +112,424 @@ namespace __gnu_norm ...@@ -89,168 +112,424 @@ namespace __gnu_norm
public: public:
// typedefs: // typedefs:
//@{
/// Public typedefs.
typedef _Key key_type; typedef _Key key_type;
typedef _Key value_type; typedef _Key value_type;
typedef _Compare key_compare; typedef _Compare key_compare;
typedef _Compare value_compare; typedef _Compare value_compare;
private: //@}
typedef _Rb_tree<key_type, value_type,
_Identity<value_type>, key_compare, _Alloc> _Rep_type; private:
_Rep_type _M_t; // red-black tree representing set typedef _Rb_tree<key_type, value_type,
public: _Identity<value_type>, key_compare, _Alloc> _Rep_type;
typedef typename _Alloc::pointer pointer; _Rep_type _M_t; // red-black tree representing set
typedef typename _Alloc::const_pointer const_pointer; public:
typedef typename _Alloc::reference reference; //@{
typedef typename _Alloc::const_reference const_reference; /// Iterator-related typedefs.
typedef typename _Rep_type::const_iterator iterator; typedef typename _Alloc::pointer pointer;
typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Alloc::const_pointer const_pointer;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator; typedef typename _Alloc::reference reference;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Alloc::const_reference const_reference;
typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::const_iterator iterator;
typedef typename _Rep_type::difference_type difference_type; typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::allocator_type allocator_type; typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
// allocation/deallocation typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
set() : _M_t(_Compare(), allocator_type()) {} typedef typename _Rep_type::allocator_type allocator_type;
explicit set(const _Compare& __comp, //@}
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {} // allocation/deallocation
/// Default constructor creates no elements.
template<class _InputIterator> set() : _M_t(_Compare(), allocator_type()) {}
set(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type()) /**
{ _M_t.insert_unique(__first, __last); } * @brief Default constructor creates no elements.
*
template<class _InputIterator> * @param comp Comparator to use.
set(_InputIterator __first, _InputIterator __last, const _Compare& __comp, * @param a Allocator to use.
const allocator_type& __a = allocator_type()) */
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); } explicit set(const _Compare& __comp,
const allocator_type& __a = allocator_type())
set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {} : _M_t(__comp, __a) {}
set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
{ /**
_M_t = __x._M_t; * @brief Builds a %set from a range.
return *this; * @param first An input iterator.
} * @param last An input iterator.
*
// accessors: * Create a %set consisting of copies of the elements from [first,last).
* This is linear in N if the range is already sorted, and NlogN
key_compare key_comp() const { return _M_t.key_comp(); } * otherwise (where N is distance(first,last)).
value_compare value_comp() const { return _M_t.key_comp(); } */
allocator_type get_allocator() const { return _M_t.get_allocator(); } template<class _InputIterator>
set(_InputIterator __first, _InputIterator __last)
iterator begin() const { return _M_t.begin(); } : _M_t(_Compare(), allocator_type())
iterator end() const { return _M_t.end(); } { _M_t.insert_unique(__first, __last); }
reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() const { return _M_t.rend(); } /**
bool empty() const { return _M_t.empty(); } * @brief Builds a %set from a range.
size_type size() const { return _M_t.size(); } * @param first An input iterator.
size_type max_size() const { return _M_t.max_size(); } * @param last An input iterator.
void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); } * @param comp A comparison functor.
* @param a An allocator object.
// insert/erase *
pair<iterator,bool> insert(const value_type& __x) { * Create a %set consisting of copies of the elements from [first,last).
pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x); * This is linear in N if the range is already sorted, and NlogN
return pair<iterator, bool>(__p.first, __p.second); * otherwise (where N is distance(first,last)).
} */
iterator insert(iterator __position, const value_type& __x) { template<class _InputIterator>
typedef typename _Rep_type::iterator _Rep_iterator; set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
return _M_t.insert_unique((_Rep_iterator&)__position, __x); const allocator_type& __a = allocator_type())
} : _M_t(__comp, __a)
template<class _InputIterator> { _M_t.insert_unique(__first, __last); }
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last); /**
} * @brief Set copy constructor.
void erase(iterator __position) { * @param x A %set of identical element and allocator types.
typedef typename _Rep_type::iterator _Rep_iterator; *
_M_t.erase((_Rep_iterator&)__position); * The newly-created %set uses a copy of the allocation object used
} * by @a x.
size_type erase(const key_type& __x) { */
return _M_t.erase(__x); set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
}
void erase(iterator __first, iterator __last) { /**
typedef typename _Rep_type::iterator _Rep_iterator; * @brief Set assignment operator.
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); * @param x A %set of identical element and allocator types.
} *
void clear() { _M_t.clear(); } * All the elements of @a x are copied, but unlike the copy constructor,
* the allocator object is not copied.
// set operations: */
set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
size_type count(const key_type& __x) const { {
return _M_t.find(__x) == _M_t.end() ? 0 : 1; _M_t = __x._M_t;
} return *this;
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 214. set::find() missing const overload // accessors:
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); } /// Returns the comparison object with which the %set was constructed.
iterator lower_bound(const key_type& __x) { key_compare key_comp() const { return _M_t.key_comp(); }
return _M_t.lower_bound(__x); /// Returns the comparison object with which the %set was constructed.
} value_compare value_comp() const { return _M_t.key_comp(); }
const_iterator lower_bound(const key_type& __x) const { /// Returns the allocator object with which the %set was constructed.
return _M_t.lower_bound(__x); allocator_type get_allocator() const { return _M_t.get_allocator(); }
}
iterator upper_bound(const key_type& __x) { /**
return _M_t.upper_bound(__x); * Returns a read/write iterator that points to the first element in the
} * %set. Iteration is done in ascending order according to the keys.
const_iterator upper_bound(const key_type& __x) const { */
return _M_t.upper_bound(__x); iterator begin() const { return _M_t.begin(); }
}
pair<iterator,iterator> equal_range(const key_type& __x) { /**
return _M_t.equal_range(__x); * Returns a read/write iterator that points one past the last element in
} * the %set. Iteration is done in ascending order according to the keys.
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const { */
return _M_t.equal_range(__x); iterator end() const { return _M_t.end(); }
}
/**
template<class _K1, class _C1, class _A1> * Returns a read/write reverse iterator that points to the last element in
friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); * the %set. Iteration is done in descending order according to the keys.
template<class _K1, class _C1, class _A1> */
friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); reverse_iterator rbegin() const { return _M_t.rbegin(); }
};
/**
template<class _Key, class _Compare, class _Alloc> * Returns a read-only (constant) reverse iterator that points to the last
inline bool operator==(const set<_Key,_Compare,_Alloc>& __x, * pair in the %map. Iteration is done in descending order according to
const set<_Key,_Compare,_Alloc>& __y) { * the keys.
return __x._M_t == __y._M_t; */
} reverse_iterator rend() const { return _M_t.rend(); }
template<class _Key, class _Compare, class _Alloc> /// Returns true if the %set is empty.
inline bool operator<(const set<_Key,_Compare,_Alloc>& __x, bool empty() const { return _M_t.empty(); }
const set<_Key,_Compare,_Alloc>& __y) {
return __x._M_t < __y._M_t; /// Returns the size of the %set.
} size_type size() const { return _M_t.size(); }
template<class _Key, class _Compare, class _Alloc> /// Returns the maximum size of the %set.
inline bool operator!=(const set<_Key,_Compare,_Alloc>& __x, size_type max_size() const { return _M_t.max_size(); }
const set<_Key,_Compare,_Alloc>& __y) {
return !(__x == __y); /**
} * @brief Swaps data with another %set.
* @param x A %set of the same element and allocator types.
template<class _Key, class _Compare, class _Alloc> *
inline bool operator>(const set<_Key,_Compare,_Alloc>& __x, * This exchanges the elements between two sets in constant time.
const set<_Key,_Compare,_Alloc>& __y) { * (It is only swapping a pointer, an integer, and an instance of
return __y < __x; * the @c Compare type (which itself is often stateless and empty), so it
} * should be quite fast.)
* Note that the global std::swap() function is specialized such that
template<class _Key, class _Compare, class _Alloc> * std::swap(s1,s2) will feed to this function.
inline bool operator<=(const set<_Key,_Compare,_Alloc>& __x, */
const set<_Key,_Compare,_Alloc>& __y) { void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
return !(__y < __x);
} // insert/erase
/**
template<class _Key, class _Compare, class _Alloc> * @brief Attempts to insert an element into the %set.
inline bool operator>=(const set<_Key,_Compare,_Alloc>& __x, * @param x Element to be inserted.
const set<_Key,_Compare,_Alloc>& __y) { * @return A pair, of which the first element is an iterator that points
return !(__x < __y); * to the possibly inserted element, and the second is a bool that
} * is true if the element was actually inserted.
*
template<class _Key, class _Compare, class _Alloc> * This function attempts to insert an element into the %set. A %set
inline void swap(set<_Key,_Compare,_Alloc>& __x, * relies on unique keys and thus an element is only inserted if it is
set<_Key,_Compare,_Alloc>& __y) { * not already present in the %set.
__x.swap(__y); *
} * Insertion requires logarithmic time.
*/
pair<iterator,bool> insert(const value_type& __x)
{
pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x);
return pair<iterator, bool>(__p.first, __p.second);
}
/**
* @brief Attempts to insert an element into the %set.
* @param position An iterator that serves as a hint as to where the
* element should be inserted.
* @param x Element to be inserted.
* @return An iterator that points to the element with key of @a x (may
* or may not be the element passed in).
*
* This function is not concerned about whether the insertion took place,
* and thus does not return a boolean like the single-argument insert()
* does. Note that the first parameter is only a hint and can
* potentially improve the performance of the insertion process. A bad
* hint would cause no gains in efficiency.
*
* See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
* for more on "hinting".
*
* Insertion requires logarithmic time (if the hint is not taken).
*/
iterator insert(iterator __position, const value_type& __x)
{
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_unique((_Rep_iterator&)__position, __x);
}
/**
* @brief A template function that attemps to insert a range of elements.
* @param first Iterator pointing to the start of the range to be
* inserted.
* @param last Iterator pointing to the end of the range.
*
* Complexity similar to that of the range constructor.
*/
template<class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last)
{ _M_t.insert_unique(__first, __last); }
/**
* @brief Erases an element from a %set.
* @param position An iterator pointing to the element to be erased.
*
* This function erases an element, pointed to by the given iterator,
* from a %set. Note that this function only erases the element, and
* that if the element is itself a pointer, the pointed-to memory is not
* touched in any way. Managing the pointer is the user's responsibilty.
*/
void erase(iterator __position)
{
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__position);
}
/**
* @brief Erases elements according to the provided key.
* @param x Key of element to be erased.
* @return The number of elements erased.
*
* This function erases all the elements located by the given key from
* a %set.
* Note that this function only erases the element, and that if
* the element is itself a pointer, the pointed-to memory is not touched
* in any way. Managing the pointer is the user's responsibilty.
*/
size_type erase(const key_type& __x) { return _M_t.erase(__x); }
/**
* @brief Erases a [first,last) range of elements from a %set.
* @param first Iterator pointing to the start of the range to be erased.
* @param last Iterator pointing to the end of the range to be erased.
*
* This function erases a sequence of elements from a %set.
* Note that this function only erases the element, and that if
* the element is itself a pointer, the pointed-to memory is not touched
* in any way. Managing the pointer is the user's responsibilty.
*/
void erase(iterator __first, iterator __last)
{
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
/**
* Erases all elements in a %set. Note that this function only erases
* the elements, and that if the elements themselves are pointers, the
* pointed-to memory is not touched in any way. Managing the pointer is
* the user's responsibilty.
*/
void clear() { _M_t.clear(); }
// set operations:
/**
* @brief Finds the number of elements.
* @param x Element to located.
* @return Number of elements with specified key.
*
* This function only makes sense for multisets; for set the result will
* either be 0 (not present) or 1 (present).
*/
size_type count(const key_type& __x) const
{ return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 214. set::find() missing const overload
//@{
/**
* @brief Tries to locate an element in a %set.
* @param x Element to be located.
* @return Iterator pointing to sought-after element, or end() if not
* found.
*
* This function takes a key and tries to locate the element with which
* the key matches. If successful the function returns an iterator
* pointing to the sought after element. If unsuccessful it returns the
* past-the-end ( @c end() ) iterator.
*/
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
//@}
//@{
/**
* @brief Finds the beginning of a subsequence matching given key.
* @param x Key to be located.
* @return Iterator pointing to first element equal to or greater
* than key, or end().
*
* This function returns the first element of a subsequence of elements
* that matches the given key. If unsuccessful it returns an iterator
* pointing to the first element that has a greater value than given key
* or end() if no such element exists.
*/
iterator lower_bound(const key_type& __x)
{ return _M_t.lower_bound(__x); }
const_iterator lower_bound(const key_type& __x) const
{ return _M_t.lower_bound(__x); }
//@}
//@{
/**
* @brief Finds the end of a subsequence matching given key.
* @param x Key to be located.
* @return Iterator pointing to the first element
* greater than key, or end().
*/
iterator upper_bound(const key_type& __x)
{ return _M_t.upper_bound(__x); }
const_iterator upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); }
//@}
//@{
/**
* @brief Finds a subsequence matching given key.
* @param x Key to be located.
* @return Pair of iterators that possibly points to the subsequence
* matching given key.
*
* This function is equivalent to
* @code
* std::make_pair(c.lower_bound(val),
* c.upper_bound(val))
* @endcode
* (but is faster than making the calls separately).
*
* This function probably only makes sense for multisets.
*/
pair<iterator,iterator> equal_range(const key_type& __x)
{ return _M_t.equal_range(__x); }
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); }
//@}
template<class _K1, class _C1, class _A1>
friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
template<class _K1, class _C1, class _A1>
friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
};
/**
* @brief Set equality comparison.
* @param x A %set.
* @param y A %set of the same type as @a x.
* @return True iff the size and elements of the sets are equal.
*
* This is an equivalence relation. It is linear in the size of the sets.
* Sets are considered equivalent if their sizes are equal, and if
* corresponding elements compare equal.
*/
template<class _Key, class _Compare, class _Alloc>
inline bool
operator==(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y)
{ return __x._M_t == __y._M_t; }
/**
* @brief Set ordering relation.
* @param x A %set.
* @param y A %set of the same type as @a x.
* @return True iff @a x is lexicographically less than @a y.
*
* This is a total ordering relation. It is linear in the size of the
* maps. The elements must be comparable with @c <.
*
* See std::lexicographical_compare() for how the determination is made.
*/
template<class _Key, class _Compare, class _Alloc>
inline bool
operator<(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y)
{ return __x._M_t < __y._M_t; }
/// Returns !(x == y).
template<class _Key, class _Compare, class _Alloc>
inline bool
operator!=(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y)
{ return !(__x == __y); }
/// Returns y < x.
template<class _Key, class _Compare, class _Alloc>
inline bool
operator>(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y)
{ return __y < __x; }
/// Returns !(y < x)
template<class _Key, class _Compare, class _Alloc>
inline bool
operator<=(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y)
{ return !(__y < __x); }
/// Returns !(x < y)
template<class _Key, class _Compare, class _Alloc>
inline bool
operator>=(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y)
{ return !(__x < __y); }
/// See std::set::swap().
template<class _Key, class _Compare, class _Alloc>
inline void
swap(set<_Key,_Compare,_Alloc>& __x, set<_Key,_Compare,_Alloc>& __y)
{ __x.swap(__y); }
} // namespace __gnu_norm } // namespace __gnu_norm
......
// Stream iterators // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
namespace std namespace std
{ {
/// Provides input iterator semantics for streams.
template<typename _Tp, typename _CharT = char, template<typename _Tp, typename _CharT = char,
typename _Traits = char_traits<_CharT>, typename _Dist = ptrdiff_t> typename _Traits = char_traits<_CharT>, typename _Dist = ptrdiff_t>
class istream_iterator class istream_iterator
...@@ -56,9 +57,11 @@ namespace std ...@@ -56,9 +57,11 @@ namespace std
_Tp _M_value; _Tp _M_value;
bool _M_ok; bool _M_ok;
public: public:
/// Construct end of input stream iterator.
istream_iterator() : _M_stream(0), _M_ok(false) {} 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(istream_type& __s) : _M_stream(&__s) { _M_read(); }
istream_iterator(const istream_iterator& __obj) istream_iterator(const istream_iterator& __obj)
...@@ -116,12 +119,14 @@ namespace std ...@@ -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> template<typename _Tp, typename _CharT, typename _Traits, typename _Dist>
inline bool inline bool
operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x, operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y) const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y)
{ return __x._M_equal(__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> template <class _Tp, class _CharT, class _Traits, class _Dist>
inline bool inline bool
operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x, operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
...@@ -129,29 +134,57 @@ namespace std ...@@ -129,29 +134,57 @@ namespace std
{ return !__x._M_equal(__y); } { 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, template<typename _Tp, typename _CharT = char,
typename _Traits = char_traits<_CharT> > typename _Traits = char_traits<_CharT> >
class ostream_iterator class ostream_iterator
: public iterator<output_iterator_tag, void, void, void, void> : public iterator<output_iterator_tag, void, void, void, void>
{ {
public: public:
//@{
/// Public typedef
typedef _CharT char_type; typedef _CharT char_type;
typedef _Traits traits_type; typedef _Traits traits_type;
typedef basic_ostream<_CharT, _Traits> ostream_type; typedef basic_ostream<_CharT, _Traits> ostream_type;
//@}
private: private:
ostream_type* _M_stream; ostream_type* _M_stream;
const _CharT* _M_string; const _CharT* _M_string;
public: public:
/// Construct from an ostream.
ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {} 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) ostream_iterator(ostream_type& __s, const _CharT* __c)
: _M_stream(&__s), _M_string(__c) { } : _M_stream(&__s), _M_string(__c) { }
/// Copy constructor.
ostream_iterator(const ostream_iterator& __obj) ostream_iterator(const ostream_iterator& __obj)
: _M_stream(__obj._M_stream), _M_string(__obj._M_string) { } : _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& ostream_iterator&
operator=(const _Tp& __value) operator=(const _Tp& __value)
{ {
......
// Streambuf iterators // 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. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
namespace std namespace std
{ {
// 24.5.3 Template class istreambuf_iterator // 24.5.3 Template class istreambuf_iterator
/// Provides input iterator semantics for streambufs.
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
class istreambuf_iterator class istreambuf_iterator
: public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, : public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
...@@ -53,11 +54,14 @@ namespace std ...@@ -53,11 +54,14 @@ namespace std
{ {
public: public:
// Types: // Types:
//@{
/// Public typedefs
typedef _CharT char_type; typedef _CharT char_type;
typedef _Traits traits_type; typedef _Traits traits_type;
typedef typename _Traits::int_type int_type; typedef typename _Traits::int_type int_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type; typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_istream<_CharT, _Traits> istream_type; typedef basic_istream<_CharT, _Traits> istream_type;
//@}
private: private:
// 24.5.3 istreambuf_iterator // 24.5.3 istreambuf_iterator
...@@ -71,16 +75,21 @@ namespace std ...@@ -71,16 +75,21 @@ namespace std
int_type _M_c; int_type _M_c;
public: public:
/// Construct end of input stream iterator.
istreambuf_iterator() throw() istreambuf_iterator() throw()
: _M_sbuf(0), _M_c(traits_type::eof()) { } : _M_sbuf(0), _M_c(traits_type::eof()) { }
/// Construct start of input stream iterator.
istreambuf_iterator(istream_type& __s) throw() istreambuf_iterator(istream_type& __s) throw()
: _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { } : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
/// Construct start of streambuf iterator.
istreambuf_iterator(streambuf_type* __s) throw() istreambuf_iterator(streambuf_type* __s) throw()
: _M_sbuf(__s), _M_c(traits_type::eof()) { } : _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 char_type
operator*() const operator*() const
{ {
...@@ -93,7 +102,8 @@ namespace std ...@@ -93,7 +102,8 @@ namespace std
#endif #endif
return traits_type::to_char_type(_M_get()); return traits_type::to_char_type(_M_get());
} }
/// Advance the iterator. Calls streambuf.sbumpc().
istreambuf_iterator& istreambuf_iterator&
operator++() operator++()
{ {
...@@ -108,6 +118,7 @@ namespace std ...@@ -108,6 +118,7 @@ namespace std
return *this; return *this;
} }
/// Advance the iterator. Calls streambuf.sbumpc().
istreambuf_iterator istreambuf_iterator
operator++(int) operator++(int)
{ {
...@@ -129,6 +140,7 @@ namespace std ...@@ -129,6 +140,7 @@ namespace std
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 110 istreambuf_iterator::equal not const // 110 istreambuf_iterator::equal not const
// NB: there is also number 111 (NAD, Future) pending on this function. // NB: there is also number 111 (NAD, Future) pending on this function.
/// Return true both iterators are end or both are not end.
bool bool
equal(const istreambuf_iterator& __b) const equal(const istreambuf_iterator& __b) const
{ {
...@@ -174,28 +186,35 @@ namespace std ...@@ -174,28 +186,35 @@ namespace std
const istreambuf_iterator<_CharT, _Traits>& __b) const istreambuf_iterator<_CharT, _Traits>& __b)
{ return !__a.equal(__b); } { return !__a.equal(__b); }
/// Provides output iterator semantics for streambufs.
template<typename _CharT, typename _Traits> template<typename _CharT, typename _Traits>
class ostreambuf_iterator class ostreambuf_iterator
: public iterator<output_iterator_tag, void, void, void, void> : public iterator<output_iterator_tag, void, void, void, void>
{ {
public: public:
// Types: // Types:
//@{
/// Public typedefs
typedef _CharT char_type; typedef _CharT char_type;
typedef _Traits traits_type; typedef _Traits traits_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type; typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type; typedef basic_ostream<_CharT, _Traits> ostream_type;
//@}
private: private:
streambuf_type* _M_sbuf; streambuf_type* _M_sbuf;
bool _M_failed; bool _M_failed;
public: public:
/// Construct output iterator from ostream.
ostreambuf_iterator(ostream_type& __s) throw () ostreambuf_iterator(ostream_type& __s) throw ()
: _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { } : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
/// Construct output iterator from streambuf.
ostreambuf_iterator(streambuf_type* __s) throw () ostreambuf_iterator(streambuf_type* __s) throw ()
: _M_sbuf(__s), _M_failed(!_M_sbuf) { } : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
/// Write character to streambuf. Calls streambuf.sputc().
ostreambuf_iterator& ostreambuf_iterator&
operator=(_CharT __c) operator=(_CharT __c)
{ {
...@@ -205,18 +224,22 @@ namespace std ...@@ -205,18 +224,22 @@ namespace std
return *this; return *this;
} }
/// Return *this.
ostreambuf_iterator& ostreambuf_iterator&
operator*() operator*()
{ return *this; } { return *this; }
/// Return *this.
ostreambuf_iterator& ostreambuf_iterator&
operator++(int) operator++(int)
{ return *this; } { return *this; }
/// Return *this.
ostreambuf_iterator& ostreambuf_iterator&
operator++() operator++()
{ return *this; } { return *this; }
/// Return true if previous operator=() failed.
bool bool
failed() const throw() failed() const throw()
{ return _M_failed; } { return _M_failed; }
......
...@@ -58,67 +58,113 @@ namespace std ...@@ -58,67 +58,113 @@ namespace std
template<> class complex<double>; template<> class complex<double>;
template<> class complex<long double>; template<> class complex<long double>;
/// Return magnitude of @a z.
template<typename _Tp> _Tp abs(const complex<_Tp>&); template<typename _Tp> _Tp abs(const complex<_Tp>&);
/// Return phase angle of @a z.
template<typename _Tp> _Tp arg(const complex<_Tp>&); template<typename _Tp> _Tp arg(const complex<_Tp>&);
/// Return @a z magnitude squared.
template<typename _Tp> _Tp norm(const complex<_Tp>&); template<typename _Tp> _Tp norm(const complex<_Tp>&);
/// Return complex conjugate of @a z.
template<typename _Tp> complex<_Tp> conj(const complex<_Tp>&); 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); template<typename _Tp> complex<_Tp> polar(const _Tp&, const _Tp& = 0);
// Transcendentals: // Transcendentals:
/// Return complex cosine of @a z.
template<typename _Tp> complex<_Tp> cos(const complex<_Tp>&); 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>&); 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>&); 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>&); 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>&); 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); 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&); 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>&, template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&,
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>&); 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>&); 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>&); 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>&); template<typename _Tp> complex<_Tp> sqrt(const complex<_Tp>&);
/// Return complex tangent of @a z.
template<typename _Tp> complex<_Tp> tan(const complex<_Tp>&); 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>&); template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&);
//@}
// 26.2.2 Primary template class complex // 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> template<typename _Tp>
class complex class complex
{ {
public: public:
/// Value typedef.
typedef _Tp value_type; 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()); 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>&); // complex (const complex<_Tp>&);
/// Copy constructor.
template<typename _Up> template<typename _Up>
complex(const complex<_Up>&); complex(const complex<_Up>&);
/// Return real part of complex number.
_Tp& real(); _Tp& real();
/// Return real part of complex number.
const _Tp& real() const; const _Tp& real() const;
/// Return imaginary part of complex number.
_Tp& imag(); _Tp& imag();
/// Return imaginary part of complex number.
const _Tp& imag() const; const _Tp& imag() const;
/// Assign this complex number to scalar @a t.
complex<_Tp>& operator=(const _Tp&); complex<_Tp>& operator=(const _Tp&);
/// Add @a t to this complex number.
complex<_Tp>& operator+=(const _Tp&); complex<_Tp>& operator+=(const _Tp&);
/// Subtract @a t from this complex number.
complex<_Tp>& operator-=(const _Tp&); complex<_Tp>& operator-=(const _Tp&);
/// Multiply this complex number by @a t.
complex<_Tp>& operator*=(const _Tp&); complex<_Tp>& operator*=(const _Tp&);
/// Divide this complex number by @a t.
complex<_Tp>& operator/=(const _Tp&); complex<_Tp>& operator/=(const _Tp&);
// Let's the compiler synthetize the // Lets the compiler synthesize the
// copy and assignment operator // copy and assignment operator
// complex<_Tp>& operator= (const complex<_Tp>&); // complex<_Tp>& operator= (const complex<_Tp>&);
/// Assign this complex number to complex @a z.
template<typename _Up> template<typename _Up>
complex<_Tp>& operator=(const complex<_Up>&); complex<_Tp>& operator=(const complex<_Up>&);
/// Add @a z to this complex number.
template<typename _Up> template<typename _Up>
complex<_Tp>& operator+=(const complex<_Up>&); complex<_Tp>& operator+=(const complex<_Up>&);
/// Subtract @a z from this complex number.
template<typename _Up> template<typename _Up>
complex<_Tp>& operator-=(const complex<_Up>&); complex<_Tp>& operator-=(const complex<_Up>&);
/// Multiply this complex number by @a z.
template<typename _Up> template<typename _Up>
complex<_Tp>& operator*=(const complex<_Up>&); complex<_Tp>& operator*=(const complex<_Up>&);
/// Divide this complex number by @a z.
template<typename _Up> template<typename _Up>
complex<_Tp>& operator/=(const complex<_Up>&); complex<_Tp>& operator/=(const complex<_Up>&);
...@@ -261,6 +307,8 @@ namespace std ...@@ -261,6 +307,8 @@ namespace std
} }
// Operators: // Operators:
//@{
/// Return new complex value @a x plus @a y.
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<_Tp>
operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
...@@ -287,7 +335,10 @@ namespace std ...@@ -287,7 +335,10 @@ namespace std
__r.real() += __x; __r.real() += __x;
return __r; return __r;
} }
//@}
//@{
/// Return new complex value @a x minus @a y.
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<_Tp>
operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
...@@ -314,7 +365,10 @@ namespace std ...@@ -314,7 +365,10 @@ namespace std
__r.real() -= __y.real(); __r.real() -= __y.real();
return __r; return __r;
} }
//@}
//@{
/// Return new complex value @a x times @a y.
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<_Tp>
operator*(const complex<_Tp>& __x, const complex<_Tp>& __y) operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
...@@ -341,7 +395,10 @@ namespace std ...@@ -341,7 +395,10 @@ namespace std
__r *= __x; __r *= __x;
return __r; return __r;
} }
//@}
//@{
/// Return new complex value @a x divided by @a y.
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<_Tp>
operator/(const complex<_Tp>& __x, const complex<_Tp>& __y) operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
...@@ -368,17 +425,22 @@ namespace std ...@@ -368,17 +425,22 @@ namespace std
__r /= __y; __r /= __y;
return __r; return __r;
} }
//@}
/// Return @a x.
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<_Tp>
operator+(const complex<_Tp>& __x) operator+(const complex<_Tp>& __x)
{ return __x; } { return __x; }
/// Return complex negation of @a x.
template<typename _Tp> template<typename _Tp>
inline complex<_Tp> inline complex<_Tp>
operator-(const complex<_Tp>& __x) operator-(const complex<_Tp>& __x)
{ return complex<_Tp>(-__x.real(), -__x.imag()); } { return complex<_Tp>(-__x.real(), -__x.imag()); }
//@{
/// Return true if @a x is equal to @a y.
template<typename _Tp> template<typename _Tp>
inline bool inline bool
operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
...@@ -393,7 +455,10 @@ namespace std ...@@ -393,7 +455,10 @@ namespace std
inline bool inline bool
operator==(const _Tp& __x, const complex<_Tp>& __y) operator==(const _Tp& __x, const complex<_Tp>& __y)
{ return __x == __y.real() && _Tp() == __y.imag(); } { return __x == __y.real() && _Tp() == __y.imag(); }
//@}
//@{
/// Return false if @a x is equal to @a y.
template<typename _Tp> template<typename _Tp>
inline bool inline bool
operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
...@@ -408,7 +473,9 @@ namespace std ...@@ -408,7 +473,9 @@ namespace std
inline bool inline bool
operator!=(const _Tp& __x, const complex<_Tp>& __y) operator!=(const _Tp& __x, const complex<_Tp>& __y)
{ return __x != __y.real() || _Tp() != __y.imag(); } { return __x != __y.real() || _Tp() != __y.imag(); }
//@}
/// Extraction operator for complex values.
template<typename _Tp, typename _CharT, class _Traits> template<typename _Tp, typename _CharT, class _Traits>
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
...@@ -441,6 +508,7 @@ namespace std ...@@ -441,6 +508,7 @@ namespace std
return __is; return __is;
} }
/// Insertion operator for complex values.
template<typename _Tp, typename _CharT, class _Traits> template<typename _Tp, typename _CharT, class _Traits>
basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) 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