1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <iostream>
#include <set>
#include <boost/multi_array.hpp>
typedef boost::multi_array<int, 2> Array2;
template <typename T>
struct IndexedArrayValue {
IndexedArrayValue( const T & val, int i = -1, int j = -1) : value(val), index1(i), index2(j) {}
T value;
size_t index1, index2;
};
struct CompIAV {
bool operator () ( const IndexedArrayValue<int> & left, const IndexedArrayValue<int> & right ) {
if ( left.value == right.value ) {
if ( left.index1 < right.index1 ) return true;
else return ( left.index2 < right.index2);
}
return ( left.value < right.value );
}
};
int main()
{
Array2 array( boost::extents[3][3] );
//... remplissage du tableau
std::set<IndexedArrayValue<int>, CompIAV> indexedValues;
for ( size_t i = 0; i < array.shape()[0]; i++)
for ( size_t j = 0; j < array.shape()[1]; j++ )
indexedValues.insert( IndexedArrayValue<int>(array[i][j], i, j ) );
std::cin.get();
return 0;
} |
Partager