Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <typename Op, typename T>
- T accumulate(const Op& _operator, const T& a, const T& b){
- return _operator(a, b);
- }
- template <typename Op, typename T, typename ... Types>
- T accumulate(const Op& _operator, const T& head, Types ... tail){
- return accumulate(_operator, head, accumulate(_operator, tail...));
- }
- class my_operator{
- public:
- int operator ()(int a, int b) const{
- return a + b;
- }
- };
- int main(){
- cout << accumulate(my_operator(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment