Boost logo

Boost Users :

Subject: Re: [Boost-users] [proto] baby steps learning with proto, proxy object
From: Eric Niebler (eric_at_[hidden])
Date: 2010-10-08 15:31:00


On 10/7/2010 2:52 PM, alfC wrote:
<snip>
> So I guess we can create a proxy of the expression h[x] , "subindex of
> historgram with double". The proxy can be used with the syntax to call
> either accumulate or increment depending on the application of += or +
> + to the proxy.
>
> The naive implementation is this:
> class histogram{
> ...
> private:
> struct proxy_histogram_subscript{
> histogram& self;
> double const& x;
> proxy_histogram_subscript(histogram& self, double const& x) :
> self(self), x(x){}
> proxy_histogram_subscript const& operator++()
> const{self.increment(x); return *this;}
> bool operator++(int) const{return self.increment(x);}
> bool operator+=(double const& weight) const{return
> self.accumulate(x, weight);}
> };
> public:
> proxy_histogram_subscript operator[](double const& x){
> return proxy_histogram_subscript(*this, x);
> }
> };
>
> which allows the desired syntax. The question is, can Boost.Proto do
> better?
<snip>

Not really, I don't think. What you have is short, simple, and
efficient. I wouldn't mess with it further.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net