Remove deprecated algorithms from documentation
Change-Id: Ie1eff48696c62ed23fedda1a9e711aeb8264432f Reviewed-by: Topi Reiniö <topi.reinio@qt.io>bb10
parent
69d9b2b6fd
commit
5023c0beb5
|
|
@ -49,316 +49,19 @@
|
|||
****************************************************************************/
|
||||
|
||||
//! [0]
|
||||
QStringList list;
|
||||
list << "one" << "two" << "three";
|
||||
|
||||
qFill(list.begin(), list.end(), "eleven");
|
||||
// list: [ "eleven", "eleven", "eleven" ]
|
||||
//! [0]
|
||||
|
||||
|
||||
//! [1]
|
||||
qFill(list.begin() + 1, list.end(), "six");
|
||||
// list: [ "eleven", "six", "six" ]
|
||||
//! [1]
|
||||
|
||||
|
||||
//! [2]
|
||||
QChar resolveEntity(const QString &entity)
|
||||
{
|
||||
static const QLatin1String name_table[] = {
|
||||
"AElig", "Aacute", ..., "zwnj"
|
||||
};
|
||||
static const ushort value_table[] = {
|
||||
0x0061, 0x00c1, ..., 0x200c
|
||||
};
|
||||
int N = sizeof(name_table) / sizeof(name_table[0]);
|
||||
|
||||
const QLatin1String *name = qBinaryFind(name_table, name_table + N,
|
||||
entity);
|
||||
int index = name - name_table;
|
||||
if (index == N)
|
||||
return QChar();
|
||||
|
||||
return QChar(value_table[index]);
|
||||
}
|
||||
//! [2]
|
||||
|
||||
|
||||
//! [3]
|
||||
QChar resolveEntity(const QString &entity)
|
||||
{
|
||||
static QMap<QString, int> entityMap;
|
||||
|
||||
if (!entityMap) {
|
||||
entityMap.insert("AElig", 0x0061);
|
||||
entityMap.insert("Aacute", 0x00c1);
|
||||
...
|
||||
entityMap.insert("zwnj", 0x200c);
|
||||
}
|
||||
return QChar(entityMap.value(entity));
|
||||
}
|
||||
//! [3]
|
||||
|
||||
|
||||
//! [4]
|
||||
QStringList list;
|
||||
list << "one" << "two" << "three";
|
||||
|
||||
QList<QString> list1(3);
|
||||
qCopy(list.begin(), list.end(), list1.begin());
|
||||
// list1: [ "one", "two", "three" ]
|
||||
|
||||
QList<QString> list2(8);
|
||||
qCopy(list.begin(), list.end(), list2.begin() + 2);
|
||||
// list2: [ "", "", "one", "two", "three", "", "", "" ]
|
||||
//! [4]
|
||||
|
||||
|
||||
//! [5]
|
||||
QStringList list;
|
||||
list << "one" << "two" << "three";
|
||||
|
||||
QList<QString> backList(5);
|
||||
qCopyBackward(list.begin(), list.end(), backList.end());
|
||||
// backList: [ "", "", "one", "two", "three" ]
|
||||
//! [5]
|
||||
|
||||
|
||||
//! [6]
|
||||
QStringList listLeft;
|
||||
listLeft << "one" << "two" << "three";
|
||||
|
||||
QList<QString> listRight(3);
|
||||
listRight[0] = "one";
|
||||
listRight[1] = "two";
|
||||
listRight[2] = "three";
|
||||
|
||||
bool ret1 = qEqual(listLeft.begin(), listLeft.end(), listRight.begin());
|
||||
// ret1 == true
|
||||
|
||||
listRight[2] = "seven";
|
||||
bool ret2 = qEqual(listLeft.begin(), listLeft.end(), listRight.begin());
|
||||
// ret2 == false
|
||||
//! [6]
|
||||
|
||||
|
||||
//! [7]
|
||||
QStringList list;
|
||||
list << "one" << "two" << "three";
|
||||
|
||||
qFill(list.begin(), list.end(), "eleven");
|
||||
// list: [ "eleven", "eleven", "eleven" ]
|
||||
|
||||
qFill(list.begin() + 1, list.end(), "six");
|
||||
// list: [ "eleven", "six", "six" ]
|
||||
//! [7]
|
||||
|
||||
|
||||
//! [8]
|
||||
QStringList list;
|
||||
list << "one" << "two" << "three";
|
||||
|
||||
QStringList::iterator i1 = qFind(list.begin(), list.end(), "two");
|
||||
// i1 == list.begin() + 1
|
||||
|
||||
QStringList::iterator i2 = qFind(list.begin(), list.end(), "seventy");
|
||||
// i2 == list.end()
|
||||
//! [8]
|
||||
|
||||
|
||||
//! [9]
|
||||
QList<int> list;
|
||||
list << 3 << 3 << 6 << 6 << 6 << 8;
|
||||
|
||||
int countOf6 = 0;
|
||||
qCount(list.begin(), list.end(), 6, countOf6);
|
||||
// countOf6 == 3
|
||||
|
||||
int countOf7 = 0;
|
||||
qCount(list.begin(), list.end(), 7, countOf7);
|
||||
// countOf7 == 0
|
||||
//! [9]
|
||||
|
||||
|
||||
//! [10]
|
||||
double pi = 3.14;
|
||||
double e = 2.71;
|
||||
|
||||
qSwap(pi, e);
|
||||
// pi == 2.71, e == 3.14
|
||||
//! [10]
|
||||
//! [0]
|
||||
|
||||
|
||||
//! [11]
|
||||
QList<int> list;
|
||||
list << 33 << 12 << 68 << 6 << 12;
|
||||
qSort(list.begin(), list.end());
|
||||
// list: [ 6, 12, 12, 33, 68 ]
|
||||
//! [11]
|
||||
|
||||
|
||||
//! [12]
|
||||
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
|
||||
{
|
||||
return s1.toLower() < s2.toLower();
|
||||
}
|
||||
|
||||
int doSomething()
|
||||
{
|
||||
QStringList list;
|
||||
list << "AlPha" << "beTA" << "gamma" << "DELTA";
|
||||
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
|
||||
// list: [ "AlPha", "beTA", "DELTA", "gamma" ]
|
||||
}
|
||||
//! [12]
|
||||
|
||||
|
||||
//! [13]
|
||||
QList<int> list;
|
||||
list << 33 << 12 << 68 << 6 << 12;
|
||||
qSort(list.begin(), list.end(), qGreater<int>());
|
||||
// list: [ 68, 33, 12, 12, 6 ]
|
||||
//! [13]
|
||||
|
||||
|
||||
//! [14]
|
||||
QStringList list;
|
||||
list << "AlPha" << "beTA" << "gamma" << "DELTA";
|
||||
|
||||
QMap<QString, QString> map;
|
||||
foreach (const QString &str, list)
|
||||
map.insert(str.toLower(), str);
|
||||
|
||||
list = map.values();
|
||||
//! [14]
|
||||
|
||||
|
||||
//! [15]
|
||||
QList<int> list;
|
||||
list << 33 << 12 << 68 << 6 << 12;
|
||||
qStableSort(list.begin(), list.end());
|
||||
// list: [ 6, 12, 12, 33, 68 ]
|
||||
//! [15]
|
||||
|
||||
|
||||
//! [16]
|
||||
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
|
||||
{
|
||||
return s1.toLower() < s2.toLower();
|
||||
}
|
||||
|
||||
int doSomething()
|
||||
{
|
||||
QStringList list;
|
||||
list << "AlPha" << "beTA" << "gamma" << "DELTA";
|
||||
qStableSort(list.begin(), list.end(), caseInsensitiveLessThan);
|
||||
// list: [ "AlPha", "beTA", "DELTA", "gamma" ]
|
||||
}
|
||||
//! [16]
|
||||
|
||||
|
||||
//! [17]
|
||||
QList<int> list;
|
||||
list << 33 << 12 << 68 << 6 << 12;
|
||||
qStableSort(list.begin(), list.end(), qGreater<int>());
|
||||
// list: [ 68, 33, 12, 12, 6 ]
|
||||
//! [17]
|
||||
|
||||
|
||||
//! [18]
|
||||
QList<int> list;
|
||||
list << 3 << 3 << 6 << 6 << 6 << 8;
|
||||
|
||||
QList<int>::iterator i = qLowerBound(list.begin(), list.end(), 5);
|
||||
list.insert(i, 5);
|
||||
// list: [ 3, 3, 5, 6, 6, 6, 8 ]
|
||||
|
||||
i = qLowerBound(list.begin(), list.end(), 12);
|
||||
list.insert(i, 12);
|
||||
// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]
|
||||
//! [18]
|
||||
|
||||
|
||||
//! [19]
|
||||
QList<int> list;
|
||||
list << 3 << 3 << 6 << 6 << 6 << 8;
|
||||
QList<int>::iterator begin6 =
|
||||
qLowerBound(list.begin(), list.end(), 6);
|
||||
QList<int>::iterator end6 =
|
||||
qUpperBound(begin6, list.end(), 6);
|
||||
|
||||
QList<int>::iterator i = begin6;
|
||||
while (i != end6) {
|
||||
*i = 7;
|
||||
++i;
|
||||
}
|
||||
// list: [ 3, 3, 7, 7, 7, 8 ]
|
||||
//! [19]
|
||||
|
||||
|
||||
//! [20]
|
||||
QList<int> list;
|
||||
list << 3 << 3 << 6 << 6 << 6 << 8;
|
||||
|
||||
QList<int>::iterator i = qUpperBound(list.begin(), list.end(), 5);
|
||||
list.insert(i, 5);
|
||||
// list: [ 3, 3, 5, 6, 6, 6, 8 ]
|
||||
|
||||
i = qUpperBound(list.begin(), list.end(), 12);
|
||||
list.insert(i, 12);
|
||||
// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]
|
||||
//! [20]
|
||||
|
||||
|
||||
//! [21]
|
||||
QList<int> list;
|
||||
list << 3 << 3 << 6 << 6 << 6 << 8;
|
||||
QList<int>::iterator begin6 =
|
||||
qLowerBound(list.begin(), list.end(), 6);
|
||||
QList<int>::iterator end6 =
|
||||
qUpperBound(list.begin(), list.end(), 6);
|
||||
|
||||
QList<int>::iterator i = begin6;
|
||||
while (i != end6) {
|
||||
*i = 7;
|
||||
++i;
|
||||
}
|
||||
// list: [ 3, 3, 7, 7, 7, 8 ]
|
||||
//! [21]
|
||||
|
||||
|
||||
//! [22]
|
||||
QList<int> list;
|
||||
list << 3 << 3 << 6 << 6 << 6 << 8;
|
||||
|
||||
QList<int>::iterator i =
|
||||
qBinaryFind(list.begin(), list.end(), 6);
|
||||
// i == list.begin() + 2 (or 3 or 4)
|
||||
//! [22]
|
||||
|
||||
|
||||
//! [23]
|
||||
//! [1]
|
||||
QList<Employee *> list;
|
||||
list.append(new Employee("Blackpool", "Stephen"));
|
||||
list.append(new Employee("Twist", "Oliver"));
|
||||
|
||||
qDeleteAll(list.begin(), list.end());
|
||||
list.clear();
|
||||
//! [23]
|
||||
|
||||
|
||||
//! [24]
|
||||
QList<int> list;
|
||||
list << 33 << 12 << 68 << 6 << 12;
|
||||
qSort(list.begin(), list.end(), qLess<int>());
|
||||
// list: [ 6, 12, 12, 33, 68 ]
|
||||
//! [24]
|
||||
|
||||
|
||||
//! [25]
|
||||
QList<int> list;
|
||||
list << 33 << 12 << 68 << 6 << 12;
|
||||
qSort(list.begin(), list.end(), qGreater<int>());
|
||||
// list: [ 68, 33, 12, 12, 6 ]
|
||||
//! [25]
|
||||
//! [1]
|
||||
|
|
|
|||
|
|
@ -47,8 +47,7 @@
|
|||
meet a certain set of requirements.
|
||||
|
||||
Different algorithms can have different requirements for the
|
||||
iterators they accept. For example, qFill() accepts two
|
||||
\l {forward iterators}. The iterator types required are specified
|
||||
iterators they accept. The iterator types required are specified
|
||||
for each algorithm. If an iterator of the wrong type is passed (for
|
||||
example, if QList::ConstIterator is passed as an
|
||||
\l {Output Iterators}{output iterator}), you will always get a
|
||||
|
|
@ -63,21 +62,7 @@
|
|||
The generic algorithms can be used on other container classes
|
||||
than those provided by Qt and STL. The syntax of STL-style
|
||||
iterators is modeled after C++ pointers, so it's possible to use
|
||||
plain arrays as containers and plain pointers as iterators. A
|
||||
common idiom is to use qBinaryFind() together with two static
|
||||
arrays: one that contains a list of keys, and another that
|
||||
contains a list of associated values. For example, the following
|
||||
code will look up an HTML entity (e.g., \c &) in the \c
|
||||
name_table array and return the corresponding Unicode value from
|
||||
the \c value_table if the entity is recognized:
|
||||
|
||||
\snippet code/doc_src_qalgorithms.cpp 2
|
||||
|
||||
This kind of code is for advanced users only; for most
|
||||
applications, a QMap- or QHash-based approach would work just as
|
||||
well:
|
||||
|
||||
\snippet code/doc_src_qalgorithms.cpp 3
|
||||
plain arrays as containers and plain pointers as iterators.
|
||||
|
||||
\section1 Types of Iterators
|
||||
|
||||
|
|
@ -156,7 +141,7 @@
|
|||
Exchanges the values of variables \a var1 and \a var2.
|
||||
|
||||
Example:
|
||||
\snippet code/doc_src_qalgorithms.cpp 10
|
||||
\snippet code/doc_src_qalgorithms.cpp 0
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
|
@ -168,7 +153,7 @@
|
|||
example, \c{QWidget *}).
|
||||
|
||||
Example:
|
||||
\snippet code/doc_src_qalgorithms.cpp 23
|
||||
\snippet code/doc_src_qalgorithms.cpp 1
|
||||
|
||||
Notice that qDeleteAll() doesn't remove the items from the
|
||||
container; it merely calls \c delete on them. In the example
|
||||
|
|
|
|||
Loading…
Reference in New Issue