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,883 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: return type of function or expressio   
   05 Feb 12 00:28:23   
   
   3eab1272   
   From: daniel.kruegler@googlemail.com   
      
   Am 04.02.2012 20:31, schrieb GH:   
   > Hi all, is there a way to statically reference the return type of a   
   > function or an expression? To make myself clear, take the iomanip   
   > std::setw for example. The standard explicitly leaves the return type   
   > of std::setw implementation dependent. Suppose I want to know and   
   > reference the type of std::setw(8) (e g create a variable of that   
   > type), is there anyway to reference that type without going to the   
   > headers and using the implementation dependent type such as std::_Setw   
   > in g++?   
      
   In C++11 you can use decltype to realize that:   
      
   #include    
      
   typedef decltype(std::setw(8)) setw_type;   
      
   or more generally:   
      
   #include    
   #include    
      
   typedef decltype(std::setw(std::declval())) setw_type;   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ 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