473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

User defined numerical types as template parameters

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
1 1792
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ruben Campos | last post by:
I've found a problem with types defined inside a template. With a non-template class, I can write the following: // MyClass.hpp class MyClass { // ... typedef unsigned int MyType; MyType...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
2
by: Herby | last post by:
I need to define my own types and arrays of these types. These types are for the most part extensions of the built in types and need to provide all the basic operations of arithmetic and...
4
by: Philipp | last post by:
Hello I have a function writeValueXml(,,int) (see below) which converts an int value to a string which is then passed to a overloaded version of itself for printing writeValueXml(,,string) ...
3
by: hurcan solter | last post by:
I have an host class that holds fundamental types template<typename T> struct Generic{ Generic(T val= T()):mval(val){} operator T(){return mval;) T mval; }
3
by: Adam Nielsen | last post by:
Hi everyone, Yet another syntax problem that's baffling me with templates. I want to instantiate a template with a single parameter as per normal, however the parameter is actually a template...
0
by: StephQ | last post by:
I face two problems related to template classes. The first one is that you can not have the parameters of a class automatically deduced by the constructor. You can solve this problem using...
5
by: abir | last post by:
Hi, I want a user defined key for tr1 unordered_map. My classes are, template<typename T> struct work{ int count; work(int count) : count(count){} }; template<typename W>
5
by: greek_bill | last post by:
Hi, I'm trying to develop a system where I can register some data/ information about a class. For example // ClassInfo.h template <class T> struct ClassInfo { static const std::string ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.