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 37
|
#include <fstream>
#include <algorithm>
#include <iterator>
#include <set>
// T is less_than_comparable, default_constructible, copy_assignable and streamable
template < typename T, std::size_t N > struct n_tuple
{
inline bool operator< ( const n_tuple& that ) const
{ return std::lexicographical_compare( array, array+N, that.array, that.array+N ) ; }
inline friend std::istream& operator >> ( std::istream& stm, n_tuple<T,N>& tup )
{
// quick and dirty
for( std::size_t i = 0 ; i < N ; ++i ) stm >> tup.array[i] ;
return stm ;
}
inline friend std::ostream& operator << ( std::ostream& stm, const n_tuple<T,N>& tup )
{
std::copy( tup.array, tup.array+N, std::ostream_iterator<T>( stm, " " ) ) ;
return stm ;
}
T array[N] ;
};
template < typename T, std::size_t N >
void make_unique( const char* srce_file, const char* dest_file )
{
std::ifstream input(srce_file) ;
std::ofstream output(dest_file) ;
std::set< n_tuple<T,N> > tuples ;
n_tuple<T,N> tup ;
while( input >> tup ) if( tuples.insert(tup).second ) output << tup << '\n' ;
}
|