Skip to content

Instantly share code, notes, and snippets.

@ilpropheta
Created June 4, 2016 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpropheta/ab72ff0d6842e418e42f11c92b9d60f2 to your computer and use it in GitHub Desktop.
Save ilpropheta/ab72ff0d6842e418e42f11c92b9d60f2 to your computer and use it in GitHub Desktop.
auto mult = number[0] == '-' ? -1 : 1;
auto realBegin = mult > 0 ? begin(number) : next(begin(number));
auto toInt = mult * accumulate(realBegin, end(number), 0, [](int curr, char nxt){
return curr * 10 + nxt - '0';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment