Boost logo

Boost :

Subject: Re: [boost] review request: addition to type_traits library ofhas_operator_xxx
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-11-22 08:24:33

viboes wrote:
> Edward Diener-3 wrote:
> > On 11/17/2010 3:48 PM, Stewart, Robert wrote:
> >> Frédéric Bron wrote:
> >>>
> >>>> Renaming "has_new_operator" seems more appropriate,
> >>>> however. "has_operator_new" puts "operator" and "new" in the
> >>>> right order as the query is for operator new, not the
> >>>> new operator.
> >>
> >> There wasn't much discussion. You asked about
> >> "has_operator_less_than" versus "has_less_than_operator"
> >> and I suggested that the former is more consistent with
> >> C++ syntax, but that deviates from
> >> boost::has_new_operator.
> >>
> >>> At that time, we preferred has_operator_xxx to has_xxx_operator.
> >>
> >> I still think its better.
> >
> > I agree also. Having all the operator traits begin with
> > 'has_operator_' makes their use easier to remember.
> I prefer has_division_operator than has_operator_division,
> and yet more than has_operator_divide.
> division_operator ::= operator/()

This is, perhaps, a native language issue. The order of modifier and modified in natural languages varies. My contention is that "operator xxx" is C++ syntax and is read as "operator xxx" (for the various operators), so that leads to corresponding traits named "has operator xxx" thus "has_operator_xxx."

> Note that interfaces must be designed not only to satisfy the
> developer but to improve the readability. If a namespace is
> used, as a user I will need to be able to decipher that
> has_division<T>::type
> intends to be "has division operator".

It's quite readable to me for two reasons. First, I can't think of any other meaning of "has division" than "has a division operator." Second, I will need to know the namespace from which such a type came to understand the code. If I'm reading another's code, I'll want to know about using directives, using declarations, and namespace aliases.

> I will find much more clear If I have to read
> has_division_operator<T>::type

In situ, without first being cognizant of namespace aliases, using directives, and using declarations, that is ever so slightly more obvious, but "has_division" isn't unclear by any stretch.

If "operator" is to be in the trait name, don't forget the new operator versus operator new naming issue. The former is used in new expressions and the latter is the operator one can overload to allocate memory. The correct word order for the latter, from the Standard, is "operator new." Thus, the correct name for that trait is "has_operator_new" and that leads to the same order for the other traits, not to mention the lexicographical grouping that results. John is willing to rename has_new_operator, so we have latitude to consider it.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at