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

Guaranteeing that a function does *not* exist

I'd like to write code that fails to compile if a certain
function *does* exist in a 3rd party library. (This is the
opposite of the well-known problem of wanting compilation to fail if
a certain function does *not* exist.)

Say a library class has been designed to prevent use
of the copy constructor,

class C
{
[stuff...]
private:
C( C const & );
};

I then write client code that assumes a C is never constructed from
another C. But, for extra safety, I'd like to put something in my code
that would cause the compiler to reject my code, should that 3rd party
library ever be changed so as to expose and define the C copy
constructor.

Maybe there's some SFINAE (substitution failure is not an error)
template trick for this...? In any case, I haven't been able to put
one together.
Ted Sternberg
Berkeley, CA, USA

Jul 23 '05 #1
4 1897
st*****@trhj.homeunix.net wrote:
I'd like to write code that fails to compile if a certain
function *does* exist in a 3rd party library. (This is the
opposite of the well-known problem of wanting compilation to fail if
a certain function does *not* exist.)

Say a library class has been designed to prevent use
of the copy constructor,

class C
{
[stuff...]
private:
C( C const & );
};

I then write client code that assumes a C is never constructed from
another C. But, for extra safety, I'd like to put something in my code
that would cause the compiler to reject my code, should that 3rd party
library ever be changed so as to expose and define the C copy
constructor.

Maybe there's some SFINAE (substitution failure is not an error)
template trick for this...? In any case, I haven't been able to put
one together.


Your "exists in a 3rd party library" is quite vague. What do you mean
by it, exactly? If you don't try using it in your code, yet it exists,
should it compile? How would "existence" be known to the compiler if
it never attempts, to, say, link against that library?

V
Jul 23 '05 #2
Do you know what the name of that function? If you do, then you can just define
a function in the same scope and the same arguments, and the program should fail
to compile (you can't have two functions defined that have the same name and
parameters -- make sure to match constness too if it's a member function).

HTH

- JFA1
Jul 23 '05 #3
Great idea (and breathtakingly simple). I do know the name of the
function; it's the copy constructor, so this will do the trick just
fine. Thanks.

Jul 23 '05 #4
<st*****@trhj.homeunix.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Great idea (and breathtakingly simple). I do know the name of the
function; it's the copy constructor, so this will do the trick just
fine. Thanks.


How can it do the trick when the function in question is inside a class
definition provided by (I presume) a third party?

DW
Jul 23 '05 #5

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

Similar topics

8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
19
by: anguo | last post by:
i find in many hash function use 5381,for exampla: static constmap_hash hash(char *pchData, int iLen) { unsigned char cBuf; constmap_hash ulHashId; ulHashId = 5381; while (iLen > 0) { cBuf =...
5
by: Andy | last post by:
Sigh... working on it for whole day and got no idea... Basically I want to have a bitmask filtering function, I will throw in 3 parameters: bitMaskValue - current bitmask value filterValue -...
2
by: Lee Harr | last post by:
I am following along with the pl/pgsql docs here: http://www.postgresql.org/docs/current/static/plpgsql-declarations.html In section 37.4.3. Row Types I have altered the function slightly (I...
0
by: Marcel Boscher | last post by:
Hello everybody, i get strange error messages when trying to call up my function with a SELECT functionname(with or without int); varying from: ERROR: function chr(double precision) does...
2
by: Johann Robette | last post by:
Hi, I'm trying to call the array_to_string function like this : SELECT array_to_string(array, '~^~') --> it comes directly from the doc. I get this error msg : ERROR: parser: parse error at...
11
by: sara | last post by:
I am trying my first functions in my code. I have a set of queries that runs to create temp tables with the right data for some reports. They can run for a long time, so I want the user to know...
9
by: Mike | last post by:
Hi, Just a simple question: why the compiler doesn't report error when accessing a private member function inside a function having template type ? For example: #include<iostream> using...
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.