Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-05 13:45:37


From: <sanichin_at_[hidden]>
[...]
> For example, at least a couple Windows compilers support the
> __stdcall calling convention, where the callee removes parameters
> from the stack.

All Windows compilers support it. ;-) They have to.

> The Win32 API and COM objects use this calling
> convention.
>
> A __stdcall member function pointer looks like this:
> typedef void (__stdcall T::*SomeMemberFunctionPtr)();

I've somehow managed to miss the fact that __stdcall can be applied to
member pointers, too (they usually use __thiscall); thank you for pointing
this out.

[...]
> But what I've had to do to solve the problem is basically re-
> implement ALL of mem_fn.hpp, and implement my own bind function
> templates. A simple generic, compiler-independent change to
> boost::mem_fn could at least simplify the work of supporting compiler-
> specific calling conventions.

The __stdcall-specific mem_fn and bind overloads would still be written
separately (although we could provide them as an "unofficial" extension) but
extending _mfi::(c)mfN to be able to handle __stdcall is probably a good
idea.

> The idea I used was to use a traits struct to specify the type of the
> function pointer. This is best illustrated through code:
[...]

I think I have a better solution. Currently mf0 is defined like this:

template<class R, class T> class mf0
{
public:

    typedef R result_type;
    typedef T * first_argument_type;

private:

    typedef R (T::*F) ();
    F f_;

public:
    // omitted
};

This can be trivially extended to handle any "pointer to member" type:

template<class R, class T, class F = R (T::*) ()> class mf0
{
public:

    typedef R result_type;
    typedef T * first_argument_type;

private:

    F f_;

public:
    // omitted
};

What do you think? Let's hope that this change won't break anything. I'll
fix mem_fn.hpp after 1.25.1 is released.

The overloads will have to go in separate headers, mem_fn_stdcall.hpp and
bind_stdcall.hpp. How to best provide such a platform-specific feature is an
open question.

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk