- Qt 6.12
- Qt TaskTree
- C++ Classes
- Do
- Qt 6.12.0 Reference Documentation

# QtTaskTree::Do Class

class QtTaskTree::Do

A body element used with For and When constructs. More...

Header: | `#include <qtasktree.h>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS TaskTree)` `target_link_libraries(mytarget PRIVATE Qt6::TaskTree)`
qmake: | `QT += tasktree`
Since: | Qt 6.11
Status: | Technology preview

This class is in technology preview and is subject to change.

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

| Do(const QtTaskTree::GroupItems &children)
| Do(std::initializer_list<QtTaskTree::GroupItem> children)
| Do(QtTaskTree::Do &&other)

## Related Non-Members

QtTaskTree::Group | operator>>(const QtTaskTree::When &whenItem, const QtTaskTree::Do &doItem)

## Detailed Description

A body element, holding a list of tasks to be executed on each For iteration or after When's barrier was advanced.

     For (RepeatIterator(5)) >> Do {
         task1,
         task2
     };

In case of For loop, the Do's body will be executed multiple times. If onGroupSetup() or onGroupDone() handlers are a part of passed children to Do's constructor, they will be executed just once - before the whole loop starts, and after the whole loop is finished:

     const RepeatIterator iterator(3);

     const auto onSetup = [] { qDebug() << "Setup"; };

     const auto onSync = [iterator] { qDebug() << "Current iteration:" << iterator->iteration(); };

     const auto onDone = [] { qDebug() << "Done"; };

     const Group recipe = For (iterator) >> Do {
         onGroupSetup(onSetup),
         QSyncTask(onSync),
         onDone(onDone)
     };

The above recipe, when executed, will output:

     Setup
     Current iteration: 0
     Current iteration: 1
     Current iteration: 2
     Done

If the intention is to invoke group handlers on each iteration, enclose the Do body with an extra Group, like:

     const Group recipe = For (iterator) >> Do {
         Group {
             onGroupSetup(onSetup),
             QSyncTask(onSync),
             onDone(onDone)
         }
     };

The latter recipe, when executed, will output:

     Setup
     Current iteration: 0
     Done
     Setup
     Current iteration: 1
     Done
     Setup
     Current iteration: 2
     Done

The similar happens when the Storage passed as a direct child of the body. The storage structure is instantiated just once, before the whole loop starts, and is destroyed just after the whole loop is finished. If the intention is to have separate instance of the Storage for each iteration, enclose the Do body with an extra Group.

Be careful with placing parallel element in the Do's body of the For loop, as all iterations will start in parallel. This might not be desired, especially in case of ForeverIterator.

See also For and When.

## Member Function Documentation

### `[explicit]` Do::Do(const QtTaskTree::GroupItems &children)

Constructs a Do body with children to be executed on each For's iteration or after When's barrier was advanced.

### `[explicit]` Do::Do(std::initializer_list<QtTaskTree::GroupItem> children)

Constructs a Do body with children passed as initializer list.

This is an overloaded function.

### `[constexpr noexcept default]` Do::Do(QtTaskTree::Do &&other)

Move-constructs an instance of Do.

## Related Non-Members

### QtTaskTree::Group operator>>(const QtTaskTree::When &whenItem, const QtTaskTree::Do &doItem)

Combines whenItem with doItem body and returns a Group ready to be used in task tree recipes.