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

adding function overload to std - Good or Bad?

I've created a class with semantics such that it makes sense to call
std::abs(foo) and get a (double) result.

Is it sensible to add to the std namespace, or would it be better to put
an "abs" function it in the same namespace as my class was created?
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Jun 27 '08 #1
9 3360
On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote:
I've created a class with semantics such that it makes sense to call
std::abs(foo) and get a (double) result.

Is it sensible to add to the std namespace, or would it be better to put
an "abs" function it in the same namespace as my class was created?

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
No it wouldn't be good.
Jun 27 '08 #2
sumsin wrote:
On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote:
>I've created a class with semantics such that it makes sense to call
std::abs(foo) and get a (double) result.

Is it sensible to add to the std namespace, or would it be better to put
an "abs" function it in the same namespace as my class was created?

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

No it wouldn't be good.
Thanks for the ambiguous response, it's very helpful.

Which wouldn't be good, and more importantly, *why*?

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Jun 27 '08 #3
On Jun 7, 11:00 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote:
sumsin wrote:
On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote:
I've created a class with semantics such that it makes sense to call
std::abs(foo) and get a (double) result.
Is it sensible to add to the std namespace, or would it be better to put
an "abs" function it in the same namespace as my class was created?
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
No it wouldn't be good.

Thanks for the ambiguous response, it's very helpful.

Which wouldn't be good, and more importantly, *why*?

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
because std namespace is meant for standard utilities and your
semantics for 'abs' function is not standard from the language
perspective thats why i am suggesting no. So keep it into your custom
namespace.
Jun 27 '08 #4
Daniel Pitts wrote:
sumsin wrote:
>On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote:
>>I've created a class with semantics such that it makes sense to call
std::abs(foo) and get a (double) result.

Is it sensible to add to the std namespace, or would it be better to put
an "abs" function it in the same namespace as my class was created?

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

No it wouldn't be good.
Thanks for the ambiguous response, it's very helpful.

Which wouldn't be good,
Putting it into namespace std.
and more importantly, *why*?
One reason would be because the C++ standard forbids it.

Jun 27 '08 #5
On Jun 7, 7:10*am, sumsin <sumsin...@gmail.comwrote:
On Jun 7, 11:00 am, Daniel Pitts

<newsgroup.spamfil...@virtualinfinity.netwrote:
sumsin wrote:
On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote:
>I've created a class with semantics such that it makes sense to call
>std::abs(foo) and get a (double) result.
>Is it sensible to add to the std namespace, or would it be better to put
>an "abs" function it in the same namespace as my class was created?
>--
>Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
No it wouldn't be good.
Thanks for the ambiguous response, it's very helpful.
Which wouldn't be good, and more importantly, *why*?
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

because std namespace is meant for standard utilities and your
semantics for 'abs' function is not standard from the language
perspective thats why i am suggesting no. So keep it into your custom
namespace.
Or you could do:

namespace super_std {

using namespace std;

/* Put more stuff here */
}
Jun 27 '08 #6
Rolf Magnus wrote:
Daniel Pitts wrote:
>sumsin wrote:
>>On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote :
I've created a class with semantics such that it makes sense to call
std::abs(foo) and get a (double) result.

Is it sensible to add to the std namespace, or would it be better to put
an "abs" function it in the same namespace as my class was created?

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
No it wouldn't be good.
Thanks for the ambiguous response, it's very helpful.

Which wouldn't be good,

Putting it into namespace std.
>and more importantly, *why*?

One reason would be because the C++ standard forbids it.
I thought it was OK to add template specializations in std::
Jun 27 '08 #7
red floyd wrote:
Rolf Magnus wrote:
>Daniel Pitts wrote:
>>sumsin wrote:
On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrot e:
I've created a class with semantics such that it makes sense to call
std::abs(foo) and get a (double) result.
>
Is it sensible to add to the std namespace, or would it be better to
put an "abs" function it in the same namespace as my class was
created?
>
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
No it wouldn't be good.
Thanks for the ambiguous response, it's very helpful.

Which wouldn't be good,

Putting it into namespace std.
>>and more importantly, *why*?

One reason would be because the C++ standard forbids it.

I thought it was OK to add template specializations in std::
Yes, but the OP wants to add an overload, not a template specialization.

Jun 27 '08 #8
Rolf Magnus wrote:
red floyd wrote:
>Rolf Magnus wrote:
>>Daniel Pitts wrote:

sumsin wrote:
On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.netwrote :
>I've created a class with semantics such that it makes sense to call
>std::abs(foo) and get a (double) result.
>>
>Is it sensible to add to the std namespace, or would it be better to
>put an "abs" function it in the same namespace as my class was
>created?
>>
>--
>Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
No it wouldn't be good.
Thanks for the ambiguous response, it's very helpful.

Which wouldn't be good,
Putting it into namespace std.

and more importantly, *why*?
One reason would be because the C++ standard forbids it.
I thought it was OK to add template specializations in std::

Yes, but the OP wants to add an overload, not a template specialization.
Isn't std::abs a template?
Jun 27 '08 #9
red floyd wrote:

>>>>Which wouldn't be good,
Putting it into namespace std.

and more importantly, *why*?
One reason would be because the C++ standard forbids it.

I thought it was OK to add template specializations in std::

Yes, but the OP wants to add an overload, not a template specialization.

Isn't std::abs a template?
Well, there is an std::abs template, but only for std::valarray:

template<class Tvalarray<Tabs (const valarray<T>&);

The rest are just overloads.

Jun 27 '08 #10

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

Similar topics

4
by: Remi Ricard | last post by:
Hi, This is a code that reproduce my problem. #include <stdio.h> class A { public: virtual int get(int a)=0; int get(float a) {return 1;} };
7
by: zalzon | last post by:
Is it good practice in C++ for a member function to return data or is it better that data is stored in private member variable and printed in the member function? should i be using int...
2
by: Kamran | last post by:
Hi I have very little experience of C++, nevertheless I have been asked to write a gui using QT/QWT. I know that I should direct the question to the relevant mailing list and I have done that but...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
39
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any...
45
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
1
by: Sagaert Johan | last post by:
Hi I am construncting a string containing some control chars (STX/ETX) I noticed that adding a byte with value 2 is the same as adding a character '2' ??? How can i solve this problem ?...
24
by: Rahul | last post by:
Hi Everyone, I was just overloading operator = for a class and i have a problem in one case... class A { A& operator=(const A& obj) { return *this;
11
Niheel
by: Niheel | last post by:
http://bytes.com/images/howtos/information_overloaded.jpgPaul Graham wrote an interesting article a few months back about how the internet is leading to information overload for information workers...
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
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...
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
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.