Dune::ForEachValue< Tuple > Class Template Reference
[Tuple Utilities]

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

#include <dune/common/tupleutility.hh>

List of all members.

Public Member Functions

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

Detailed Description

template<class Tuple>
class Dune::ForEachValue< Tuple >

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

Compile-time constructs that allows one to process all elements in a std::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 std::tuple. Each std::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 std::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 std::tuple are stored in the member variable result_. The Counter can be used as follows, assuming a std::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 Tuple >
Dune::ForEachValue< Tuple >::ForEachValue ( Tuple &  t  )  [inline]

Constructor.

Parameters:
t The std::tuple which we want to process.

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 25 Mar 2018 for dune-common by  doxygen 1.6.1