On 23 Apr 2001, Lars Gullik [iso-8859-1] Bjønnes wrote:

> Allan Rae <[EMAIL PROTECTED]> writes:
> | struct LFUNAction {
> |     void operator() (pair<LFUN, string>);
> | };
> |
> | for_each(macro.begin(), macro.end(), LFUNAction());
>
> Still don't like it.
>
> std::for_each(macro.begin(), macro.end(),
>               lyx::class_fun(string, lyxfunc, LyXFunc::Dispatch));
>
> seems better to me, more obvious and open.

Then how about:

struct LFUNAction {
        LFUNAction(LyXFunc &);
        string const operator() (pair<int, string const &> lfun) {
                return lf_.Dispatch(lfun.first, lfun.second);
        }
private:
        LyXFunc lf_;
};

for_each(macro.begin(), macro.end(), LFUNAction(lyxfunc));

This leaves the problem of what happens to the returned string.  I'm
pretty sure we can ignore it completely.

It also seems that you are overlooking the extra string arguement as your
solution sets the return type as string and only has one input, an int.
What if,
        string const Dispatch(int action, string const & arg = string());

is called with an arg other than string()?  This is certainly possible as
evidenced in
        int LyXFunc::processKeySym(KeySym keysym, unsigned int state);

near the end and also in:
        string const LyXFunc::Dispatch(string const & s)

Unless of course I'm not understanding how lyx::class_fun is supposed to
work because I can't see any version of that that takes three parameters.
Both implementations appear to to only take one parameter for the
function.  So would you be changing Dispatch(int, string) into
Dispatch(pair<int, string>) ?

Allan. (ARRae)

Reply via email to