#include #include #include #include template std::vector equilibrium(T first, T last) { typedef typename std::iterator_traits::value_type value_t; value_t left = 0; value_t right = std::accumulate(first, last, value_t(0)); std::vector result; for (size_t index = 0; first != last; ++first, ++index) { right -= *first; if (left == right) { result.push_back(index); } left += *first; } return result; } template void print(const T& value) { std::cout << value << "\n"; } int main() { const int data[] = { -7, 1, 5, 2, -4, 3, 0 }; std::vector indices(equilibrium(data, data + 7)); std::for_each(indices.begin(), indices.end(), print); }