fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. std::set<int> ints = {1, -1, 3};
  10.  
  11. auto dupe = std::find_if(ints.begin(),ints.end(),[&](const int& first){
  12. return std::find_if(ints.begin(),ints.end(),[&](const int& second) {
  13. // so a the same value isn't checked against itself..
  14. if (&first == &second) return false;
  15. return std::abs(first) == std::abs(second);
  16. }) != ints.end();
  17. } );
  18.  
  19. if (dupe != ints.end()) std::cout << "Found dupe: " << *dupe << std::endl;
  20. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
Found dupe: -1