fork download
  1. #include <iostream>
  2. #include <numeric>
  3. #include <set>
  4.  
  5. int main()
  6. {
  7. int t[4] = { 3, 3, 1, 5 };
  8. std::set<int> mySet;
  9. int mySum = std::accumulate(std::begin(t), std::end(t), 0,
  10. [&](int n, int n2){return n += mySet.insert(n2).second?n2:0;});
  11. std::cout << "The sum is: " << mySum << std::endl;
  12. return 0;
  13. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
The sum is: 9