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

Determine if type supports operation at compile time

Is there a way, using template metaprogramming techinques like e.g. SFINAE,
to determine at compile time if a type supports certain operation (for
example if operator == is defined for that type)?

// Function for types supporting ==
template<class Tbool func(T t)
{
if (t == 3)
return true;
else
return false;
}

// Function for types not supporting ==
template<class Tbool func(T t)
{
return false;
}

Can I somehow make compiler call appropriate function depending on type of
T?

thanks,
Marcin
Aug 2 '07 #1
1 1588
On 2 Aug, 20:47, "Marcin Kalicinski" <kal...@poczta.onet.plwrote:
Is there a way, using template metaprogramming techinques like e.g. SFINAE,
to determine at compile time if a type supports certain operation (for
example if operator == is defined for that type)?

// Function for types supporting ==
template<class Tbool func(T t)
{
if (t == 3)
return true;
else
return false;

}

// Function for types not supporting ==
template<class Tbool func(T t)
{
return false;

}

Can I somehow make compiler call appropriate function depending on type of
T?

thanks,
Marcin
Using the example of ==, there are plans to incorporate this type of
functionality into the next version of C++.

See the ConceptG++ EqualityComparable concept:

http://tinyurl.com/32q2bq

regards
Andy Little

Aug 3 '07 #2

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

Similar topics

3
by: Vinodh Kumar P | last post by:
Whenever I read any C++ literature I find the words "C++ is statically type checked".OK.Agreed. Is there any language that supports "Dynamic type checking"? In such a case any type can be assigned...
3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
2
by: Marcia Gulesian | last post by:
How can I determine the version of Safari (for example, 1.0.2 or 1.2.2) that's downloaded a document?
1
by: Ashabul Yeameen | last post by:
I am writing a program which at some point need to call fputwc() function. But since I want to make this code portable I've decided to write my own fputwc() funcion where the compiler doesn't...
2
by: Ashabul Yeameen | last post by:
Hi all, I am writing a C program which at some certain steps needs to use the wide character funcion fputwc() for giving utf-8 output. Since I want to make the code more portable, I wrote my own...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
1
by: Dave Harrington | last post by:
Greetings all - We have a client who uses Lotus Notes as their default e-mail. The version of Lotus they use can run internet explorer windows within Lotus. I'd like to find if they are...
19
by: perry.yuan | last post by:
How could I determine the endianness of my compile environment at compile time, instead of run time? I need a macro ("some_expression"), i.e. #if some_expression #define TARGET_IS_LITTLE_ENDIAN...
7
by: Robert | last post by:
Thanks George, I really am grateful for attempts to be helpful, but this really doesn't answer the question in my OP. What I am looking for is an explanation of WHY things are this way (I was...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.