473,387 Members | 1,532 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,387 software developers and data experts.

integral vs. user-defined type check

Is there a way to check if an object is an instance of a user-defined
type or an integral type? I have a templated class that this would be
very handy in (do _something_ if the template parameter is integral
type, or call a method of the template parameter if it is a
user-defined type/class).

I know this is quite error prone (e.g., instantiating the template
class with a class that doesn't define the required method), but this
is just for internal use (nothing distributed or production level).

Thanks in advance.

Sep 27 '05 #1
2 1819
maynard wrote:
Is there a way to check if an object is an instance of a user-defined
type or an integral type? I have a templated class that this would be
very handy in (do _something_ if the template parameter is integral
type, or call a method of the template parameter if it is a
user-defined type/class).

I know this is quite error prone (e.g., instantiating the template
class with a class that doesn't define the required method), but this
is just for internal use (nothing distributed or production level).


Specialise. Explicitly.

See 'has_member' in archives.

V
Sep 27 '05 #2

Victor Bazarov wrote:
maynard wrote:
Is there a way to check if an object is an instance of a user-defined
type or an integral type? I have a templated class that this would be
very handy in (do _something_ if the template parameter is integral
type, or call a method of the template parameter if it is a
user-defined type/class).

I know this is quite error prone (e.g., instantiating the template
class with a class that doesn't define the required method), but this
is just for internal use (nothing distributed or production level).


Specialise. Explicitly.

See 'has_member' in archives.

V


Probably explicit specialization is what you want, like Victor says.
However, you might also find the Boost type traits library to be handy:

http://boost.org/doc/html/boost_typetraits.html

Cheers! --M

Sep 27 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
2
by: Susan Baker | last post by:
Hi, I got this error msg whilst building some classes. It is realatively asy to fix. But I just wondered, does anyone know the technical reason why one can't initialiaze a const static...
9
by: Fred Ma | last post by:
Hello, I've been trying to clear up a confusion about integer promotions during expression evaluation. I've checked the C FAQ and C++ FAQ (they are different languages, but I was hoping one...
6
by: bayxarea-usenet | last post by:
I am getting the following error during compiling: 'switch expression not integral' I am new to the switch command - here is a snip of my code where I have used this.. .. what is the problem...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
2
by: Daniel Molina Wegener | last post by:
Hello, How can I pad integral values on double variables with printf. I know that %.nf or %.ng sets the precision. But I want to pad the integral value with zeroes, like 001.023 or 032.012. ...
50
by: Romeo Colacitti | last post by:
Is the C library of most OSes (i.e, unix type OSes) implemented at the very low kernel or just outside kernel level? Looking through the source tree of Linux/BSDs it seems like the C library is...
1
by: Tomás | last post by:
When you have a constant integral in a program, like the population of a town, how do you declare it? A const variable or an enum? Up until now I've always used variables, e.g.: unsigned const...
6
by: =?ISO-8859-1?Q?Sch=FCle_Daniel?= | last post by:
Hello, In : def simple_integral(func,a,b,dx = 0.001): ....: return sum(map(lambda x:dx*x, func(arange(a,b,dx)))) ....: In : simple_integral(sin, 0, 2*pi) Out: -7.5484213527594133e-08 ...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.