1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <stdexcept>
//ligne et colonne sont fourni pour information, cela peut être utile pour la définition (par exemple, pour ne faire un traitement que sur une variable
template <typename Source, typename Index = int>
using pFonction = void (*)(Source& valeur, Index const& ligne, Index const& colonne);
template <Typename Type, typename Index = int>
void mapFunctionOnRow(pFonction<Type, Index> foncteur, Type[][] matrice, Index const& largeur, Index const& hauteur, Index indiceFixe)
{
if (indiceFixe<0 || indiceFixe>hauteur) throw std::out_of_range("can't map on an undefined row");
for(Index i = 0; i<largeur; ++i) {
(*foncteur)(matrice[indiceFixe][i], indiceFixe, i);
}
}
template <Typename Type, typename Index = int>
void mapFunctionOnColumn(pFonction<Type, Type, Index> foncteur, Type[][] matrice, Index const& largeur, Index const& hauteur, Index indiceFixe)
{
if (indiceFixe<0 || indiceFixe>largeur) throw std::out_of_range("can't map on an undefined column");
for(Index i = 0; i<hauteur; ++i) {
(*foncteur)(matrice[i][indiceFixe], i, indiceFixe);
}
} |
Partager