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,223 of 33,346   
   Daryle Walker to Daryle Walker   
   Re: Is using a braced-list as a function   
   30 Sep 13 00:15:09   
   
   From: darylew@googlemail.com   
      
   On Sunday, September 29, 2013 10:00:05 PM UTC-4, Daryle Walker wrote:   
   > Code like:   
   >   
   >      template < unsigned N >   
   >      class MyClass   
   >      {   
   >      public:   
   >          //...   
   >          template < typename ...Args > bool MyFunc( Args &&...args );   
   >          bool MyFunc( std::array &a );   
   >          //...   
   >      };   
   >   
   > I can make calls like "MyFunc(a, b, c)" just fine.  But when I   
   > try "MyFunc({d, e, f})" to trigger the std::array overload, I get   
   > complaints on no candidate being found; that initializer-list (the   
   > internal compiler concept, not necessarily std::initializer_list)   
   > couldn't convert to anything appropriate.   
   >   
   > I know that you can use a std::initializer_list as a function   
   > parameter and it'll work, but can you use any type that can use a   
   > braced-list (assuming the right parameter type)?   
      
   Found the answer while wandering around StackOverflow.   
      
   The class definition is fine.  But when calling the code, I have to use   
   std::array's proper double braces to work.  I guess sloppy brace placement   
   won't work; any such foolishness will match std::initializer_list first.   
      
   Daryle W.   
      
      
   --   
         [ 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