Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > adding function overload to std - Good or Bad?

Reply
Thread Tools

adding function overload to std - Good or Bad?

 
 
Daniel Pitts
Guest
Posts: n/a
 
      06-07-2008
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/>
 
Reply With Quote
 
 
 
 
sumsin
Guest
Posts: n/a
 
      06-07-2008
On Jun 7, 6:48 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
> 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.
 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      06-07-2008
sumsin wrote:
> On Jun 7, 6:48 am, Daniel Pitts
> <newsgroup.spamfil...@virtualinfinity.net> wrote:
>> 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/>
 
Reply With Quote
 
sumsin
Guest
Posts: n/a
 
      06-07-2008
On Jun 7, 11:00 am, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
> sumsin wrote:
> > On Jun 7, 6:48 am, Daniel Pitts
> > <newsgroup.spamfil...@virtualinfinity.net> wrote:
> >> 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.
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      06-07-2008
Daniel Pitts wrote:

> sumsin wrote:
>> On Jun 7, 6:48 am, Daniel Pitts
>> <newsgroup.spamfil...@virtualinfinity.net> wrote:
>>> 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.

 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      06-07-2008
On Jun 7, 7:10*am, sumsin <sumsin...@gmail.com> wrote:
> On Jun 7, 11:00 am, Daniel Pitts
>
>
>
>
>
> <newsgroup.spamfil...@virtualinfinity.net> wrote:
> > sumsin wrote:
> > > On Jun 7, 6:48 am, Daniel Pitts
> > > <newsgroup.spamfil...@virtualinfinity.net> wrote:
> > >> 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 */
}
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      06-08-2008
Rolf Magnus wrote:
> Daniel Pitts wrote:
>
>> sumsin wrote:
>>> On Jun 7, 6:48 am, Daniel Pitts
>>> <newsgroup.spamfil...@virtualinfinity.net> wrote:
>>>> 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::
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      06-08-2008
red floyd wrote:

> Rolf Magnus wrote:
>> Daniel Pitts wrote:
>>
>>> sumsin wrote:
>>>> On Jun 7, 6:48 am, Daniel Pitts
>>>> <newsgroup.spamfil...@virtualinfinity.net> wrote:
>>>>> 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.

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      06-08-2008
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.net> wrote:
>>>>>> 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?
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      06-08-2008
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 T> valarray<T> abs (const valarray<T>&);

The rest are just overloads.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
xServices::CServices<TImp>::StHoldClientList::StHoldClientList(std::set<TImp*, std::less<TImp*>, std::allocator<TImp*> >&)': Vinu C++ 4 07-07-2005 06:08 AM
std::map<int,std::set<std::string> > Wrong? (Segmentation fault.) Peter Jansson C++ 5 03-17-2005 06:34 AM
function overload (not operator overload) Ying-Chieh Liao Perl Misc 3 10-11-2004 11:24 AM
How use the overload of>> (or<<) of a class in the overload of << and >> of another class? Piotre Ugrumov C++ 3 01-25-2004 08:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57