Boost logo

Boost :

Subject: Re: [boost] sorting library proposal
From: Gevorg Voskanyan (v_gevorg_at_[hidden])
Date: 2009-06-04 11:03:40


Steven Ross wrote:
> 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.

You can have a look here:
http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/static_warning.html

[snip]

> 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.

enable_if does work for functions as well, that's for sure.

E.g.

template < typename Div_type >
typename boost::enable_if_c< sizeof(Div_type) <= sizeof(size_t), void >::type
foo( /*args*/ )
{
    // use optimized algorithm
}

template < typename Div_type >
typename boost::disable_if_c< sizeof(Div_type) <= sizeof(size_t), void >::type
foo( /*args*/ )
{
    // fallback to std::sort
    BOOST_STATIC_WARNING( sizeof(Div_type) <= sizeof(size_t) );
    // BOOST_STATIC_WARNING( false ); won't work because the expression must depend on a template parameter
}

Or you might consider using tag dispatching to avoid having the condition duplicated in enable_if_c and disable_if_c.

[snip]

HTH,

Regards,
Gevorg

      


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk