#include <functional>
#include <iostream>

std::function<int(int, int)> sum = [](int a, int b) { return a + b; };

// create a "before" hook
template<typename Functor, typename Hook>
Functor hook_before(const Functor & original, Hook hook)
{
    // not legal, but illustrates what I want to achive
    template<typename Args ...args> 
    return [=](Args ...args)
    {
        hook();
        original(args...);
    };
}

int main()
{
    std::cout << sum(3, 4) << std::endl;

    auto myhook = []() { std::cout << "Calculating sum" << std::endl; };
    auto hooked_sum = hook_before(sum, myhook);
    hooked_sum(3, 4);
}