Boost logo

Boost :

Subject: Re: [boost] [local] Help for the Alternatives section
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-05-12 16:00:39


On Thu, May 12, 2011 at 12:05 PM, lcaminiti <lorcaminiti_at_[hidden]> wrote:

>
> Jeffrey Lee Hellrung, Jr.-2 wrote:
> >
> > On Thu, May 12, 2011 at 11:16 AM, lcaminiti &lt;lorcaminiti_at_[hidden]
> &gt;
> > wrote:
> >
> >>
> >> Jeffrey Lee Hellrung, Jr.-2 wrote:
> >>
> > [...]
> >
> >> > I would infer from this and the documentation that
> >> >
> >> > const bind(const int&) factor // outer const superfluous???
> >> > bind(const int&) factor
> >> > const bind(const int)& factor // outer const superfluous???
> >> > bind(const int)& factor
> >> > const bind(int)& factor
> >> > bind(const int&) const factor // outer const superfluous???
> >> > bind(int) const & factor
> >> >
> >> > are all equivalent, but I'm not sure. Can you please clarify in the
> >> > documentation?
> >> >
> >> > [...snip rest of example...]
> >> >
> >>
> >> Yes, the Tutorial section already mentions that:
> >> 1) const must always appear before bind when constant binding is used so
> >> bind ... const is not valid (this is just for simplicity, the macros
> >> could
> >> be programmed to accepts both const bind and bind const).
> >> 2) when const bind is used on a variable that is already const the
> bind's
> >> const has no effect.
> >>
> >
> > So that addresses the placement of const; the '&' can also either be put
> > inside or outside the bind(...), right?
> >
>
> No. References are bound be value when bind is used without the trailing &:
>
> int y = 0;
> int& x = y
> BOOST_LOCAL_BLOCK(bind x) { // by val
> x = 0; // Has only local effect (outer x and y are not changed).
> }
> BOOST_LOCAL_BLOCK(bind& x) { // by ref
> x = 0; // Has effect on enclosing scope (outer x and y are changed).
> }
>
> This is how Boost.ScopeExit bind semantic works and it made sense to me
> because it allows to bind references by both value and reference (and not
> just by reference). I can spell this out more clearly in the docs.
>

I meant to explicitly ask whether the following are equivalent:

    bind(T)& x
    bind(T&) x

[...]

> > Also, what about commas from template instantiations? E.g., does
> >
> > bind(tmpl&lt;T1,T2&gt;) x
> >
> > work?
> >
>
> Yes but you have to use BOOST_IDENTITY_TYPE (its a macro of Boost.Local
> that
> I'd eventually propose to add to under boost/utility). It's explained in
> the
> Advanced Topics section:
>
>
> http://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/boost_local/Advanced_Topics.html#boost_local.Advanced_Topics.commas_and_symbols_in_macro_parameters
>
> For example:
>
> bind(BOOST_IDENTITY_TYPE((std::map&lt;std::string, double&gt;))) x
>
> This works (on ISO C++, no variadics required). Note the extra set of
> parenthesis needed around the type-with-commas within the macro parenthesis
> BOOST_IDENTITY_TYPE((type_with_commas)) -- it expands to something like
> function_traits&lt;void(type_with_commas)&gt;::arg1_type.
>

Sounds good.

- Jeff


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