Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Non-const First Argument for Nested eval<>'s operator() ()
From: Eric Niebler (eric_at_[hidden])
Date: 2011-01-12 00:47:05


On 1/10/2011 10:00 AM, Hossein Haeri wrote:
> Dear all,
>
> In the Proto documentation, is there any reason why in all the specialisations of eval<Expr> for contexts, the first argument to their operator() is of type Expr& as opposed to const Expr&?

The docs don't make this very clear (and are in fact a little out of
date) but this:

  const Expr & e = ...;
  Context ctx;
  proto::eval( e, ctx );

is essentially equivalent to:

  Context::eval< Expr const, Context >()( e, ctx );
-----------------^^^^^^^^^^

That is, proto::eval deduces the const-ness of the expression and uses
that in the instantiation of the nested eval struct. For that reason,
eval::operator() need only take the expression parameter by Expr &. The
const-ness is baked into the "Expr" template parameter.

Hope that makes sense. If not, just look at the implementation of
proto::eval. It's a one-liner.

-- 
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