Boost logo

Boost Users :

Subject: [Boost-users] How to force a compile failure if a template parameter isn't floating-point
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2012-07-18 06:54:21


I have some functions that I want to ensure (with a compile failure - because it means a logical
mistake) that they are not instantiated if the template parameter is not floating point type.

In effect,

 #error Type Not floating point!

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

At present I have added a run-time check, but doesn't prevent compilation (and instantiation).

  if (boost::is_floating_point<FPT>::value; == false)
  {
    assert fail or something and/or
    return " "Type Not floating point!";
  }

I don't see how enable_if can help either.

I can't find

  BOOST_CONCEPT_ASSERT((boost::FloatingPoint<FPT>));
or
   boost::function_requires< boost::Integer<FPT> >();

Suggestions welcome :-)

Paul

---
Paul A. Bristow,
Prizet Farmhouse, Kendal LA8 8AB  UK
+44 1539 561830  07714330204
pbristow_at_[hidden]

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