Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > specializing std::less

Reply
Thread Tools

specializing std::less

 
 
Exits Funnel
Guest
Posts: n/a
 
      01-12-2005
I've got this code:

//Begin foo.cpp
#include <utility>
#include <bits/stl_function.h>

typedef std:air<int, int> int_pair_t;

template<>
struct std::less<int_pair_t> { };
//End foo.cpp

g++ has this to say on the issue:

foo.cpp:7: specializing `struct std::less<int_pair_t>' in different
namespace
/usr/include/c++/3.2.3/bits/stl_function.h:195: from definition of `
template<class _Tp> struct std::less'

This seems reasonable (though for what it's worth, it compiles under
VC7.1). I can fix the problem by wrapping the specialization in a
'namespace std' block but I'm wondering if this is prudent or is there
some other solution. Thanks.

-exits

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-12-2005
"Exits Funnel" <(E-Mail Removed)> wrote...
> [...] I can fix the problem by wrapping the specialization in a
> 'namespace std' block but I'm wondering if this is prudent or is there
> some other solution. Thanks.


It's expressly allowed by the Standard.

Victor


 
Reply With Quote
 
 
 
 
Sharad Kala
Guest
Posts: n/a
 
      01-12-2005

"Exits Funnel" <(E-Mail Removed)> wrote in message
> I've got this code:
>

[snip]

> This seems reasonable (though for what it's worth, it compiles under
> VC7.1). I can fix the problem by wrapping the specialization in a
> 'namespace std' block but I'm wondering if this is prudent or is there
> some other solution. Thanks.


That's fine (Read 17.4.3.1/1)

Sharad




 
Reply With Quote
 
Dietmar Kuehl
Guest
Posts: n/a
 
      01-12-2005

Victor Bazarov wrote:
> "Exits Funnel" <(E-Mail Removed)> wrote...
> > [...] I can fix the problem by wrapping the specialization in a
> > 'namespace std' block but I'm wondering if this is prudent or is

there
> > some other solution. Thanks.

>
> It's expressly allowed by the Standard.


It is allowed to [partially] specialize class templates from the
standard library in namespace 'std' *IF* the specialization involves
a user defined type. 'std:air<int, int>' as used in the original
article does not qualify for a user defined specialization!

That said, it is probably save to specialize things which don't exist
according to the standard - only there is no guarantee that it indeed
works...
--
<(E-Mail Removed)> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>

 
Reply With Quote
 
Sharad Kala
Guest
Posts: n/a
 
      01-12-2005

"Dietmar Kuehl" <(E-Mail Removed)> wrote in message

>
> Victor Bazarov wrote:
> > "Exits Funnel" <(E-Mail Removed)> wrote...
> > > [...] I can fix the problem by wrapping the specialization in a
> > > 'namespace std' block but I'm wondering if this is prudent or is

> there
> > > some other solution. Thanks.

> >
> > It's expressly allowed by the Standard.

>
> It is allowed to [partially] specialize class templates from the
> standard library in namespace 'std' *IF* the specialization involves
> a user defined type. 'std:air<int, int>' as used in the original
> article does not qualify for a user defined specialization!


True, but this is a well known work around that works on all the modern
compilers I have tested it on. But as you say it is not legal as quoted in
the Standard. Is there a proposal to change it (for std:air) ?

Sharad


 
Reply With Quote
 
Exits Funnel
Guest
Posts: n/a
 
      01-12-2005
Sharad Kala wrote:
> "Dietmar Kuehl" <(E-Mail Removed)> wrote in message
>
>
>>Victor Bazarov wrote:
>>
>>>"Exits Funnel" <(E-Mail Removed)> wrote...
>>>
>>>>[...] I can fix the problem by wrapping the specialization in a
>>>>'namespace std' block but I'm wondering if this is prudent or is

>>
>>there
>>
>>>>some other solution. Thanks.
>>>
>>>It's expressly allowed by the Standard.

>>
>>It is allowed to [partially] specialize class templates from the
>>standard library in namespace 'std' *IF* the specialization involves
>>a user defined type. 'std:air<int, int>' as used in the original
>>article does not qualify for a user defined specialization!

>
>
> True, but this is a well known work around that works on all the modern
> compilers I have tested it on. But as you say it is not legal as quoted in
> the Standard. Is there a proposal to change it (for std:air) ?
>
> Sharad
>
>


Thanks Victor, Sharad, Dietmar. I appreciate the information.

-exits

 
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
Specializing Member Function Template of Class Template? Simon G Best C++ 2 12-29-2006 12:32 PM
Specializing on a templated type Alex Drummond C++ 2 09-03-2005 03:13 PM
Specializing Subclassed Methods cppaddict C++ 1 06-03-2004 07:13 AM
Trouble specializing a member function in a template class Jeff C++ 2 11-20-2003 04:39 AM
Specializing in security!!!! Nicolau4@aol.com MCSE 22 11-04-2003 04:11 PM



Advertisments