fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <iterator>
  5.  
  6. template< typename T, typename ...U >
  7. std::vector<T> my_unique( std::vector<T> & cont, std::vector<U> &... other_containers )
  8. {
  9. std::vector<T> destination{};
  10. auto uniq = []( std::vector<T> & arg )->typename std::vector<T>::iterator { std::sort(arg.begin(), arg.end() );
  11. return std::unique( std::begin( arg ), std::end( arg ) ); };
  12. auto coppy = [&]( std::vector<T> & args )-> void { std::copy( std::begin( args ), uniq( args ), std::back_inserter( destination ) ); };
  13.  
  14. int hack[]{( void( coppy( cont ) ), 0 ), ( void( coppy( other_containers )), 0)... };
  15. return destination;
  16. }
  17.  
  18. int main()
  19. {
  20. std::vector<int> a { 11, 12, 11, 15, 16, 23, 15, 23, 15 }, b { 3, 5, 6, 2, 3, 4, 3, 8, 9, 8 }, c { 1, 1, 3, 6, 60, 2, 2, 1 };
  21. std::vector<int> d = my_unique( a, b, c );
  22. for( const auto &x: d ) std::cout << x << ", ";
  23. return 0;
  24. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
11, 12, 15, 16, 23, 2, 3, 4, 5, 6, 8, 9, 1, 2, 3, 6, 60,