Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #719

Is removing necessity of std::move for local variables used for the last time a good proposal?

X-Received by 10.50.51.68 with SMTP id i4mr12368igo.5.1401482405532; Fri, 30 May 2014 13:40:05 -0700 (PDT)
MIME-Version 1.0
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!hl10no7982293igb.0!news-out.google.com!qf4ni18955igc.0!nntp.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Fri, 30 May 2014 15:40:05 -0500
Return-Path <cppmods@glengoyne.dreamhost.com>
Sender std-cpp-request@vandevoorde.com
Approved james.dennett@gmail.com
Message-ID <874c0712-4aed-4a8f-991e-b064daa5000f@googlegroups.com> (permalink)
Newsgroups comp.std.c++
From Piotr Nycz <piotrwn1@googlemail.com>
Subject Is removing necessity of std::move for local variables used for the last time a good proposal?
Organization unknown
X-Original-Date Thu, 29 May 2014 05:21:21 -0700 (PDT)
X-Submission-Address std-cpp-submit@vandevoorde.com
To undisclosed-recipients:;
Date Fri, 30 May 2014 15:32:56 CST
Lines 48
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-xRjBatiQCZHncfbPPOdBiw9MOlr/71aAAp65DVvM8GAxjjWC7jFGDuYSNQxaYr2agCaTH5tzOjzUiWI!jJxLECyc162MzZFZQiPOj93t2ESAGCcSyY2JuOkG6ZoWNi20V6Vqjt1VwmF5hi0qFDFMLoBHCL/R!Sf6RU5crviA=
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2825
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.std.c++:719

Show key headers only | View raw


Hello,

During discussion on SO
(http://stackoverflow.com/questions/23929800/is-stdmove-really-needed-on-initialization-list-of-constructor-for-heavy-membe)
I came to conclusion that necessity of using std::move for arguments
passed by value or local variables can be somehow relaxed for a
specific case where they are used for the last time - so its lifetime
is practically expired.

Some examples:

struct President {
  std::string name;
  President(std::string p_name)
    : name(std::move(p_name))
      //   ^^^^^^^^^:  MOVE or NOT TO MOVE?
  {}
  void setDefaultName()
  {
      std::string l_name = "XYZ";
      name = std::move(l_name);
      //     ^^^^^^^^^:  MOVE or NOT TO MOVE?
  }
};

So, do you think is it a good idea to add a rule to C++ language that:

If the automatic variable is used as a source for copying and this is
the last time variable is used - then move is used instead of copy.

If the above rule would be added to language - then to my best
understanding - there would be no need to use std::move in my example.

My motivation is simple: there are plenty of C++03 where std::move was
not used. So, according to C++11 rules we shall add almost everywhere
this std::move?

BR,
Piotr


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextNext in thread | Find similar


Thread

Is removing necessity of std::move for local variables used for the  last time a good proposal? Piotr Nycz <piotrwn1@googlemail.com> - 2014-05-30 15:32 -0600
  Re: Is removing necessity of std::move for local variables used for  the  last time a good proposal? SG <s.gesemann@googlemail.com> - 2014-06-05 12:31 -0600
    Re: Is removing necessity of std::move for local variables used for  the  last time a good proposal? Kalle Olavi Niemitalo <kon@iki.fi> - 2014-06-07 01:25 -0600
    Re: Is removing necessity of std::move for local variables used for   the  last time a good proposal? Piotr Nycz <piotrwn1@googlemail.com> - 2014-06-07 02:33 -0600
      Re: Is removing necessity of std::move for local variables used for   the  last time a good proposal? Daniel Krügler <daniel.kruegler@googlemail.com> - 2014-06-08 01:32 -0600
        Re: Is removing necessity of std::move for local variables used for    the  last time a good proposal? Piotr Nycz <piotrwn1@googlemail.com> - 2014-06-17 07:25 -0600

csiph-web