|
Boost : |
Subject: Re: [boost] [local] this_ or _this?
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-04-05 20:11:28
On Tue, Apr 5, 2011 at 4:52 PM, Lorenzo Caminiti <lorcaminiti_at_[hidden]>wrote:
> On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe <watanabesj_at_[hidden]>
> wrote:
> > AMDG
> >
> > On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
> >>
> >> Boost.Local uses a special name `this_` to access the object `this`
> >> bound from the enclosing scope. Shall this name be `this_` or `_this`
> >> according to Boost practices?
> >>
> >> struct c {
> >> void g(int x) { ... }
> >> void f() {
> >> void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) {
> >> this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);`
> >> instead?
> >> ...
> >> } BOOST_LOCAL_FUNCTIO_NAME(l)
> >> ...
> >> }
> >> ...
> >> };
> >>
> >> In particular, some library uses _ postfix for statements like
> >> mpl::if_ (not mpl::_if) while other uses _ prefix for variables like
> >> phoenix::local_names::_f (not local_names::f_).
> >>
> >
> > The convention is that _xxx is used for placeholders.
> > xxx_ is used when xxx is a keyword.
>
> 1) What is the exact definition of a "placeholder"?
>
My guess: Any object that gets implicitly bound upon the evaluation of its
enclosing expression.
> 2) What is the convention for an xxx that is both a keyword and a
> placeholder?
>
My guess: Just use a leading underscore, as then it isn't a keyword anymore,
so no need for a trailing underscore.
I wouldn't consider your bound "this" variable *implicitly* bound, as it
appears explicitly in the bind list, so I'm partial to "this_" (trailing
underscore only).
I also believe some variant of "this" is better than other suggestions like
"that" and "self", because:
- The bind list should use the keyword "this" to bind the current object, as
that's the *only* thing "this" could mean. Any other keyword you choose
*could* happen to be a local variable that the user *could* want to bind
instead, and they'd be SOL.
- The keyword used in the function body should match (as closely as
possible) the keyword used in the bind list.
Also, additional suggestion, but probably not a good one: You could provide
a macro for any user to introduce a new name for the "this" variable within
a Boost.Local block, similar to Boost.Tribool's macro that allows one to
introduce a new name for the 3rd tribool state. So if one prefers "self",
"_this", "this_", "that", etc., they will be free to do so. Of course,
introducing multiple names for the same thing can easily make things
confusing...
- Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk