public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* c++0x and rvalue references on gcc 4.6.1
@ 2011-09-09 13:23 leon zadorin
  2011-09-09 13:36 ` Kevin P. Fleming
  0 siblings, 1 reply; 7+ messages in thread
From: leon zadorin @ 2011-09-09 13:23 UTC (permalink / raw)
  To: gcc-help

Hi everyone.

Just started looking-into/reading-on c++0x rvalue refs and would like
clarification on the following code being compiled by gcc v 4.6.1 (on
freebsd 8.2 release, amd64):

#include <iostream>
struct init {};
struct x {
  template <typename InitPolicy>
  void
  init_from(InitPolicy const & x)
  {
    ::std::cout << "by ref\n";
  }
  template <typename InitPolicy>
  void
  init_from(InitPolicy && x)
  {
    ::std::cout << "by rvalue ref possibly stealing resources held by x\n";
  }
};

int
main()
{
  x x1;
  init i;
  x1.init_from(i);
  return 0;
}

compiled with:
c++ -std=c++0x main.cc
produces:
"by rvalue ref possibly stealing resources held by x"

From various experiments, the above 'x1.init_from(i)' binds as
'x1.init_from<init&>(i)' [as opposed to 'x1.init_from<init>(i)]... but
even if so -- I was wondering how does this correlate with the
following quote from wiki on c++11:
http://en.wikipedia.org/wiki/C%2B%2B0x#Rvalue_references_and_move_constructors
"... A named variable will never be considered to be an rvalue even if
it's declared as such; in order to get an rvalue, the function
template std::move<T>() should be used ..."

I am most likely missing something simple here (just starting to read
no rval refs...)

Best regards
Leon Zadorin.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-09-09 22:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-09 13:23 c++0x and rvalue references on gcc 4.6.1 leon zadorin
2011-09-09 13:36 ` Kevin P. Fleming
2011-09-09 14:29   ` leon zadorin
2011-09-09 14:54     ` leon zadorin
2011-09-09 15:01       ` leon zadorin
2011-09-09 16:35     ` Jonathan Wakely
2011-09-09 22:42       ` leon zadorin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).