Boost logo

Boost :

From: Sean Perry (perry_at_[hidden])
Date: 2007-11-16 10:31:50


This compiles fine with the version 9 compiler. I think the code is legal
(haven't spent great deal of time confirming) because the too swap()'s are
should be available for overload resolution with std::swap winning.

A very simple simple fix is to change the call to swap to be qualified.
For example:

 void swap(foo& x)
 {
   std::swap(t,x.t);
 }

--
Sean Perry
Compiler Development
IBM Canada Lab
(905)-413-6031 (tie 313-6031), fax (905)-413-4839
                                                                           
             Joaquín Mª López                                              
             Muñoz                                                         
             <joaquin_at_[hidden]>                                           To 
             Sent by:                  boost_at_[hidden]               
             boost-bounces_at_lis                                          cc 
             ts.boost.org                                                  
                                                                   Subject 
                                       Re: [boost] [config][vacpp8.0]      
             11/16/07 07:10 AM         BOOST_FUNCTION_SCOPE_USING_DECLARAT 
                                       ION_BREAKS_ADL should be defined?   
                                                                           
             Please respond to                                             
             boost_at_lists.boost                                             
                   .org                                                    
                                                                           
                                                                           
John Maddock ha escrito:
> Hmmm, the interesting thing is, I'm having a hard time convincing myself
> that this code is legal, I'm cc'ing our friendly IBM compiler expert in
case
> he can shed light on this.
>
> Consider the code again:
>
> #include <algorithm>
>
> template<typename T>
> struct foo
> {
>  T t;
>  foo():t(0){}
>  void swap(foo& x)
>  {
>    using std::swap;
>    swap(t,x.t);
>  }
> };
>
> template<typename T>
> void swap(foo<T>& x,foo<T>& y)
> {
>   x.swap(y);
> }
>
> int main()
> {
>   foo<int> x,y;
>   x.swap(y);
> }
>
> In foo::swap the local declaration of the member function "swap" hides
any
> occurances of swap in the outer scope, and the using declaration behaves
"as
> if" std::swap were imported into the *enclosing namespace*, which would
> still be hidden... and yet I can't believe that this simple idiom isn't
> actually legal ! :-)  And indeed all the other compilers I tested do
compile
> this OK.
Ouch, didn't think about name hiding... this is why I love C++ :-/
Now I don't know either whether the code is legal or not. Anyway, if I
changed
foo::swap to foo::swop the code would be undoubtedly legal then, right?
Noel, would you please try the attached variation?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
(See attached file: fsudba2.cpp)
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk