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

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);
    }

};

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.

See Also

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

Thread safety unknown!