SlideShare uma empresa Scribd logo
1 de 8
Baixar para ler offline
Where	to	type	std::move?
Andrey	Upadyshev
Licensed	under	a	CC	BY-SA	4.0	License.	 Version	2016-04-26-1
The	Problem
void foo(Object && object)
{
// Should we apply std::move
// to the object member?
consume( std::move(object.member) );
// or to the object itself?
consume( std::move(object).member );
}
Note	that	it’s	all	related	to	std::forward as	well.
What	the	heck,	is	there	a	difference?
It	is.	Sometimes.
std::move(object.member)
• Means:	cast	a	result	of	the	object	member	access	to	a	[cv-qualified] rvalue.
• The	result	is	always an	rvalue.
std::move(object).member
• Means:	cast	the	object	to	a	[cv-qualified] rvalue then	access	its	member.
• If	member	is	neither	a	static	member	nor	a	reference	the	result	is	an	rvalue.
• Otherwise the	result	is	lvalue.
Why	should	I	care?
std::move(object.member) can	accidentally	move	from	a	shared	
object	if	applied	to	a	reference	or	a	static	member:
class Object {
Member& member;
…
};
...
std::move(object.member)
std::move(object).member never	does	so.
Think	about	generic	code	or	changing	a	member	type	as	a	result	of	
refactoring.
Generic	code	example
Somewhere	in	the	heart	of	the	generic	code:
consume(std::move(std::get<i>(tuple))...);
No	idea,	what’s	in	the	tuple.	It	can	be	a	value	or	a	reference.	When	
accidental	move	from	a	shared	object	is	happened	it	will	be	a	disaster.
This	approach	is	safe	(or	at	least	safer):
consume(std::get<i>(std::move(tuple))...);
Sometimes	it	may	be	really	different
Slice	from	a	tuple.	Member	that	are	rvalues are	moved:
auto tuple = hana::make_tuple("abc"s, "def"s,
"ghi"s, "jkl"s);
consume(hana::slice_c<0, 2>(std::move(tuple)));
consume(hana::slice_c<2, 4>(std::move(tuple)));
Applying	std::move at	the	last	step	is	useless,	members	are	already	copied	inside	
slice:
consume(std::move(hana::slice_c<0, 2>(tuple))); // copy
Another	example	where	behavior	may	differ	is	ref-qualified	methods.
Where	to	type	what?
• std::move(object.member) to	unconditionally	move	from	a	
member.
• std::move(object).member to	tell	that	the	object	is	actually	an	
rvalue then	only	the	safe	things	can	happen	J
Links
1. Andrey	Upadyshev,	What's	the	difference	between	std::move(object.member)	and	
std::move(object).member?
http://oliora.github.io/2016/02/12/where-to-put-std-move.html
2. Louis	Dionne,	A	tentative	notion	of	move-independence
http://ldionne.com/2016/02/17/a-tentative-notion-of-move-independence/
3. Reddit thread
https://www.reddit.com/r/cpp/comments/45w3fs/whats_the_difference_between_stdmoveo
bjectmember/
4. The	C++	Standard:	Class	Member	Access [expr.ref-4]
http://eel.is/c++draft/expr.ref#4

Mais conteúdo relacionado

Mais procurados

Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dartImran Qasim
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++Ilio Catallo
 
Lecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming LanguageLecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming LanguageSURAJ KUMAR
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 
Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画mametter
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayAlexis Gallagher
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3mametter
 
Optionals by Matt Faluotico
Optionals by Matt FaluoticoOptionals by Matt Faluotico
Optionals by Matt FaluoticoWithTheBest
 
(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-stringsNico Ludwig
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overviewJulian Król
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringSri Harsha Pamu
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course yoavrubin
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersRichard Thomson
 
Web application architecture
Web application architectureWeb application architecture
Web application architectureIlio Catallo
 
C++ to java
C++ to javaC++ to java
C++ to javaAjmal Ak
 
Exception Handling1
Exception Handling1Exception Handling1
Exception Handling1guest739536
 

Mais procurados (20)

Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dart
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
 
Lecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming LanguageLecture 2 keyword of C Programming Language
Lecture 2 keyword of C Programming Language
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
 
Template classes and ROS messages
Template classes and ROS messagesTemplate classes and ROS messages
Template classes and ROS messages
 
Optionals by Matt Faluotico
Optionals by Matt FaluoticoOptionals by Matt Faluotico
Optionals by Matt Faluotico
 
(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings(4) cpp automatic arrays_pointers_c-strings
(4) cpp automatic arrays_pointers_c-strings
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overview
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmers
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
 
C++ to java
C++ to javaC++ to java
C++ to java
 
Start with swift
Start with swiftStart with swift
Start with swift
 
Exception Handling1
Exception Handling1Exception Handling1
Exception Handling1
 

Semelhante a Where to type_std_move?

OOPs_Lecture 09_Argument Passing, static members.pptx
OOPs_Lecture 09_Argument Passing, static members.pptxOOPs_Lecture 09_Argument Passing, static members.pptx
OOPs_Lecture 09_Argument Passing, static members.pptxNAYEEMBASHA12
 
Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptxAbhishekkumarsingh630054
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxDrYogeshDeshmukh1
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics PresentationOmid Sohrabi
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesDigitalDsms
 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfArpana Awasthi
 
Pooja Sharma , BCA Third Year
Pooja Sharma , BCA Third YearPooja Sharma , BCA Third Year
Pooja Sharma , BCA Third YearDezyneecole
 
Liberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User GroupLiberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User GroupGaylord Mazelier
 
C Sharp Jn (5)
C Sharp Jn (5)C Sharp Jn (5)
C Sharp Jn (5)jahanullah
 
C Sharp Jn (5)
C Sharp Jn (5)C Sharp Jn (5)
C Sharp Jn (5)jahanullah
 
Generic Objects - Bill Wei - ManageIQ Design Summit 2016
Generic Objects - Bill Wei - ManageIQ Design Summit 2016Generic Objects - Bill Wei - ManageIQ Design Summit 2016
Generic Objects - Bill Wei - ManageIQ Design Summit 2016ManageIQ
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programmingshinyduela
 

Semelhante a Where to type_std_move? (20)

OOPs_Lecture 09_Argument Passing, static members.pptx
OOPs_Lecture 09_Argument Passing, static members.pptxOOPs_Lecture 09_Argument Passing, static members.pptx
OOPs_Lecture 09_Argument Passing, static members.pptx
 
Sep 15
Sep 15Sep 15
Sep 15
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
Sep 15
Sep 15Sep 15
Sep 15
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics Presentation
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book Notes
 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdf
 
Pooja Sharma , BCA Third Year
Pooja Sharma , BCA Third YearPooja Sharma , BCA Third Year
Pooja Sharma , BCA Third Year
 
Liberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User GroupLiberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User Group
 
C Sharp Jn (5)
C Sharp Jn (5)C Sharp Jn (5)
C Sharp Jn (5)
 
C Sharp Jn (5)
C Sharp Jn (5)C Sharp Jn (5)
C Sharp Jn (5)
 
Classes2
Classes2Classes2
Classes2
 
Static Members-Java.pptx
Static Members-Java.pptxStatic Members-Java.pptx
Static Members-Java.pptx
 
Generic Objects - Bill Wei - ManageIQ Design Summit 2016
Generic Objects - Bill Wei - ManageIQ Design Summit 2016Generic Objects - Bill Wei - ManageIQ Design Summit 2016
Generic Objects - Bill Wei - ManageIQ Design Summit 2016
 
WPF Concepts
WPF ConceptsWPF Concepts
WPF Concepts
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 

Último

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 

Último (20)

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 

Where to type_std_move?