src/corelib/tools/qset.qdoc
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the documentation of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 /*!
       
    43     \class QSet
       
    44     \brief The QSet class is a template class that provides a hash-table-based set.
       
    45 
       
    46     \ingroup tools
       
    47     \ingroup shared
       
    48     \reentrant
       
    49 
       
    50 
       
    51     QSet<T> is one of Qt's generic \l{container classes}. It stores
       
    52     values in an unspecified order and provides very fast lookup of
       
    53     the values. Internally, QSet<T> is implemented as a QHash.
       
    54 
       
    55     Here's an example QSet with QString values:
       
    56 
       
    57     \snippet doc/src/snippets/code/doc_src_qset.qdoc 0
       
    58 
       
    59     To insert a value into the set, use insert():
       
    60 
       
    61     \snippet doc/src/snippets/code/doc_src_qset.qdoc 1
       
    62 
       
    63     Another way to insert items into the set is to use operator<<():
       
    64 
       
    65     \snippet doc/src/snippets/code/doc_src_qset.qdoc 2
       
    66 
       
    67     To test whether an item belongs to the set or not, use contains():
       
    68 
       
    69     \snippet doc/src/snippets/code/doc_src_qset.qdoc 3
       
    70 
       
    71     If you want to navigate through all the values stored in a QSet,
       
    72     you can use an iterator. QSet supports both \l{Java-style
       
    73     iterators} (QSetIterator and QMutableSetIterator) and \l{STL-style
       
    74     iterators} (QSet::iterator and QSet::const_iterator). Here's how
       
    75     to iterate over a QSet<QWidget *> using a Java-style iterator:
       
    76 
       
    77     \snippet doc/src/snippets/code/doc_src_qset.qdoc 4
       
    78 
       
    79     Here's the same code, but using an STL-style iterator:
       
    80 
       
    81     \snippet doc/src/snippets/code/doc_src_qset.qdoc 5
       
    82 
       
    83     QSet is unordered, so an iterator's sequence cannot be assumed to
       
    84     be predictable. If ordering by key is required, use a QMap.
       
    85 
       
    86     To navigate through a QSet, you can also use \l{foreach}:
       
    87 
       
    88     \snippet doc/src/snippets/code/doc_src_qset.qdoc 6
       
    89 
       
    90     Items can be removed from the set using remove(). There is also a
       
    91     clear() function that removes all items.
       
    92 
       
    93     QSet's value data type must be an \l{assignable data type}. You
       
    94     cannot, for example, store a QWidget as a value; instead, store a
       
    95     QWidget *. In addition, the type must provide \c operator==(), and
       
    96     there must also be a global qHash() function that returns a hash
       
    97     value for an argument of the key's type. See the QHash
       
    98     documentation for a list of types supported by qHash().
       
    99 
       
   100     Internally, QSet uses a hash table to perform lookups. The hash
       
   101     table automatically grows and shrinks to provide fast lookups
       
   102     without wasting memory. You can still control the size of the hash
       
   103     table by calling reserve(), if you already know approximately how
       
   104     many elements the QSet will contain, but this isn't necessary to
       
   105     obtain good performance. You can also call capacity() to retrieve
       
   106     the hash table's size.
       
   107 
       
   108     \sa QSetIterator, QMutableSetIterator, QHash, QMap
       
   109 */
       
   110 
       
   111 /*!
       
   112     \fn QSet::QSet()
       
   113 
       
   114     Constructs an empty set.
       
   115 
       
   116     \sa clear()
       
   117 */
       
   118 
       
   119 /*!
       
   120     \fn QSet::QSet(const QSet<T> &other)
       
   121 
       
   122     Constructs a copy of \a other.
       
   123 
       
   124     This operation occurs in \l{constant time}, because QSet is
       
   125     \l{implicitly shared}. This makes returning a QSet from a
       
   126     function very fast. If a shared instance is modified, it will be
       
   127     copied (copy-on-write), and this takes \l{linear time}.
       
   128 
       
   129     \sa operator=()
       
   130 */
       
   131 
       
   132 /*!
       
   133     \fn QSet<T> &QSet::operator=(const QSet<T> &other)
       
   134 
       
   135     Assigns the \a other set to this set and returns a reference to
       
   136     this set.  
       
   137 */
       
   138 
       
   139 /*!
       
   140     \fn bool QSet::operator==(const QSet<T> &other) const
       
   141 
       
   142     Returns true if the \a other set is equal to this set; otherwise
       
   143     returns false.
       
   144 
       
   145     Two sets are considered equal if they contain the same elements.
       
   146 
       
   147     This function requires the value type to implement \c operator==().
       
   148 
       
   149     \sa operator!=()
       
   150 */
       
   151 
       
   152 /*!
       
   153     \fn bool QSet::operator!=(const QSet<T> &other) const
       
   154 
       
   155     Returns true if the \a other set is not equal to this set; otherwise
       
   156     returns false.
       
   157 
       
   158     Two sets are considered equal if they contain the same elements.
       
   159 
       
   160     This function requires the value type to implement \c operator==().
       
   161 
       
   162     \sa operator==()
       
   163 */
       
   164 
       
   165 /*!
       
   166     \fn int QSet::size() const
       
   167 
       
   168     Returns the number of items in the set.
       
   169 
       
   170     \sa isEmpty(), count()
       
   171 */
       
   172 
       
   173 /*!
       
   174     \fn bool QSet::isEmpty() const
       
   175 
       
   176     Returns true if the set contains no elements; otherwise returns
       
   177     false.
       
   178 
       
   179     \sa size()
       
   180 */
       
   181 
       
   182 /*!
       
   183     \fn int QSet::capacity() const
       
   184 
       
   185     Returns the number of buckets in the set's internal hash
       
   186     table.
       
   187 
       
   188     The sole purpose of this function is to provide a means of fine
       
   189     tuning QSet's memory usage. In general, you will rarely ever need
       
   190     to call this function. If you want to know how many items are in
       
   191     the set, call size().
       
   192 
       
   193     \sa reserve(), squeeze()
       
   194 */
       
   195 
       
   196 /*! \fn void QSet::reserve(int size)
       
   197 
       
   198     Ensures that the set's internal hash table consists of at
       
   199     least \a size buckets.
       
   200 
       
   201     This function is useful for code that needs to build a huge set
       
   202     and wants to avoid repeated reallocation. For example:
       
   203 
       
   204     \snippet doc/src/snippets/code/doc_src_qset.qdoc 7
       
   205 
       
   206     Ideally, \a size should be slightly more than the maximum number
       
   207     of elements expected in the set. \a size doesn't have to be prime,
       
   208     because QSet will use a prime number internally anyway. If \a size
       
   209     is an underestimate, the worst that will happen is that the QSet
       
   210     will be a bit slower.
       
   211 
       
   212     In general, you will rarely ever need to call this function.
       
   213     QSet's internal hash table automatically shrinks or grows to
       
   214     provide good performance without wasting too much memory.
       
   215 
       
   216     \sa squeeze(), capacity()
       
   217 */
       
   218 
       
   219 /*!
       
   220     \fn void QSet::squeeze()
       
   221 
       
   222     Reduces the size of the set's internal hash table to save
       
   223     memory.
       
   224 
       
   225     The sole purpose of this function is to provide a means of fine
       
   226     tuning QSet's memory usage. In general, you will rarely ever
       
   227     need to call this function.
       
   228 
       
   229     \sa reserve(), capacity()
       
   230 */
       
   231 
       
   232 /*!
       
   233     \fn void QSet::detach()
       
   234 
       
   235     \internal
       
   236 
       
   237     Detaches this set from any other sets with which it may share
       
   238     data.
       
   239 
       
   240     \sa isDetached()
       
   241 */
       
   242 
       
   243 /*! \fn bool QSet::isDetached() const
       
   244 
       
   245     \internal
       
   246 
       
   247     Returns true if the set's internal data isn't shared with any
       
   248     other set object; otherwise returns false.
       
   249 
       
   250     \sa detach()
       
   251 */
       
   252 
       
   253 /*!
       
   254     \fn void QSet::setSharable(bool sharable)
       
   255     \internal
       
   256 */
       
   257 
       
   258 /*!
       
   259     \fn void QSet::clear()
       
   260 
       
   261     Removes all elements from the set.
       
   262 
       
   263     \sa remove()
       
   264 */
       
   265 
       
   266 /*!
       
   267     \fn bool QSet::remove(const T &value)
       
   268 
       
   269     Removes any occurrence of item \a value from the set. Returns
       
   270     true if an item was actually removed; otherwise returns false.
       
   271 
       
   272     \sa contains(), insert()
       
   273 */
       
   274 
       
   275 /*!
       
   276     \fn QSet::iterator QSet::erase(iterator pos)
       
   277     \since 4.2
       
   278 
       
   279     Removes the item at the iterator position \a pos from the set, and
       
   280     returns an iterator positioned at the next item in the set.
       
   281 
       
   282     Unlike remove(), this function never causes QSet to rehash its
       
   283     internal data structure. This means that it can safely be called
       
   284     while iterating, and won't affect the order of items in the set.
       
   285 
       
   286     \sa remove(), find()
       
   287 */
       
   288 
       
   289 /*! \fn QSet::const_iterator QSet::find(const T &value) const
       
   290     \since 4.2
       
   291 
       
   292     Returns a const iterator positioned at the item \a value in the
       
   293     set. If the set contains no item \a value, the function returns
       
   294     constEnd().
       
   295 
       
   296     \sa constFind(), contains()
       
   297 */
       
   298 
       
   299 /*! \fn QSet::iterator QSet::find(const T &value)
       
   300     \since 4.2
       
   301     \overload
       
   302 
       
   303     Returns a non-const iterator positioned at the item \a value in
       
   304     the set. If the set contains no item \a value, the function
       
   305     returns end(). 
       
   306 */
       
   307 
       
   308 /*! \fn QSet::const_iterator QSet::constFind(const T &value) const
       
   309     \since 4.2
       
   310 
       
   311     Returns a const iterator positioned at the item \a value in the
       
   312     set. If the set contains no item \a value, the function returns
       
   313     constEnd().
       
   314 
       
   315     \sa find(), contains()
       
   316 */
       
   317 
       
   318 /*!
       
   319     \fn bool QSet::contains(const T &value) const
       
   320 
       
   321     Returns true if the set contains item \a value; otherwise returns
       
   322     false.
       
   323 
       
   324     \sa insert(), remove(), find()
       
   325 */
       
   326 
       
   327 /*!
       
   328     \fn bool QSet::contains(const QSet<T> &other) const
       
   329     \since 4.6
       
   330 
       
   331     Returns true if the set contains all items from the \a other set;
       
   332     otherwise returns false.
       
   333 
       
   334     \sa insert(), remove(), find()
       
   335 */
       
   336 
       
   337 /*! \fn QSet::const_iterator QSet::begin() const
       
   338 
       
   339     Returns a const \l{STL-style iterator} positioned at the first
       
   340     item in the set.
       
   341 
       
   342     \sa constBegin(), end()
       
   343 */
       
   344 
       
   345 /*! \fn QSet::iterator QSet::begin()
       
   346     \since 4.2
       
   347     \overload
       
   348 
       
   349     Returns a non-const \l{STL-style iterator} positioned at the first
       
   350     item in the set.  
       
   351 */
       
   352 
       
   353 /*! \fn QSet::const_iterator QSet::constBegin() const
       
   354 
       
   355     Returns a const \l{STL-style iterator} positioned at the first
       
   356     item in the set.
       
   357 
       
   358     \sa begin(), constEnd()
       
   359 */
       
   360 
       
   361 /*! \fn QSet::const_iterator QSet::end() const
       
   362 
       
   363     Returns a const \l{STL-style iterator} positioned at the imaginary
       
   364     item after the last item in the set.
       
   365 
       
   366     \sa constEnd(), begin()
       
   367 */
       
   368 
       
   369 /*! \fn QSet::iterator QSet::end()
       
   370     \since 4.2
       
   371     \overload
       
   372 
       
   373     Returns a non-const \l{STL-style iterator} pointing to the
       
   374     imaginary item after the last item in the set.
       
   375 */
       
   376 
       
   377 /*! \fn QSet::const_iterator QSet::constEnd() const
       
   378 
       
   379     Returns a const \l{STL-style iterator} pointing to the imaginary
       
   380     item after the last item in the set.
       
   381 
       
   382     \sa constBegin(), end()
       
   383 */
       
   384 
       
   385 /*!
       
   386     \typedef QSet::Iterator
       
   387     \since 4.2
       
   388 
       
   389     Qt-style synonym for QSet::iterator.
       
   390 */
       
   391 
       
   392 /*!
       
   393     \typedef QSet::ConstIterator
       
   394 
       
   395     Qt-style synonym for QSet::const_iterator.
       
   396 */
       
   397 
       
   398 /*!
       
   399     \typedef QSet::const_pointer
       
   400 
       
   401     Typedef for const T *. Provided for STL compatibility.
       
   402 */
       
   403 
       
   404 /*!
       
   405     \typedef QSet::const_reference
       
   406 
       
   407     Typedef for const T &. Provided for STL compatibility.
       
   408 */
       
   409 
       
   410 /*!
       
   411     \typedef QSet::difference_type
       
   412 
       
   413     Typedef for const ptrdiff_t. Provided for STL compatibility.
       
   414 */
       
   415 
       
   416 /*!
       
   417     \typedef QSet::key_type
       
   418 
       
   419     Typedef for T. Provided for STL compatibility.
       
   420 */
       
   421 
       
   422 /*!
       
   423     \typedef QSet::pointer
       
   424 
       
   425     Typedef for T *. Provided for STL compatibility.
       
   426 */
       
   427 
       
   428 /*!
       
   429     \typedef QSet::reference
       
   430 
       
   431     Typedef for T &. Provided for STL compatibility.
       
   432 */
       
   433 
       
   434 /*!
       
   435     \typedef QSet::size_type
       
   436 
       
   437     Typedef for int. Provided for STL compatibility.
       
   438 */
       
   439 
       
   440 /*!
       
   441     \typedef QSet::value_type
       
   442 
       
   443     Typedef for T. Provided for STL compatibility.
       
   444 */
       
   445 
       
   446 /*!
       
   447     \fn QSet::const_iterator QSet::insert(const T &value)
       
   448 
       
   449     Inserts item \a value into the set, if \a value isn't already
       
   450     in the set, and returns an iterator pointing at the inserted
       
   451     item.
       
   452 
       
   453     \sa operator<<(), remove(), contains()
       
   454 */
       
   455 
       
   456 /*!
       
   457     \fn QSet<T> &QSet::unite(const QSet<T> &other)
       
   458 
       
   459     Each item in the \a other set that isn't already in this set is
       
   460     inserted into this set. A reference to this set is returned.
       
   461 
       
   462     \sa operator|=(), intersect(), subtract()
       
   463 */
       
   464 
       
   465 /*!
       
   466     \fn QSet<T> &QSet::intersect(const QSet<T> &other)
       
   467 
       
   468     Removes all items from this set that are not contained in the
       
   469     \a other set. A reference to this set is returned.
       
   470 
       
   471     \sa operator&=(), unite(), subtract()
       
   472 */
       
   473 
       
   474 /*!
       
   475     \fn QSet<T> &QSet::subtract(const QSet<T> &other)
       
   476 
       
   477     Removes all items from  this set that are contained in the 
       
   478     \a other set. Returns a reference to this set.
       
   479 
       
   480     \sa operator-=(), unite(), intersect()
       
   481 */
       
   482 
       
   483 /*!
       
   484     \fn bool QSet::empty() const
       
   485 
       
   486     Returns true if the set is empty. This function is provided
       
   487     for STL compatibility. It is equivalent to isEmpty().  
       
   488 */
       
   489 
       
   490 /*!
       
   491     \fn bool QSet::count() const
       
   492 
       
   493     Same as size().
       
   494 */
       
   495 
       
   496 /*!
       
   497     \fn QSet<T> &QSet::operator<<(const T &value)
       
   498     \fn QSet<T> &QSet::operator+=(const T &value)
       
   499     \fn QSet<T> &QSet::operator|=(const T &value)
       
   500 
       
   501     Inserts a new item \a value and returns a reference to the set.
       
   502     If \a value already exists in the set, the set is left unchanged.
       
   503 
       
   504     \sa insert()
       
   505 */
       
   506 
       
   507 /*!
       
   508     \fn QSet<T> &QSet::operator-=(const T &value)
       
   509 
       
   510     Removes the occurrence of item \a value from the set, if 
       
   511     it is found, and returns a reference to the set. If the
       
   512     \a value is not contained the set, nothing is removed.
       
   513 
       
   514     \sa remove()
       
   515 */
       
   516 
       
   517 /*!
       
   518     \fn QSet<T> &QSet::operator|=(const QSet<T> &other)
       
   519     \fn QSet<T> &QSet::operator+=(const QSet<T> &other)
       
   520 
       
   521     Same as unite(\a other).
       
   522 
       
   523     \sa operator|(), operator&=(), operator-=()
       
   524 */
       
   525 
       
   526 /*!
       
   527     \fn QSet<T> &QSet::operator&=(const QSet<T> &other)
       
   528 
       
   529     Same as intersect(\a other).
       
   530 
       
   531     \sa operator&(), operator|=(), operator-=()
       
   532 */
       
   533 
       
   534 /*!
       
   535     \fn QSet<T> &QSet::operator&=(const T &value)
       
   536 
       
   537     \overload
       
   538 
       
   539     Same as intersect(\e{other}), if we consider \e{other} to be a set
       
   540     that contains the singleton \a value.  
       
   541 */
       
   542 
       
   543 
       
   544 /*!
       
   545     \fn QSet<T> &QSet::operator-=(const QSet<T> &other)
       
   546 
       
   547     Same as subtract(\a{other}).
       
   548 
       
   549     \sa operator-(), operator|=(), operator&=()
       
   550 */
       
   551 
       
   552 /*!
       
   553     \fn QSet<T> QSet::operator|(const QSet<T> &other) const
       
   554     \fn QSet<T> QSet::operator+(const QSet<T> &other) const
       
   555 
       
   556     Returns a new QSet that is the union of this set and the 
       
   557     \a other set.
       
   558 
       
   559     \sa unite(), operator|=(), operator&(), operator-()
       
   560 */
       
   561 
       
   562 /*!
       
   563     \fn QSet<T> QSet::operator&(const QSet<T> &other) const
       
   564 
       
   565     Returns a new QSet that is the intersection of this set and the
       
   566     \a other set.
       
   567 
       
   568     \sa intersect(), operator&=(), operator|(), operator-()
       
   569 */
       
   570 
       
   571 /*!
       
   572     \fn QSet<T> QSet::operator-(const QSet<T> &other) const
       
   573 
       
   574     Returns a new QSet that is the set difference of this set and
       
   575     the \a other set, i.e., this set - \a other set.
       
   576 
       
   577     \sa subtract(), operator-=(), operator|(), operator&()
       
   578 */
       
   579 
       
   580 /*!
       
   581     \fn QSet<T> QSet::operator-(const QSet<T> &other)
       
   582     \fn QSet<T> QSet::operator|(const QSet<T> &other)
       
   583     \fn QSet<T> QSet::operator+(const QSet<T> &other)
       
   584     \fn QSet<T> QSet::operator&(const QSet<T> &other)
       
   585     \internal
       
   586 
       
   587     These will go away in Qt 5.
       
   588 */
       
   589 
       
   590 /*!
       
   591     \class QSet::iterator
       
   592     \since 4.2
       
   593     \brief The QSet::iterator class provides an STL-style non-const iterator for QSet.
       
   594 
       
   595     QSet features both \l{STL-style iterators} and
       
   596     \l{Java-style iterators}. The STL-style iterators are more
       
   597     low-level and more cumbersome to use; on the other hand, they are
       
   598     slightly faster and, for developers who already know STL, have
       
   599     the advantage of familiarity.
       
   600 
       
   601     QSet<T>::iterator allows you to iterate over a QSet and to remove
       
   602     items (using QSet::erase()) while you iterate. (QSet doesn't let
       
   603     you \e modify a value through an iterator, because that
       
   604     would potentially require moving the value in the internal hash
       
   605     table used by QSet.) If you want to iterate over a const QSet,
       
   606     you should use QSet::const_iterator. It is generally good
       
   607     practice to use QSet::const_iterator on a non-const QSet as well,
       
   608     unless you need to change the QSet through the iterator. Const
       
   609     iterators are slightly faster, and can improve code readability.
       
   610 
       
   611     QSet\<T\>::iterator allows you to iterate over a QSet\<T\> and
       
   612     modify it as you go (using QSet::erase()). However, 
       
   613 
       
   614     The default QSet::iterator constructor creates an uninitialized
       
   615     iterator. You must initialize it using a function like
       
   616     QSet::begin(), QSet::end(), or QSet::insert() before you can
       
   617     start iterating. Here's a typical loop that prints all the items
       
   618     stored in a set:
       
   619 
       
   620     \snippet doc/src/snippets/code/doc_src_qset.qdoc 8
       
   621 
       
   622     Here's a loop that removes certain items (all those that start
       
   623     with 'J') from a set while iterating:
       
   624 
       
   625     \snippet doc/src/snippets/code/doc_src_qset.qdoc 9
       
   626 
       
   627     STL-style iterators can be used as arguments to \l{generic
       
   628     algorithms}. For example, here's how to find an item in the set
       
   629     using the qFind() algorithm:
       
   630 
       
   631     \snippet doc/src/snippets/code/doc_src_qset.qdoc 10
       
   632 
       
   633     Multiple iterators can be used on the same set. However, you may
       
   634     not attempt to modify the container while iterating on it.
       
   635 
       
   636     \sa QSet::const_iterator, QMutableSetIterator
       
   637 */
       
   638 
       
   639 /*!
       
   640     \class QSet::const_iterator
       
   641     \brief The QSet::const_iterator class provides an STL-style const iterator for QSet.
       
   642     \since 4.2
       
   643 
       
   644     QSet features both \l{STL-style iterators} and
       
   645     \l{Java-style iterators}. The STL-style iterators are more
       
   646     low-level and more cumbersome to use; on the other hand, they are
       
   647     slightly faster and, for developers who already know STL, have
       
   648     the advantage of familiarity.
       
   649 
       
   650     QSet\<Key, T\>::const_iterator allows you to iterate over a QSet.
       
   651     If you want to modify the QSet as you iterate over it, you must
       
   652     use QSet::iterator instead. It is generally good practice to use
       
   653     QSet::const_iterator on a non-const QSet as well, unless you need
       
   654     to change the QSet through the iterator. Const iterators are
       
   655     slightly faster, and can improve code readability.
       
   656 
       
   657     The default QSet::const_iterator constructor creates an
       
   658     uninitialized iterator. You must initialize it using a function
       
   659     like QSet::begin(), QSet::end(), or QSet::insert() before you can
       
   660     start iterating. Here's a typical loop that prints all the items
       
   661     stored in a set:
       
   662 
       
   663     \snippet doc/src/snippets/code/doc_src_qset.qdoc 11
       
   664 
       
   665     STL-style iterators can be used as arguments to \l{generic
       
   666     algorithms}. For example, here's how to find an item in the set
       
   667     using the qFind() algorithm:
       
   668 
       
   669     \snippet doc/src/snippets/code/doc_src_qset.qdoc 12
       
   670 
       
   671     Multiple iterators can be used on the same set. However, you may
       
   672     not attempt to modify the container while iterating on it.
       
   673 
       
   674     \sa QSet::iterator, QSetIterator
       
   675 */
       
   676 
       
   677 /*!
       
   678     \fn QSet::iterator::iterator()
       
   679     \fn QSet::const_iterator::const_iterator()
       
   680 
       
   681     Constructs an uninitialized iterator.
       
   682 
       
   683     Functions like operator*() and operator++() should not be called
       
   684     on an uninitialized iterator. Use operator=() to assign a value
       
   685     to it before using it.
       
   686 
       
   687     \sa QSet::begin(), QSet::end()
       
   688 */
       
   689 
       
   690 /*! 
       
   691     \fn QSet::iterator::iterator(typename Hash::iterator i)
       
   692     \fn QSet::const_iterator::const_iterator(typename Hash::const_iterator i)
       
   693 
       
   694     \internal
       
   695 */
       
   696 
       
   697 /*!
       
   698   \typedef QSet::iterator::iterator_category
       
   699   \typedef QSet::const_iterator::iterator_category
       
   700 
       
   701   Synonyms for \e {std::bidirectional_iterator_tag} indicating
       
   702   these iterators are bidirectional iterators.
       
   703  */
       
   704 
       
   705 /*!
       
   706     \typedef QSet::iterator::difference_type
       
   707     \typedef QSet::const_iterator::difference_type
       
   708 
       
   709     \internal
       
   710 */
       
   711 
       
   712 /*!
       
   713     \typedef QSet::iterator::value_type
       
   714     \typedef QSet::const_iterator::value_type
       
   715 
       
   716     \internal
       
   717 */
       
   718 
       
   719 /*!
       
   720     \typedef QSet::iterator::pointer
       
   721     \typedef QSet::const_iterator::pointer
       
   722 
       
   723     \internal
       
   724 */
       
   725 
       
   726 /*!
       
   727     \typedef QSet::iterator::reference
       
   728     \typedef QSet::const_iterator::reference
       
   729 
       
   730     \internal
       
   731 */
       
   732 
       
   733 /*!
       
   734     \fn QSet::iterator::iterator(const iterator &other)
       
   735     \fn QSet::const_iterator::const_iterator(const const_iterator &other)
       
   736 
       
   737     Constructs a copy of \a other.
       
   738 */
       
   739 
       
   740 /*!
       
   741     \fn QSet::const_iterator::const_iterator(const iterator &other)
       
   742     \since 4.2
       
   743     \overload
       
   744 
       
   745     Constructs a copy of \a other.
       
   746 */
       
   747 
       
   748 /*!
       
   749     \fn QSet::iterator &QSet::iterator::operator=(const iterator &other)
       
   750     \fn QSet::const_iterator &QSet::const_iterator::operator=(const const_iterator &other)
       
   751 
       
   752     Assigns \a other to this iterator.
       
   753 */
       
   754 
       
   755 /*!
       
   756     \fn const T &QSet::iterator::operator*() const
       
   757     \fn const T &QSet::const_iterator::operator*() const
       
   758 
       
   759     Returns a reference to the current item.
       
   760 
       
   761     \sa operator->()
       
   762 */
       
   763 
       
   764 /*!
       
   765     \fn const T *QSet::iterator::operator->() const
       
   766     \fn const T *QSet::const_iterator::operator->() const
       
   767 
       
   768     Returns a pointer to the current item.
       
   769 
       
   770     \sa operator*()
       
   771 */
       
   772 
       
   773 /*!
       
   774     \fn bool QSet::iterator::operator==(const iterator &other) const
       
   775     \fn bool QSet::const_iterator::operator==(const const_iterator &other) const
       
   776 
       
   777     Returns true if \a other points to the same item as this
       
   778     iterator; otherwise returns false.
       
   779 
       
   780     \sa operator!=()
       
   781 */
       
   782 
       
   783 /*!
       
   784     \fn bool QSet::iterator::operator==(const const_iterator &other) const
       
   785     \fn bool QSet::iterator::operator!=(const const_iterator &other) const
       
   786 
       
   787     \overload
       
   788 */
       
   789 
       
   790 /*!
       
   791     \fn bool QSet::iterator::operator!=(const iterator &other) const
       
   792     \fn bool QSet::const_iterator::operator!=(const const_iterator &other) const
       
   793 
       
   794     Returns true if \a other points to a different item than this
       
   795     iterator; otherwise returns false.
       
   796 
       
   797     \sa operator==()
       
   798 */
       
   799 
       
   800 /*!
       
   801     \fn QSet::iterator &QSet::iterator::operator++()
       
   802     \fn QSet::const_iterator &QSet::const_iterator::operator++()
       
   803 
       
   804     The prefix ++ operator (\c{++it}) advances the iterator to the
       
   805     next item in the set and returns an iterator to the new current
       
   806     item.
       
   807 
       
   808     Calling this function on QSet::constEnd() leads to
       
   809     undefined results.
       
   810 
       
   811     \sa operator--()
       
   812 */
       
   813 
       
   814 /*!
       
   815     \fn QSet::iterator QSet::iterator::operator++(int)
       
   816     \fn QSet::const_iterator QSet::const_iterator::operator++(int)
       
   817 
       
   818     \overload
       
   819 
       
   820     The postfix ++ operator (\c{it++}) advances the iterator to the
       
   821     next item in the set and returns an iterator to the previously
       
   822     current item.
       
   823 */
       
   824 
       
   825 /*!
       
   826     \fn QSet::iterator &QSet::iterator::operator--()
       
   827     \fn QSet::const_iterator &QSet::const_iterator::operator--()
       
   828 
       
   829     The prefix -- operator (\c{--it}) makes the preceding item
       
   830     current and returns an iterator to the new current item.
       
   831 
       
   832     Calling this function on QSet::begin() leads to undefined
       
   833     results.
       
   834 
       
   835     \sa operator++()
       
   836 */
       
   837 
       
   838 /*!
       
   839     \fn QSet::iterator QSet::iterator::operator--(int)
       
   840     \fn QSet::const_iterator QSet::const_iterator::operator--(int)
       
   841 
       
   842     \overload
       
   843 
       
   844     The postfix -- operator (\c{it--}) makes the preceding item
       
   845     current and returns an iterator to the previously current item.
       
   846 */
       
   847 
       
   848 /*!
       
   849     \fn QSet::iterator QSet::iterator::operator+(int j) const
       
   850     \fn QSet::const_iterator QSet::const_iterator::operator+(int j) const
       
   851 
       
   852     Returns an iterator to the item at \a j positions forward from
       
   853     this iterator. (If \a j is negative, the iterator goes backward.)
       
   854 
       
   855     This operation can be slow for large \a j values.
       
   856 
       
   857     \sa operator-()
       
   858 */
       
   859 
       
   860 /*!
       
   861     \fn QSet::iterator QSet::iterator::operator-(int j) const
       
   862     \fn QSet::const_iterator QSet::const_iterator::operator-(int j) const
       
   863 
       
   864     Returns an iterator to the item at \a j positions backward from
       
   865     this iterator. (If \a j is negative, the iterator goes forward.)
       
   866 
       
   867     This operation can be slow for large \a j values.
       
   868 
       
   869     \sa operator+()
       
   870 */
       
   871 
       
   872 /*!
       
   873     \fn QSet::iterator &QSet::iterator::operator+=(int j)
       
   874     \fn QSet::const_iterator &QSet::const_iterator::operator+=(int j)
       
   875 
       
   876     Advances the iterator by \a j items. (If \a j is negative, the
       
   877     iterator goes backward.)
       
   878 
       
   879     This operation can be slow for large \a j values.
       
   880 
       
   881     \sa operator-=(), operator+()
       
   882 */
       
   883 
       
   884 /*!
       
   885     \fn QSet::iterator &QSet::iterator::operator-=(int j)
       
   886     \fn QSet::const_iterator &QSet::const_iterator::operator-=(int j)
       
   887 
       
   888     Makes the iterator go back by \a j items. (If \a j is negative,
       
   889     the iterator goes forward.)
       
   890 
       
   891     This operation can be slow for large \a j values.
       
   892 
       
   893     \sa operator+=(), operator-()
       
   894 */
       
   895 
       
   896 /*! \fn QList<T> QSet<T>::toList() const
       
   897 
       
   898     Returns a new QList containing the elements in the set. The
       
   899     order of the elements in the QList is undefined.
       
   900 
       
   901     Example:
       
   902 
       
   903     \snippet doc/src/snippets/code/doc_src_qset.qdoc 13
       
   904 
       
   905     \sa fromList(), QList::fromSet(), qSort()
       
   906 */
       
   907 
       
   908 /*! \fn QList<T> QSet<T>::values() const
       
   909 
       
   910     Returns a new QList containing the elements in the set. The
       
   911     order of the elements in the QList is undefined.
       
   912 
       
   913     This is the same as toList().
       
   914 
       
   915     \sa fromList(), QList::fromSet(), qSort()
       
   916 */
       
   917 
       
   918 
       
   919 /*! \fn QSet<T> QSet<T>::fromList(const QList<T> &list)
       
   920 
       
   921     Returns a new QSet object containing the data contained in \a
       
   922     list. Since QSet doesn't allow duplicates, the resulting QSet
       
   923     might be smaller than the \a list, because QList can contain
       
   924     duplicates.
       
   925 
       
   926     Example:
       
   927 
       
   928     \snippet doc/src/snippets/code/doc_src_qset.qdoc 14
       
   929 
       
   930     \sa toList(), QList::toSet()
       
   931 */
       
   932 
       
   933 /*!
       
   934     \fn QDataStream &operator<<(QDataStream &out, const QSet<T> &set)
       
   935     \relates QSet
       
   936 
       
   937     Writes the \a set to stream \a out.
       
   938 
       
   939     This function requires the value type to implement \c operator<<().
       
   940 
       
   941     \sa \link datastreamformat.html Format of the QDataStream operators \endlink
       
   942 */
       
   943 
       
   944 /*!
       
   945     \fn QDataStream &operator>>(QDataStream &in, QSet<T> &set)
       
   946     \relates QSet
       
   947 
       
   948     Reads a set from stream \a in into \a set.
       
   949 
       
   950     This function requires the value type to implement \c operator>>().
       
   951 
       
   952     \sa \link datastreamformat.html Format of the QDataStream operators \endlink
       
   953 */