Loop - SeqAn API Documentation

# Class Loop
Helper for loops.

Defined in | <seqan/basic.h>
Signature | `template <typename TWorker, unsigned COUNT> struct Loop;`

## Template Parameters

`TWorker` | A struct with a static inline void function called `body`. `body` should have two parameters, one for passing in values and state from the outside and the second is an int. The function will be called `COUNT` times with the same reference for the first one and the values `COUNT`, `COUNT - 1`, ..., `1` for the second parameter.
`COUNT` | An `int` constant.

## Member Function Overview

- `Loop::run(arg, i);`
  Run the loop body.

## Detailed Description

### Example

We define the following worker to print an integer. The first argument is of `Nothing` as a dummy. Note that the parameter is not const.

    struct PrintWorker
    {
        static inline void body(Nothing & arg, int I)
        {
            (void)arg;  // ignored
            printf("%d\n", I);
        }

    };

Snippet from: demos/dox/basic/metaprogramming_control.cpp

The following shows an example calling `PrintWorker::body()` through Loop. We have to create a local variable since the first parameter is not const. The reason for this is that the parameter can also be used for a mutable object that holds some state.

            Nothing nothing;
            LoopReverse<PrintWorker, 10>::run(nothing);
            // This will print the numbers 10, 9, ..., 2, 1.

Snippet from: demos/dox/basic/metaprogramming_control.cpp

## See Also

- LoopReverse

## Member Functions Detail

### `Loop::run(arg, i);`

Run the loop body.

#### Parameters

`arg` | The argument to pass to the worker's `body()` function.
`i` | The `int` passed to the `body()` function.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

#### Dox Sources

    /*!
     * @class Loop
     *
     * @headerfile <seqan/basic.h>
     *
     * @brief Helper for loops.
     *
     * @signature template <typename TWorker, unsigned COUNT> struct Loop;
     *
     * @tparam TWorker A struct with a static inline void function called
     *                 <tt>body</tt>. <tt>body</tt> should have two parameters, one
     *                 for passing in values and state from the outside and the
     *                 second is an int. The function will be called <tt>COUNT</tt>
     *                 times with the same reference for the first one and the
     *                 values <tt>COUNT</tt>, <tt>COUNT - 1</tt>, ..., <tt>1</tt>
     *                 for the second parameter.
     * @tparam COUNT An <tt>int</tt> constant.
     *
     * @section Example
     *
     * We define the following worker to print an integer. The first argument is of
     * <tt>Nothing</tt> as a dummy. Note that the parameter is not const.
     *
     * @snippet demos/dox/basic/metaprogramming_control.cpp print worker
     *
     * The following shows an example calling <tt>PrintWorker::body()</tt> through
     * Loop. We have to create a local variable since the first parameter is not
     * const. The reason for this is that the parameter can also be used for a
     * mutable object that holds some state.
     *
     * @snippet demos/dox/basic/metaprogramming_control.cpp print worker call loop reverse
     *
     * @see LoopReverse
     *
     * @fn Loop::run
     *
     * @brief Run the loop body.
     *
     * @signature Loop::run(arg, i);
     *
     * @param[in,out] arg The argument to pass to the worker's <tt>body()</tt>
     *                    function.
     * @param[in] i The <tt>int</tt> passed to the <tt>body()</tt> function.
     */