|
Boost Users : |
Subject: Re: [Boost-users] How to force a compile failure if a template parameter isn't floating-point
From: Alexander Stoyan (alexander.stoyan_at_[hidden])
Date: 2012-07-18 06:57:20
If you need only floating points only, then what do you need template for?
Make two overloaded versions of your routine:
std::string f(float v)
{
...
}
std::string f(double v)
{
...
}
That's it :)
-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Paul A. Bristow
Sent: Wednesday, July 18, 2012 1:54 PM
To: boost-users_at_[hidden]
Subject: [Boost-users] How to force a compile failure if a template
parameter isn't floating-point
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 mailing list Boost-users_at_[hidden] http://lists.boost.org/mailman/listinfo.cgi/boost-users
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