Decorator for a class method
<p>Supposing I have a function (a decorator) that measures the duration of given function:</p>

<pre><code>#include &lt;unistd.h&gt;

void measure(void (*f)()) {
    time_t tBegin = time(NULL);
    f();
    time_t tEnd = time(NULL);
    cout &lt;&lt; "Duration: " &lt;&lt; (tEnd - tBegin) &lt;&lt; " sec" &lt;&lt; endl;
}
</code></pre>

<p>And I want to measure the duration of a method of a class. For example:</p>

<pre><code>class Myclass {
private:
    double _d;

public:
    Myclass(double d) : _d(d) {}

    void run() {
        measure(m);
    }

    void m() const {
        usleep(1000000 * _d);
    }
};

int main() {
    Myclass obj(2.0);
    obj.run();
    return 0;
}
</code></pre>

<p>Such implementation leads to the error:</p>

<pre><code>error: invalid use of non-static member function
</code></pre>

<p>Is there a way in C++ to implement it correctly? It's supposed not to modify the external function <code>measure</code> and the measured method is exactly non-static (it uses data of the instance). The measurement should be inside of the method <code>run</code>.</p>

<p>I need solution for C++ 1998/2003 Standard.</p>