Qt 4.8
Public Types | Public Functions | Properties | List of all members
QFuture< T >::const_iterator Class Reference

The QFuture::const_iterator class provides an STL-style const iterator for QFuture. More...

#include <qfuture.h>

Public Types

typedef qptrdiff difference_type
 Typedef for ptrdiff_t. More...
 
typedef std::bidirectional_iterator_tag iterator_category
 Typedef for std::bidirectional_iterator_tag. More...
 
typedef const T * pointer
 Typedef for const T *. More...
 
typedef const T & reference
 Typedef for const T &. More...
 
typedef T value_type
 Typedef for T. More...
 

Public Functions

 const_iterator ()
 Constructs an uninitialized iterator. More...
 
 const_iterator (QFuture const *const _future, int _index)
 
 const_iterator (const const_iterator &o)
 Constructs a copy of other. More...
 
bool operator!= (const const_iterator &other) const
 Returns true if other points to a different result than this iterator; otherwise returns false. More...
 
const T & operator* () const
 Returns the current result. More...
 
const_iterator operator+ (int j) const
 Returns an iterator to the results at j positions forward from this iterator. More...
 
const_iteratoroperator++ ()
 The prefix ++ operator (++it) advances the iterator to the next result in the future and returns an iterator to the new current result. More...
 
const_iterator operator++ (int)
 The postfix ++ operator (it++) advances the iterator to the next result in the future and returns an iterator to the previously current result. More...
 
const_iteratoroperator+= (int j)
 Advances the iterator by j results. More...
 
const_iterator operator- (int j) const
 Returns an iterator to the result at j positions backward from this iterator. More...
 
const_iteratoroperator-- ()
 The prefix – operator (–it) makes the preceding result current and returns an iterator to the new current result. More...
 
const_iterator operator-- (int)
 The postfix – operator (it–) makes the preceding result current and returns an iterator to the previously current result. More...
 
const_iteratoroperator-= (int j)
 Makes the iterator go back by j results. More...
 
const T * operator-> () const
 Returns a pointer to the current result. More...
 
const_iteratoroperator= (const const_iterator &o)
 Assigns other to this iterator. More...
 
bool operator== (const const_iterator &o) const
 Returns true if other points to the same result as this iterator; otherwise returns false. More...
 

Properties

QFuture const * future
 
int index
 

Detailed Description

template<typename T>
class QFuture< T >::const_iterator

The QFuture::const_iterator class provides an STL-style const iterator for QFuture.

Note
This class or function is reentrant.
Since
4.4

QFuture provides both STL-style iterators and Java-style iterators. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity.

The default QFuture::const_iterator constructor creates an uninitialized iterator. You must initialize it using a QFuture function like QFuture::constBegin() or QFuture::constEnd() before you start iterating. Here's a typical loop that prints all the results available in a future:

for (i = future.constBegin(); i != future.constEnd(); ++i)
cout << *i << endl;
See also
QFutureIterator, QFuture

Definition at line 110 of file qfuture.h.

Typedefs

◆ difference_type

template<typename T>
QFuture< T >::const_iterator::difference_type

Typedef for ptrdiff_t.

Provided for STL compatibility.

Definition at line 114 of file qfuture.h.

◆ iterator_category

template<typename T>
QFuture< T >::const_iterator::iterator_category

Typedef for std::bidirectional_iterator_tag.

Provided for STL compatibility.

Definition at line 113 of file qfuture.h.

◆ pointer

template<typename T>
QFuture< T >::const_iterator::pointer

Typedef for const T *.

Provided for STL compatibility.

Definition at line 116 of file qfuture.h.

◆ reference

template<typename T>
QFuture< T >::const_iterator::reference

Typedef for const T &.

Provided for STL compatibility.

Definition at line 117 of file qfuture.h.

◆ value_type

template<typename T>
QFuture< T >::const_iterator::value_type

Typedef for T.

Provided for STL compatibility.

Definition at line 115 of file qfuture.h.

Constructors and Destructors

◆ const_iterator() [1/3]

template<typename T>
QFuture< T >::const_iterator::const_iterator ( )
inline

Constructs an uninitialized iterator.

Functions like operator*() and operator++() should not be called on an uninitialized iterartor. Use operator=() to assign a value to it before using it.

See also
QFuture::constBegin() QFuture::constEnd()

Definition at line 119 of file qfuture.h.

Referenced by QFuture< T >::begin(), QFuture< T >::constBegin(), QFuture< T >::constEnd(), QFuture< T >::end(), QFuture< T >::const_iterator::operator+(), and QFuture< T >::const_iterator::operator-().

119 {}

◆ const_iterator() [2/3]

template<typename T>
QFuture< T >::const_iterator::const_iterator ( QFuture const *const  future,
int  index 
)
inline
Warning
This function is not part of the public interface.

Definition at line 120 of file qfuture.h.

120 : future(_future), index(_index) {}
QFuture const * future
Definition: qfuture.h:146

◆ const_iterator() [3/3]

template<typename T>
QFuture< T >::const_iterator::const_iterator ( const const_iterator o)
inline

Constructs a copy of other.

Definition at line 121 of file qfuture.h.

121 : future(o.future), index(o.index) {}
QFuture const * future
Definition: qfuture.h:146

Functions

◆ operator!=()

template<typename T>
bool QFuture< T >::const_iterator::operator!= ( const const_iterator other) const
inline

Returns true if other points to a different result than this iterator; otherwise returns false.

See also
operator==()

Definition at line 127 of file qfuture.h.

Referenced by QFutureInterface< T >::future(), and QFuture< T >::const_iterator::operator==().

128  {
129  if (index == -1 && other.index == -1) // comparing end != end?
130  return false;
131  if (other.index == -1)
132  return (future->isRunning() || (index < future->resultCount()));
133  return (index != other.index);
134  }
int resultCount() const
Returns the number of continuous results available in this future.
Definition: qfuture.h:96
QFuture const * future
Definition: qfuture.h:146
bool isRunning() const
Returns true if the asynchronous computation represented by this future is currently running; otherwi...
Definition: qfuture.h:94

◆ operator*()

template<typename T>
const T & QFuture< T >::const_iterator::operator* ( ) const
inline

Returns the current result.

Definition at line 124 of file qfuture.h.

124 { return future->d.resultReference(index); }
QFuture const * future
Definition: qfuture.h:146
QFutureInterface< T > d
Definition: qfuture.h:161

◆ operator+()

template<typename T>
QFuture::const_iterator QFuture< T >::const_iterator::operator+ ( int  j) const
inline

Returns an iterator to the results at j positions forward from this iterator.

(If j is negative, the iterator goes backward.)

See also
operator-(), operator+=()

Definition at line 141 of file qfuture.h.

141 { return const_iterator(future, index + j); }
const_iterator()
Constructs an uninitialized iterator.
Definition: qfuture.h:119
QFuture const * future
Definition: qfuture.h:146

◆ operator++() [1/2]

template<typename T>
QFuture::const_iterator & QFuture< T >::const_iterator::operator++ ( )
inline

The prefix ++ operator (++it) advances the iterator to the next result in the future and returns an iterator to the new current result.

Calling this function on QFuture::constEnd() leads to undefined results.

See also
operator--()

Definition at line 137 of file qfuture.h.

137 { ++index; return *this; }

◆ operator++() [2/2]

template<typename T>
QFuture::const_iterator QFuture< T >::const_iterator::operator++ ( int  )
inline

The postfix ++ operator (it++) advances the iterator to the next result in the future and returns an iterator to the previously current result.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 138 of file qfuture.h.

138 { const_iterator r = *this; ++index; return r; }
const_iterator()
Constructs an uninitialized iterator.
Definition: qfuture.h:119

◆ operator+=()

template<typename T>
QFuture::const_iterator & QFuture< T >::const_iterator::operator+= ( int  j)
inline

Advances the iterator by j results.

(If j is negative, the iterator goes backward.)

See also
operator-=(), operator+()

Definition at line 143 of file qfuture.h.

143 { index += j; return *this; }

◆ operator-()

template<typename T>
QFuture::const_iterator QFuture< T >::const_iterator::operator- ( int  j) const
inline

Returns an iterator to the result at j positions backward from this iterator.

(If j is negative, the iterator goes forward.)

See also
operator+(), operator-=()

Definition at line 142 of file qfuture.h.

142 { return const_iterator(future, index - j); }
const_iterator()
Constructs an uninitialized iterator.
Definition: qfuture.h:119
QFuture const * future
Definition: qfuture.h:146

◆ operator--() [1/2]

template<typename T>
QFuture::const_iterator & QFuture< T >::const_iterator::operator-- ( )
inline

The prefix – operator (–it) makes the preceding result current and returns an iterator to the new current result.

Calling this function on QFuture::constBegin() leads to undefined results.

See also
operator++()

Definition at line 139 of file qfuture.h.

139 { --index; return *this; }

◆ operator--() [2/2]

template<typename T>
QFuture::const_iterator QFuture< T >::const_iterator::operator-- ( int  )
inline

The postfix – operator (it–) makes the preceding result current and returns an iterator to the previously current result.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 140 of file qfuture.h.

140 { const_iterator r = *this; --index; return r; }
const_iterator()
Constructs an uninitialized iterator.
Definition: qfuture.h:119

◆ operator-=()

template<typename T>
QFuture::const_iterator & QFuture< T >::const_iterator::operator-= ( int  j)
inline

Makes the iterator go back by j results.

(If j is negative, the iterator goes forward.)

See also
operator+=(), operator-()

Definition at line 144 of file qfuture.h.

144 { index -= j; return *this; }

◆ operator->()

template<typename T>
const T * QFuture< T >::const_iterator::operator-> ( ) const
inline

Returns a pointer to the current result.

Definition at line 125 of file qfuture.h.

125 { return future->d.resultPointer(index); }
QFuture const * future
Definition: qfuture.h:146
QFutureInterface< T > d
Definition: qfuture.h:161

◆ operator=()

template<typename T>
QFuture::const_iterator & QFuture< T >::const_iterator::operator= ( const const_iterator o)
inline

Assigns other to this iterator.

Definition at line 122 of file qfuture.h.

Referenced by QFutureInterface< T >::future().

123  { future = o.future; index = o.index; return *this; }
QFuture const * future
Definition: qfuture.h:146

◆ operator==()

template<typename T>
bool QFuture< T >::const_iterator::operator== ( const const_iterator other) const
inline

Returns true if other points to the same result as this iterator; otherwise returns false.

See also
operator!=()

Definition at line 136 of file qfuture.h.

Referenced by QFutureInterface< T >::future().

136 { return !operator!=(o); }
bool operator!=(const const_iterator &other) const
Returns true if other points to a different result than this iterator; otherwise returns false...
Definition: qfuture.h:127

Properties

◆ future

template<typename T>
QFuture const* QFuture< T >::const_iterator::future
private

◆ index

template<typename T>
int QFuture< T >::const_iterator::index
private

The documentation for this class was generated from the following files: