Boost logo

Boost :

Subject: Re: [boost] New libraries implementing C++11 features in C++03
From: Joel de Guzman (joel_at_[hidden])
Date: 2011-11-25 08:58:04


On 11/25/2011 9:21 PM, Christopher Jefferson wrote:
>
> Sorry to ask you another problem, but could you try another test?
>
> The following code shows a small example, which comes from a real program of mine. I
have changed my old out-of-line code to use boost local. Note that in practice there are
many different types which implement my 'vars' interface (getMax/getMin/setMax/setMin).
>
> #include <iostream>
> #include <string>
> #include <vector>
> #include <algorithm>
> #include "local/boost/local/function.hpp"
>
>
> template<typename T>
> struct Var
> {
> void setMax(int i) {}
> void setMin(int i) {}
> int getMax() { return 0; }
> int getMin() { return 0; }
> };
>
> template<typename T>
> void squeeze_vars_local(std::vector<T>& vec, int i)
> {
>
> void BOOST_LOCAL_FUNCTION_PARAMS_TPL(T& t, bind i)
> {
> t.first.setMax(t.second.getMax() - i);
> t.second.setMin(t.first.getMin() + i);
> } BOOST_LOCAL_FUNCTION_NAME(squeeze);
>
> std::for_each(vec.begin(), vec.end(), squeeze);
> }
>
> int main(void)
> {
> std::vector<std::pair<Var<int>, Var<double> > > v;
> squeeze_vars_local(v,2);
> }
>

> In the past I tried turning this into phoenix code, and failed. I'd be genuinely
interested to know what it would look like as a phoenix function.

Here's the phoenix functions rendition of that:

  http://pastebin.com/QWnHiKkv

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

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