From: normvcr@telus.net   
      
   Using gcc 4.8.2 on fedora 19, I got a compilation error:   
      
   26:15: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka   
   std::basic_ostream}’ and ‘’)   
    std::cout << Max<1>::Compare<13>::Compare<5>::Value << std::endl;   
      
   To understand the error, I simplified the code:   
      
      
    template< long RHS >   
    using Y = typename Max<1>::Compare<13>::Compare;   
      
   int main()   
   {   
    std::cout << Y<5>::Value << std::endl;   
   }   
      
      
   and this gives the correct answer of 13. There was an   
   intermediate analysis step, where the compiler explained   
   that Max<1>::Compare<13>::Compare refers to the constructor,   
   and not to the type.   
      
      
      
   On 11/07/2013 09:59 AM, puverle@googlemail.com wrote:   
   > Hi,   
   >   
   > I came across an issue which I was able to distil to a smaller example   
   > which seems to exhibit similar behaviour.   
   > The following snippet of code doesn't do what I'd expect:   
   >   
   >   
   > #include    
   > #include    
   >   
   > template   
   > struct Compare_   
   > {   
   > enum { Value = (Lhs_ >= Rhs_) ? Lhs_ : Rhs_ };   
   >   
   > template   
   > struct Compare: Compare_ {};   
   > };   
   >   
   > //#1   
   > //template   
   > //struct Compare_   
   > //{   
   > //};   
   >   
   >   
   > template   
   > struct Max: Compare_   
   > {};   
   >   
   > int main()   
   > {   
   > std::cout << Max<1>::Compare<13>::Compare<5>::Value << std::endl;   
   > }   
   >   
   >   
   > In the example, I was expecting to compute the maximum of 1, 13 and 5.   
   > The program compiles, however, it doesn't work (I outputs 5).   
   > I tested this both on g++ 4.7 and clang 3.3, getting the same result.   
   >   
   > For additional insight, if I uncomment the specialization in #1, I get   
   > errors complaining that   
   >   
   > "Compare<-1, 1>::Compare<5>"   
   >   
   > doesn't have an inner member Value (as expected) - i.e. it seems the   
   > Compare<13> class is getting dropped somehow.   
   >   
   > Why doesn't this work? C++ standard references appreciated.   
   >   
   > (Please note: I am not looking for a correct/better implementation of   
   > the above, so just posting one that works doesn't help. I am trying to   
   > understand the issue above. Apologies in advance if it's something   
   > trivial/embarrassing!)   
   >   
   > Thanks,   
   >   
   > Tom   
   >   
   >   
      
      
   --   
    [ 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)   
|