Boost logo

Boost :

Subject: Re: [boost] sorting library proposal
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-06-04 11:36:36


Steven Ross wrote
On Thursday, June 04, 2009 10:41 AM
>
> Is there a good way to issue a compile-time warning telling
> people that integer_sort or float_sort isn't being used,
> because they passed in an incompatible data type? I see
> static assertions, but what I need is an equivalent static
> warning, after which I use std::sort.

I'm not aware of any.

> Also, I'm using a simple if to decided this:
>
> if(sizeof(Div_type) <= sizeof(size_t))
>
> because enable_if appears to only work with classes. I'm

enable_if_c works with any Boolean expression.

> assuming here that the compiler is smart enough to figure
> out that the expression is constant and to only bring in the
> code if it's true. It would be nice to be able to eliminate
> the compiler warnings about size, and issue a more concise
> and meaningful message telling the user that their data type
> is too big for integer_sort (or incompatible with
> float_sort, as appropriate).

If you forward to an implementation class template with a bool template parameter defaulted to sizeof(Div_type) <= sizeof(size_t), you can partially specialize for the false case to provide the alternative implementation. Thus, your algorithm invokes a static member function of the implementation class to select the appropriate implementation via compile time dispatch.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
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