MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros
Forall.hpp File Reference

This file contains the defines the forall loops. More...

#include <Config.hpp>
#include <iterator>
#include <utility>

Go to the source code of this file.

Macros

#define forall_range(typed_var, range)
 
#define forall(typed_var, cont)
 
#define forall_reverse(typed_var, cont)
 
#define forall_named(typed_var, cont, name)
 

Detailed Description

This file contains the defines the forall loops.

Forall allows to iterate on STL container or range.

Note
A STL range is a pair of iterator where the first element of the pair is the beginning the second element of the pair is the end.

Use examples:

std::vector<int> va;
// ... Filling in va ...
forall(int a, va)
{
cout << a << endl;
}

This example shows how to iterate on a container returned by value by a function:

std::vector<int> create_vector();
// Now put the output of the function in a local variable
std::vector<int> va = create_vector();
forall(int a, va)
{
cout << a << endl;
}
Note
You should not iterate directly on it! The loop do not keep the container alive.

Use example with range:

typedef std::vector<int>::iterator iterator;
std::pair<iterator,iterator> extract(std::vector<int> v, int first, int last);
std::vector<int> va;
// ... Filling in va ...
forall(int& i, extract(va, 2, 10))
{
i += 5;
cout << i << endl;
}

In this example, the values in the vector are changed too.