|
Boost : |
Subject: Re: [boost] Local and Phoenix idiosyncrasy
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-12-01 06:46:15
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?
Thanks a lot.
--Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk