By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

User defined numerical types as template parameters

P: n/a
I'm writing a class where one template parameter must be a type
behaving like a floating-point type. Is there a standard way of
checking for this?

I can come up with two ways of doing this. One is to check if
std::numeric_limits<T>::is_specialized == true and
std::numeric_limits<T>::is_integer == false. Do other libraries use
this test? Is this in any way standard practice?

A second alternative I can think of is to write a FloatingPointConcept
class and use Boost's concept_check library. But I'm not sure as to
what syntactic constructions I should test for (seems to be many of
them!). Also, even if a type conforms to the syntatic constructions I
test for, the type might not behave like a floating point type
semantically.

Cheers,
/ALiX

Jul 29 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jul 29, 9:49 am, ALiX <alix.tof...@gmail.comwrote:
I'm writing a class where one template parameter must be a type
behaving like a floating-point type. Is there a standard way of
checking for this?

I can come up with two ways of doing this. One is to check if
std::numeric_limits<T>::is_specialized == true and
std::numeric_limits<T>::is_integer == false. Do other libraries use
this test? Is this in any way standard practice?
Yes, the unary type trait: std::tr1::is_floating_point<(or the boost
version, if tr1 is not available for your compiler) would be the
standard way of detecting any of the three built-in floating point
types (float, double and long double) as well as any user-defined type
with "floating point behavior" that had defined the appropriate
is_floating_point<specialization.

Greg
Jul 29 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.