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 33,257 of 33,346   
   Seungbeom Kim to peter koch larsen   
   Re: How to differentiate template classe   
   14 Nov 13 11:40:08   
   
   From: musiphil@bawi.org   
      
   On 2013-11-13 10:47, peter koch larsen wrote:   
   > Hi group,   
   >   
   > I hope this text looks okay. Unfortunately, I am currently   
   > forced to use google groups.   
      
   Your text looks very good; thanks for taking the care.   
      
   > I have a question regarding differentiating templated classes.   
   > Assume I have (the real code is more complex):   
   >   
   > template< .... > class my_template;   
   > typedef my_template lat_long;   
   > typedef my_template complex;   
   >   
   > I still have only one type, so I could input a complex to   
   > a function expecting a complex - reducing typesafety.   
   > What is perhaps worse, I can't overload on the two types.   
   > std::ostream operator<< must be the same for both types.   
      
   One solution would be to use differentiating tag types.   
      
   template<..., typename tag = void> class my_template;   
      
   struct lat_long_tag { };   
   typedef my_template lat_long;   
   struct complex_tag { };   
   typedef my_template complex;   
      
   The tag type is never used in the definition of my_template, but   
   different tags still serve to differentiate the resulting types.   
      
   --   
   Seungbeom Kim   
      
      
         [ 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