Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <stdexcept>
- #include <exception>
- #include <vector>
- #include <string>
- #include <cctype>
- #include <forward_list>
- #include <deque>
- #include <iostream>
- template <class Iterator, class Predicate, class Functor>
- void TransformIf(Iterator first, Iterator last, Predicate p, Functor f) {
- std::vector<std::pair<int, decltype(*first)>> log;
- int cnt = 0;
- for (auto i = first; i != last; ++i) {
- try {
- if (p(*i)) {
- try {
- log.template emplace_back(cnt, *i);
- } catch (...) {
- }
- f(*i);
- }
- ++cnt;
- } catch (...) {
- auto it = first;
- int in = 0;
- for (int j = 0; j != cnt && in < log.size(); ++j) {
- if (log[in].first == j) {
- *it = log[in].second;
- }
- ++it;
- }
- throw;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement