Boost logo

Boost Users :

Subject: Re: [Boost-users] How to force a compile failure if a template parameter isn't floating-point
From: Maxime van Noppen (maxime_at_[hidden])
Date: 2012-07-18 07:02:57


On 07/18/2012 12:54 PM, Paul A. Bristow wrote:
> Suggestions welcome :-)

Hi,

Either:

http://www.boost.org/doc/libs/1_47_0/doc/html/boost_staticassert.html

BOOST_STATIC_ASSERT(boost::is_floating_point<FPT>::value);

Or:

http://www.boost.org/doc/libs/1_47_0/libs/utility/enable_if.html

template <typename FPT>
std::string f(FPT v,
  typename
boost::enable_if_c<boost::is_floating_point<FPT>::value>::type* = 0)

But you might as well consider having:

template <typename FPT>
std::string f_impl(FPT v)
{
}

std::string f(float v) { return f_impl(v); }
std::string f(double v) { return f_impl(v); }

Best,

-- 
Maxime

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net