Boost logo

Boost :

Subject: Re: [boost] New, powerful way to use enable_if in C++0x
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-04-12 12:56:46


Matt Calabrese wrote:
> On Tue, Apr 12, 2011 at 9:00 AM, Stewart, Robert
> <Robert.Stewart_at_[hidden]>wrote:
>
> > I don't care for boost::enabler because "boost::" and
> > "enable" are repeated (the first "enable" is in
> > "enable_when") and a long line is made even longer. Note
> > that the use of boost::enabler is optional: the type is void
> > *&, so, for example, "= 0" works just as well and might be
> > thought to negate enable_when.
>
> You can't initialize a reference template parameter to 0 (I
> don't believe you can for pointer parameters either for that
> matter).

You're right regarding references, of course, but a pointer to const should allow initialization from 0, right?

> If we go the route of making _when templates (which I'm not
> sure is a great idea as it doubles the number of templates in
> Boost.Enable_If),

That's a minor issue, compared to *& on the end which, as you noted previously, is unusual, and is easy to forget. Consider the error messages if one forgets to add *&.

> the syntax that I think would be best would be:
>
> typename enable_when< is_arithmetic< T > >::type = {}

Interesting, but not nearly as clear as "= true." OTOH, it eliminates the *& line noise.

Since I don't have access to a C++11 compiler that supports default function template arguments, I can't offer any other concrete suggestions.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP http://www.sig.com

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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk