dune-common  2.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Static Public Member Functions | List of all members
Dune::ForLoop< Operation, first, last > Class Template Reference

A static loop using TMP. More...

#include <dune/common/forloop.hh>

Static Public Member Functions

template<typename... Args>
static void apply (Args &&...args)
 

Detailed Description

template<template< int > class Operation, int first, int last>
class Dune::ForLoop< Operation, first, last >

A static loop using TMP.

The ForLoop takes a

template<int i> class Operation

template argument with a static apply method which is called for i=first...last (first<=last are int template arguments). A specialization for class template class Operation for i=first or i=last is not required. The class Operation must provide a static void function apply(...). Arguments are perfectly forwarded through the ForLoop to this function.

It is possible to pass a subclass to the ForLoop (since no specialization is needed).

Example of usage:

* template<class Tuple>
* struct PrintTupleTypes
* {
* template <int i>
* struct Operation
* {
* template<class Stream>
* static void apply(Stream &stream, const std::string &prefix)
* {
* stream << prefix << i << ": "
* << className<typename tuple_element<i, Tuple>::type>()
* << std::endl;
* }
* };
* template<class Stream>
* static void print(Stream &stream, const std::string &prefix)
* {
* // cannot attach on-the-fly in the argument to ForLoop<..>::apply() since
* // that would yield an rvalue
* std::string extended_prefix = prefix+" ";
*
* stream << prefix << "tuple<" << std::endl;
* ForLoop<Operation, 0, tuple_size<Tuple>::value-1>::
* apply(stream, extended_prefix);
* stream << prefix << ">" << std::endl;
* }
* };
*

Member Function Documentation

template<template< int > class Operation, int first, int last>
template<typename... Args>
static void Dune::ForLoop< Operation, first, last >::apply ( Args &&...  args)
inlinestatic

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