Doc: Update boost::bind()/std::tr1::bind() to std::bind()
boost::bind() became part of the C++11 standard with minor modifications. Present the standard version as the main one to use, but list the others as alternatives. Change-Id: If419d8d24c0925119d3b9f7ff76be44981351bc0 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
This commit is contained in:
parent
eb921e6edc
commit
3567f4c2fc
@ -136,7 +136,7 @@ bool QString::contains(const QRegExp ®exp) const;
|
|||||||
|
|
||||||
|
|
||||||
//! [10]
|
//! [10]
|
||||||
boost::bind(&QString::contains, QRegExp("^\\S+$")); // matches strings without whitespace
|
std::bind(&QString::contains, QRegExp("^\\S+$")); // matches strings without whitespace
|
||||||
//! [10]
|
//! [10]
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ bool contains(const QString &string)
|
|||||||
|
|
||||||
//! [12]
|
//! [12]
|
||||||
QStringList strings = ...;
|
QStringList strings = ...;
|
||||||
boost::bind(static_cast<bool(QString::*)(const QRegExp&)>( &QString::contains ), QRegExp("..." ));
|
std::bind(static_cast<bool(QString::*)(const QRegExp&)>( &QString::contains ), QRegExp("..." ));
|
||||||
//! [12]
|
//! [12]
|
||||||
|
|
||||||
//! [13]
|
//! [13]
|
||||||
|
@ -149,7 +149,7 @@ QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const;
|
|||||||
|
|
||||||
|
|
||||||
//! [11]
|
//! [11]
|
||||||
boost::bind(&QImage::scaledToWidth, 100, Qt::SmoothTransformation)
|
std::bind(&QImage::scaledToWidth, 100, Qt::SmoothTransformation)
|
||||||
//! [11]
|
//! [11]
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ QImage scaledToWith(const QImage &image)
|
|||||||
|
|
||||||
//! [13]
|
//! [13]
|
||||||
QList<QImage> images = ...;
|
QList<QImage> images = ...;
|
||||||
QFuture<QImage> thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation));
|
QFuture<QImage> thumbnails = QtConcurrent::mapped(images, std::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation));
|
||||||
//! [13]
|
//! [13]
|
||||||
|
|
||||||
//! [14]
|
//! [14]
|
||||||
|
@ -93,6 +93,6 @@ future.waitForFinished();
|
|||||||
|
|
||||||
//! [6]
|
//! [6]
|
||||||
void someFunction(int arg1, double arg2);
|
void someFunction(int arg1, double arg2);
|
||||||
QFuture<void> future = QtConcurrent::run(boost::bind(someFunction, 1, 2.0));
|
QFuture<void> future = QtConcurrent::run(std::bind(someFunction, 1, 2.0));
|
||||||
...
|
...
|
||||||
//! [6]
|
//! [6]
|
||||||
|
@ -155,15 +155,11 @@
|
|||||||
|
|
||||||
\section2 Using Bound Function Arguments
|
\section2 Using Bound Function Arguments
|
||||||
|
|
||||||
Note that Qt does not provide support for bound functions. This is
|
|
||||||
provided by 3rd party libraries like
|
|
||||||
\l{http://www.boost.org/libs/bind/bind.html}{Boost} or
|
|
||||||
\l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf}
|
|
||||||
{C++ TR1 Library Extensions}.
|
|
||||||
|
|
||||||
If you want to use a filter function takes more than one argument, you can
|
If you want to use a filter function takes more than one argument, you can
|
||||||
use boost::bind() or std::tr1::bind() to transform it onto a function that
|
use std::bind() to transform it onto a function that takes one argument. If
|
||||||
takes one argument.
|
C++11 support is not available, \l{http://www.boost.org/libs/bind/bind.html}
|
||||||
|
{boost::bind()} or \l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf}
|
||||||
|
{std::tr1::bind()} are suitable replacements.
|
||||||
|
|
||||||
As an example, we use QString::contains():
|
As an example, we use QString::contains():
|
||||||
|
|
||||||
@ -177,7 +173,7 @@
|
|||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentfilter.cpp 10
|
\snippet code/src_concurrent_qtconcurrentfilter.cpp 10
|
||||||
|
|
||||||
The return value from boost::bind() is a function object (functor) with
|
The return value from std::bind() is a function object (functor) with
|
||||||
the following signature:
|
the following signature:
|
||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentfilter.cpp 11
|
\snippet code/src_concurrent_qtconcurrentfilter.cpp 11
|
||||||
|
@ -204,15 +204,11 @@
|
|||||||
|
|
||||||
\section2 Using Bound Function Arguments
|
\section2 Using Bound Function Arguments
|
||||||
|
|
||||||
Note that Qt does not provide support for bound functions. This is
|
|
||||||
provided by 3rd party libraries like
|
|
||||||
\l{http://www.boost.org/libs/bind/bind.html}{Boost} or
|
|
||||||
\l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf}{C++
|
|
||||||
TR1 Library Extensions}.
|
|
||||||
|
|
||||||
If you want to use a map function that takes more than one argument you can
|
If you want to use a map function that takes more than one argument you can
|
||||||
use boost::bind() or std::tr1::bind() to transform it onto a function that
|
use std::bind() to transform it onto a function that takes one argument. If
|
||||||
takes one argument.
|
C++11 support is not available, \l{http://www.boost.org/libs/bind/bind.html}
|
||||||
|
{boost::bind()} or \l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf}
|
||||||
|
{std::tr1::bind()} are suitable replacements.
|
||||||
|
|
||||||
As an example, we'll use QImage::scaledToWidth():
|
As an example, we'll use QImage::scaledToWidth():
|
||||||
|
|
||||||
@ -226,7 +222,7 @@
|
|||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentmap.cpp 11
|
\snippet code/src_concurrent_qtconcurrentmap.cpp 11
|
||||||
|
|
||||||
The return value from boost::bind() is a function object (functor) with
|
The return value from std::bind() is a function object (functor) with
|
||||||
the following signature:
|
the following signature:
|
||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentmap.cpp 12
|
\snippet code/src_concurrent_qtconcurrentmap.cpp 12
|
||||||
|
@ -110,15 +110,12 @@
|
|||||||
|
|
||||||
\section2 Using Bound Function Arguments
|
\section2 Using Bound Function Arguments
|
||||||
|
|
||||||
Note that Qt does not provide support for bound functions. This is
|
You can use std::bind() to \e bind a number of arguments to a function when
|
||||||
provided by 3rd party libraries like
|
called. If C++11 support is not available, \l{http://www.boost.org/libs/bind/bind.html}
|
||||||
\l{http://www.boost.org/libs/bind/bind.html}{Boost} or
|
{boost::bind()} or \l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf}
|
||||||
\l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf}
|
{std::tr1::bind()} are suitable replacements.
|
||||||
{C++ TR1 Library Extensions}.
|
|
||||||
|
|
||||||
You can use boost::bind() or std::tr1::bind() to \e bind a number of
|
There are number of reasons for binding:
|
||||||
arguments to a function when called. There are number of reasons for doing
|
|
||||||
this:
|
|
||||||
|
|
||||||
\list
|
\list
|
||||||
\li To call a function that takes more than 5 arguments.
|
\li To call a function that takes more than 5 arguments.
|
||||||
|
Loading…
Reference in New Issue
Block a user