fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <bitset>
  4. #include <algorithm>
  5. #include <climits>
  6.  
  7. template <typename IterType>
  8. unsigned long getValue(IterType i1, IterType i2)
  9. {
  10. unsigned long i = 0;
  11. std::bitset<8 * sizeof(unsigned long)> b;
  12. std::for_each(i1, i2, [&](int n) { b.set(i++, n);});
  13. return b.to_ulong();
  14. }
  15.  
  16. int main()
  17. {
  18. std::vector<int> v = {0, 1, 1, 0, 1, 0, 0, 1, 0, 0};
  19. auto val = getValue(v.rbegin(), v.rend());
  20. std::cout << val << "\n";;
  21. auto val2 = getValue(v.begin(), v.end());
  22. std::cout << val2;
  23. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
420
150