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
|
#include <iostream>
#include <vector>
#include <set>
#include <functional>
std::size_t count_unique_vectors( const std::vector< std::vector<int> >& vectors )
{
using vec_wrapper = std::reference_wrapper< const std::vector<int> > ;
static const auto cmp_less = [] ( const vec_wrapper& a, const vec_wrapper& b )
{ return a.get() < b.get() ; } ;
std::set< vec_wrapper, decltype(cmp_less) > set(cmp_less) ;
for( const auto& vec : vectors ) set.insert( std::cref(vec) ) ;
return set.size() ;
}
int main()
{
const std::vector< std::vector<int> > my_vectors =
{
{ 1, 2, 3, 4 }, { 1, 3, 2, 4 }, { 1, 2, 3, 4 }, { 4, 2, 3, 1 }, { 1, 2, 3, 4 },
{ 1, 2, 3 }, { 1, 2, 3 }, { 1, 2, 4 }, { 2, 3, 1 }, { 1, 2, 3 }, { 1, 1, 3 },
{ 1, 2 }, { 2, 1 }, { 1, 2 }, {}, { 1, 2 }, {1}, {2}, {}, {2}, {1}, {}, {1}, {1,2}, {2}
};
std::cout << my_vectors.size() << " vectors in all, of which "
<< count_unique_vectors(my_vectors) << " are unique\n" ;
}
|