From: marc.glisse@gmail.com   
      
    wrote:   
      
   > #include    
   > #include    
   > #include    
   > #include    
   > #include    
   >   
   > namespace ns {   
   > template, class   
   > Allocator = std::allocator >   
   > class myContainer {   
   > public:   
   > class iterator_implementation {   
   > public:   
   > inline iterator_implementation() {   
   > }   
   > };   
   > public:   
   > typedef iterator_implementation iterator;   
   > };   
   > template    
   > inline void swap(typename myContainer Allocator>::iterator& x,   
   > typename myContainer Allocator>::iterator& y) {   
      
   This is non-deducible. The compiler can't randomly try all Key,   
   Compare and Allocator, hoping to find one such that myContainer has a   
   suitable iterator typedef in it. One common solution is to   
   declare/define your iterator outside the class.   
      
   > std::cout << "**** specialized iterator swap ****" << std::endl;   
   > }   
   > }   
   >   
   > int main(int argc, char* argv[]) {   
   > ns::myContainer::iterator x =   
   ns::myContainer::iterator();   
   > ns::myContainer::iterator y =   
   ns::myContainer::iterator();   
   > using std::swap;   
      
   Removing this using declaration will let the compiler tell you why it   
   can't use your swap function.   
      
   > std::cout << "before swap(x, y)" << std::endl;   
   > swap(x, y);   
   > std::cout << "after swap(x, y)" << std::endl;   
   > std::cout << std::endl;   
   > std::cout << "before swap, std::allocator   
   >>(x, y)" << std::endl;   
   > swap, std::allocator >(x, y);   
   > std::cout << "after swap, std::allocator   
   >>(x, y)" << std::endl;   
   > exit(0);   
   > }   
   >   
   [...]   
   > In this case is there a standard way to define a specialize swap for   
   > iterator short of making the iterator_implementation class its own   
   > stand-alone class rather than a nested class?   
      
   Move swap inside myContainer, or even inside the iterator, as a friend   
   function, for instance.   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|