Boost logo

Boost :

From: Joel de Guzman (djowel_at_[hidden])
Date: 2003-01-23 23:29:08


----- Original Message -----
From: "Aleksey Gurtovoy" <agurtovoy_at_[hidden]>

> My current understanding (which, admittedly, is not backed up by a
> real-world experience) is that if you care about higher-orderness of your
> generic algorithms, a preferred implementation construct for those
> algorithms is not a function template, but a static _function object_ (a
> technique used in FC++):
>
> struct my_function_
> {
> template< typename U >
> void operator()(std::string const& text, U)
> {
> // ...
> }
>
> } my_function; // here!
>
>
> For ordinary uses, the above will act just like a plain function template
> (minus ADL/explicit template arguments specification):
>
> my_function("text", int());
>
> and it will also allow one to do something like this:
>
> std::string text("text");
> mpl::for_each< my_types >(boost::bind<void>(my_function, text, _1));

Here's the Phoenix version:

    struct my_function_
    {

        template <typename Arg1T, typename Arg2T>
        struct result { typedef void type; };

        template< typename U >
        void operator()(std::string const& text, U)
        {
            // ...
        }

    };

    function<my_function_> my_function; // here!

Then:

    mpl::for_each< my_types >(my_function(text, _1));

Regards,
Joel de Guzman
joel_at_[hidden]
http://www.boost-consulting.com


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