home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,378 of 33,346   
   Ulrich Eckhardt to All   
   Re: template member function specialisat   
   28 Jun 11 17:12:03   
   
   From: ulrich.eckhardt@dominolaser.com   
      
   cpp4ever wrote:   
   > With regard to your own container template class, if a template class of   
   > a type, (class SomeObject), requires a lot of it's member functions   
   > specialised, (>60% perhaps), then surely it would be better to implement   
   > a template class specialisation.   
      
   I disagree, if you need to specialize large parts of a class in order to use   
   it with your type, then maybe you shouldn't use it. If for example you took   
   a vector and hacked it via specializations to allow auto_ptr   
   as type, then the vector wouldn't be a vector anymore. In particular, it   
   rather obfuscates to the casual reader that this vector behaves very   
   differently from the one they already know.   
      
      
   > I'm thinking it would be a better idea to define those class template   
   > member functions that often need specialisation as virtual, (as well as   
   > the destructor), and then achieve the same result via inheritance and   
   > overriding.   
      
   I don't want to pay the price for that overhead when you're talking about   
   containers. I haven't found the need to override anything there. Concerning   
   a container that allows auto_ptr, this can easily be done using   
   aggregation instead of overriding or specialization. For this example, the   
   aggregated vector is a vector while the wrapping code converts   
   the various function calls. Using e.g. Boost.Iterator you can even get the   
   STL iterator interface working with little effort.   
      
      
   > In this case should the template class itself inherit a well   
   > defined interface, (pure virtual base class)? This approach does appear   
   > to be easier to implement/understand/extend than using class template   
   > member function specialisations.   
   >   
   > Thanks Daniel for your response, and like yourself I have never seen   
   > this done for production code. This certainly suggests that although the   
   > idea is possible, it is not a good solution for reasons I have given to   
   > a better alternative solution idea in the previous paragraph.   
      
   I'm seriously wondering what you are doing. In particular, what should this   
   push_back() specialisation that you mentioned do differently than the   
   default? What is it you're trying to achieve?   
      
      
   Cheers!   
      
   Uli   
      
   --   
   Domino Laser GmbH   
   Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932   
      
      
         [ 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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca