fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <numeric>
  5. #include <initializer_list>
  6.  
  7. template <typename T>
  8. bool different(std::vector<T> list)
  9. {
  10. if (list.size() > 1)
  11. {
  12. std::sort(list.begin(), list.end());
  13.  
  14. for (auto i = list.begin(); i != list.end() - 1; ++i)
  15. if (*i == *(i + 1))
  16. return false;
  17. }
  18.  
  19. return true;
  20. }
  21.  
  22. template <typename T>
  23. bool different(std::initializer_list<T> list)
  24. {
  25. return different(std::vector<T>(list.begin(), list.end()));
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31. int a, b, c;
  32. a = 3; b = 4; c = 4;
  33.  
  34. std::cout << std::boolalpha << different({ a, b, c }) << '\n' ;
  35.  
  36. a = 5, b = 3, c = 4;
  37.  
  38. std::cout << different({ a, b, c }) << '\n';
  39. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
false
true