I want to print some strings in functions, but indented depending on how far the depth of the function calls has gone. My solution so far includes a class from this thread like the following:
class DepthCounter
{
    static int depth;
public:
    DepthCounter(const std::string& name)
    {
        std::cout << std::string(depth*2, ' ') << name << "  // depth " << depth << '\n';
        ++depth;
    }
    ~DepthCounter()
    {
        --depth;
    }
};
int DepthCounter::depth = 0;
void func1(){
    DepthCounter dc("name1");
}
void func2(){
    DepthCounter dc("name2");
    func1();
}
so the print in the first construction will have 1 depth and the second one 2 depth (indent). but I want to make this print multiple times. that is
void func2(){
    DepthCounter dc("name0");
    DepthCounter dc1("name1");
    DepthCounter dc2("name2");
    DepthCounter dc3("name3");
    func1();
}
but I don't find it nice, let alone the fact that this construction increases the depth although it is still in the same function. Is there a better way do have such functionality?
ideally I want something like:
void func1(){
    funcX("name5");
}
void func2(){
    funcX("name0");
    funcX("name1");
    funcX("name2");
    funcX("name3");
    func1();
}
Does anyone know an alternative way?
 
    