Skip to content
Snippets Groups Projects
Commit b61cdfee authored by Carsten Gräser's avatar Carsten Gräser Committed by Steffen Müthing
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.

(cherry picked from commit a8f68be4)
Signed-off-by: default avatarSteffen Müthing <muething@dune-project.org>
parent cbb11f31
No related branches found
No related tags found
No related merge requests found
......@@ -261,8 +261,85 @@ namespace Dune {
*/
int count() {return mpl::size<type>::value;}
/**
* assignment 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<int,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<int,0>()] = ...
* \endcode
*/
template< int index >
typename std::tuple_element<index,tupleType>::type&
operator[] ( const std::integral_constant< int, index > indexVariable )
{
DUNE_UNUSED_PARAMETER(indexVariable);
return std::get<index>(*this);
}
/** \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.
*/
template< int index >
const typename std::tuple_element<index,tupleType>::type&
operator[] ( const std::integral_constant< int, index > indexVariable ) const
{
DUNE_UNUSED_PARAMETER(indexVariable);
return std::get<index>(*this);
}
/** \brief Assignment operator
*/
template<typename T>
void operator= (const T& newval) {MultiTypeBlockVector_Ident<mpl::size<type>::value,type,T>::equalize(*this, newval); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment