#include <iostream>
#include <cmath>

using namespace std;

template<size_t depth, typename Func, typename... Args>
auto deep(Func foo, Args&&... args)
{
    if constexpr(depth != 0)
    {
        return foo(deep<depth-1>(foo, std::forward<Args>(args)...));
    }
    else
        return foo(std::forward<Args>(args)...);
}

double Cos(double x) { return cos(x); }

int main(int argc, char * argv[])
{
    cout << deep<100>(Cos,0.0);
}
