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,151 of 33,346    |
|    8604sprucemill@googlemail.com to All    |
|    Re: Order of template function overloads    |
|    27 Jul 13 23:40:36    |
   
   > In essence, what is important for the observed behaviour in your two example   
   > code snippets is that:   
   >   
   > 1) a template function and a template class (i.e. the particular   
   > specializations created by means of automatic instantiation from the   
   > respective function/class templates - a process driven by the compiler and   
   > resulting in generation of a class instance/object or a function definition)   
   > are instantiated at different locations with respect to the entity that   
   > enforced their instantiation:   
   > a) "C++ defines the POI for a reference to a nonclass specialization   
   > to be immediately AFTER the nearest namespace scope declaration or   
   > definition that contains that reference."   
   >   
   > b) "[T]he POI for a reference to a generated class instance is defined   
   > to be the point immediately BEFORE the nearest namespace scope   
   > declaration [or] definition that contains the reference   
   > to that instance.";   
   >   
   > Additionally, these also may play role in particular situations:   
   >   
   > 2) multiple POIs for the same instance in a translation unit may exist   
   > (incl. when specializations are deliberately created by the programmer   
   > through explicit instantiation directive or explicit specialization): "For   
   > class template instances, only the first POI in each translation unit is   
   > retained, and the subsequent ones are ignored (they are not really   
   > considered POIs). For nonclass instances, all POIs are retained." Here a   
   > problem arises: the retained POIs might not be equivalent to each other,   
   > which could result in an unexpected behaviour depending on which POI the   
   > compiler will choose for the actual instantiation;   
   >   
   > 3) different implementation strategies amongst compilers as concerned the   
   > location of a POI for the actual instantiation of noninline function   
   > templates - generally postponed to the end of the translation unit.   
      
   Thank you for the detailed and thorough explanation. If I understand it   
   correctly, there is no reliable way to overload functions in a namespace   
   that is not controlled by me:   
      
   // not_under_my_control.h   
   namespace not_under_my_control {   
   template
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca