-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Maddock Sent: Wednesday, July 18, 2012 3:41 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] How to force a compile failure if a templateparameter isn't 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.
template <typename FPT> typename enable_if
::type f(FPT v) { ... } If FTP is not a built in floating point type, then no overload for f() will be found and you'll get a compiler error.
Well - out of curiosity (having solved my problem neatly with BOOST_STATIC_ASSERT) I had a brief skirmish with this but got error C4519: default template arguments are only allowed on a class template and my need is for a free function, not a member function. It isn't worth spending time on me or you making this work - having solved my problem (which was actually downstream and these checks are now redundant). However, in reading the docs for enable_if (and to some extent type_traits), I felt they were not up to the current best examples of documentation. They lack enough tutorial (especially at an introductory level) material, and especially the invaluable fully worked (and commented) examples. I think we need these improved if these undoubtedly invaluable tools are to come out of the 'gurus and brainiacs only' zone and be suitable for 'bears of little brain' ;-) Might this be a GSoC project? Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com