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,869 of 33,346    |
|    =?windows-1252?Q?Daniel_Kr=FCgler?= to Daryle Walker    |
|    Re: Is there a way to determine the retu    |
|    30 Jan 12 01:47:40    |
      d1b2136b       From: daniel.kruegler@googlemail.com              On 2012-01-29 23:42, Daryle Walker wrote:       > Now I have a couple more thoughts on this.       >       > 1. If you use this recursive-call technique to get the return type within       the function,       > do you need to use "std::move" in the function for arguments that are       r-value references?              I don't know, what you mean with "do you need to use [..]", but it       surely makes a difference and I would suggest to do that for the       preparation of an expression with the wanted value category.              > 2. If a reference is returned, will "decltype" on the recursive call include       the reference marker,       > or just be the referenced type? I'm not sure which way I prefer it.        Including the marker would       > be consistent, but it wouldn't be useful (since references aren't       objects themselves). Any non-dangling       > reference that you could return would have to be based on a non-local       object, and then you could       > just return the expression that generates that reference. (Hmm, now       I wonder if you could return       > a local object as a r-value reference.) For manipulation purposes,       getting the referenced type       > would be more useful.              It depends on the expression and the way how you form the decltype       expression (e.g. with a surrounding pair of parentheses or not), but in       general an xvalue expression will result in an rvalue reference and an       lvalue expression will result in an lvalue reference. I suggest to       discuss more concrete examples. I don't understand what you mean with       "but it wouldn't be useful (since references aren't objects       themselves)", because references are generally stripped away when       interpreting expressions, see Clause 5 p5:              "If an expression initially has the type “reference to T” (8.3.2,       8.5.3), the type is adjusted to T prior to any further analysis. The       expression designates the object or function denoted by the reference,       and the expression is an lvalue or an xvalue, depending on the expression."              And yes, it is possible (albeit not recommended) to return an rvalue       reference of a variable with automatic storage duration.              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