Skip to content
Snippets Groups Projects
Commit a8f68be4 authored by Carsten Gräser's avatar Carsten Gräser
Browse files

Provide operator[] for integral_constant<std::size_t, k>

This a littel more natural then int. Furthermore it allows
to use the index constants from dune-typetree.
parent 491ca46b
No related branches found
No related tags found
No related merge requests found
......@@ -269,7 +269,7 @@ namespace Dune {
return sizeof...(Args);
}
/** \brief Random-access operator
/** \brief Random-access operator
*
* This method mimicks the behavior of normal vector access with square brackets like, e.g., v[5] = 1.
* The problem is that the return type is different for each value of the argument in the brackets.
......@@ -295,7 +295,46 @@ namespace Dune {
return std::get<index>(*this);
}
/** \brief Const random-access operator
/** \brief Random-access operator
*
* This method mimicks the behavior of normal vector access with square brackets like, e.g., v[5] = 1.
* The problem is that the return type is different for each value of the argument in the brackets.
* Therefore we implement a trick using std::integral_constant. To access the first entry of
* a MultiTypeBlockVector named v write
* \code
* MultiTypeBlockVector<A,B,C,D> v;
* std::integral_constant<std::size_t,0> _0;
* v[_0] = ...
* \endcode
* The name '_0' used here as a static replacement of the integer number zero is arbitrary.
* Any other variable name can be used. If you don't like the separate variable, you can writee
* \code
* MultiTypeBlockVector<A,B,C,D> v;
* v[std::integral_constant<std::size_t,0>()] = ...
* \endcode
*/
template< std::size_t index >
typename std::tuple_element<index,tupleType>::type&
operator[] ( const std::integral_constant< std::size_t, index > indexVariable )
{
DUNE_UNUSED_PARAMETER(indexVariable);
return std::get<index>(*this);
}
/** \brief Const random-access operator
*
* This is the const version of the random-access operator. See the non-const version for a full
* explanation of how to use it.
*/
template< std::size_t index >
const typename std::tuple_element<index,tupleType>::type&
operator[] ( const std::integral_constant< std::size_t, index > indexVariable ) const
{
DUNE_UNUSED_PARAMETER(indexVariable);
return std::get<index>(*this);
}
/** \brief Const random-access operator
*
* This is the const version of the random-access operator. See the non-const version for a full
* explanation of how to use it.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment