Dune::ForEachValue< TupleType > Class Template Reference

Helper template which implements iteration over all storage elements in a tuple. More...

#include <dune/common/tupleutility.hh>

List of all members.

Public Member Functions

 ForEachValue (TupleType &tuple)
 Constructor.
template<class Functor >
void apply (Functor &f) const
 Applies a function object to each storage element of the tuple.

Detailed Description

template<class TupleType>
class Dune::ForEachValue< TupleType >

Helper template which implements iteration over all storage elements in a tuple.

Compile-time constructs that allows to process all elements in a tuple. The exact operation performed on an element is defined by a function object, which needs to implement a visit method which is applicable to all storage elements of a tuple. Each tuple element is visited once, and the iteration is done in ascending order.

The following example implements a function object which counts the elements in a tuple

   template <class T>
   struct Counter {
   Counter() : result_(0) {}
   
   template <class T>
   void visit(T& elem) { ++result_; }

   int result_;
   };

The number of elements in the tuple are stored in the member variable result_. The Counter can be used as follows, assuming a tuple t of type MyTuple is given:

   Counter c;
   ForEachValue<MyTuple> forEach(t);

   forEach.apply(c);
   std::cout << "Number of elements is: " << c.result_ << std::endl;

Constructor & Destructor Documentation

template<class TupleType >
Dune::ForEachValue< TupleType >::ForEachValue ( TupleType &  tuple  )  [inline]

Constructor.

Parameters:
tuple The tuple which we want to process.

Member Function Documentation

template<class TupleType >
template<class Functor >
void Dune::ForEachValue< TupleType >::apply ( Functor &  f  )  const [inline]

Applies a function object to each storage element of the tuple.

Parameters:
f Function object.

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

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].