Boost logo

Boost :

Subject: Re: [boost] Local and Phoenix idiosyncrasy
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-12-02 00:40:20


On Thu, Dec 1, 2011 at 3:46 AM, Lorenzo Caminiti <lorcaminiti_at_[hidden]>wrote:

> On Sat, Nov 26, 2011 at 7:28 AM, Lorenzo Caminiti <lorcaminiti_at_[hidden]>
> wrote:
> > On Thu, Nov 24, 2011 at 1:14 PM, Thomas Heller <
> thom.heller_at_[hidden]> wrote:
> >> Here is what I have to propose: Why not combine Boost.Local and
> >> Boost.Phoenix and keep everybody happy?
>
> Hello Thomas, Joel, Hartmut, et alt. Sorry for asking again... I know
> we are all trying to get disintoxicated from the last week's
> discussions :)
>
> > int main() {
> > using boost::phoenix::arg_names::arg1;
> >
> > std::vector<int> v(3);
> > v[0] = 1; v[1] = 2; v[2] = 3;
> > int offset = 10;
> >
> > // Phoenix function defined locally:
> > int BOOST_LOCAL_FUNCTION_PARAMS(int x, bind offset) {
> > int total = x + offset;
> > std::cout << total << std::endl;
> > return total;
> > } BOOST_LOCAL_FUNCTION_NAME(local_add)
> >
> > boost::phoenix::function<BOOST_LOCAL_TYPEOF(local_add)> pl_add =
> local_add;
> > std::for_each(v.begin(), v.end(), pl_add(arg1));
> >
> > return 0;
> > }
>
> Would this ability to plug local functions into Phoenix be useful?
>
> > // some global scope
> > template<typename Arg1>
> > Arg1 BOOST_PHOENIX_FUNCTION_TPL(Arg1 const& n) {
> > return (n <= 0) ? 1 : n * (*this)(n - 1);
> > } BOOST_PHOENIX_FUNCTION_END(factorial_impl);
> >
> > boost::phoenix::function<factorial_impl> f;
>
> Is there any interest in the above macros to define Phoenix functions
> at global scope?
>

I don't think this would be all that useful. If you're doing doing
something simple enough with Phoenix that it could just be rolled into the
local function, you should probably just do that (e.g., the "pl_add(arg1)"
above might as well just be "local_add"). If it's more complicated than
that, maybe you should just "suck it up" and define it out-of-line. I
wouldn't think you would get much extra mileage from mixing local functions
with Phoenix.

- Jeff


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