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-17 15:13:42

vicente.botet wrote:
> From: "Edward Diener" <eldiener_at_[hidden]>
> On 11/16/2010 6:49 PM, Frédéric Bron wrote:
> >
> > // binary operators:
> > template< typename LHS, typename RHS=LHS, typename RET=void>
> > == has_operator_equal_to
> > != has_operator_not_equal_to
> > > has_operator_greater
> > >= has_operator_greater_equal
> > < has_operator_less
> > <= has_operator_less_equal
> > + has_operator_plus
> > - has_operator_minus
> > * has_operator_multiplies
> > / has_operator_divides
> > % has_operator_modulus
> > && has_operator_logical_and
> > || has_operator_logical_or
> > & has_operator_bit_and
> > | has_operator_bit_or
> > ^ has_operator_bit_xor
> >
> > // unary operators:
> > template< typename RHS, typename RET=void>
> > + has_operator_unary_plus
> > - has_operator_unary_minus
> > ! has_operator_logical_not

Those names are not consistent with boost::has_new_operator. That is, you need to rename them like the following for consistency:


The result won't be perfect. For example, "has_operator_divides" should be renamed "has_division_operator."

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.

> ::boost::has_address_of_op<T>::value
> Evaluates to true if the expression &a is valid.

"has_operator_address_of" is more consistent with the above list, but "has_address_of_operator" is more consistent with boost::has_new_operator.

The same discussion applies to the other traits.

> ::boost::has_member_access_op<T>::value
> Evaluates to true if the expression a-><member> is valid.

That's called the member selection operator, so "has_member_selection_operator."

> The member access operator has to be a member function, so it
> can only be detected for classes and unions by specialising
> this trait. It gives default true for these.

Why would the default be true? I'd expect the default to be false so only those classes for which a specialization is provided which may evaluate to true. (The only reason to specialize the trait, then, is for classes that define the operator.)

The same question applies to the other traits that default to true.

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