Overloading std::move vs Overloading std::forward for perfect forwarding.

53 views
Skip to first unread message

Aakash Mishra

unread,
Apr 13, 2023, 6:35:22 PM4/13/23
to Discussion forum for Programming in Modern C++
Hi, I have a question from " Live Interactive Session : 3 " on 13/04/23 and Prof. Partha Pratim Das asked me to Post this in Discussion forum and remind TA's to get it answered from him properly using codes.

While deciding code semantics for move operation in Module 50, we face challenge of deciding  parameter type for std::move (M50.19)

1.PNG

One solution to this is overloading std::move giving two definitions one for moving lvalue and one for moving rvalue argument. But still perfect forwarding problem remains !! M(50.20)
2.PNG

Later in  Module 51 we see for Perfect forwarding by a template function we use std::forward component which checks reference type from template deduction and forwards arguments to their corresponding parameters correctly. Resolves the problem ! M(51.14)
3.PNG

BUT std::forward C++ implementation is itself overloaded for lvalue reference and for rvalue reference.( M51.27 )
So how is overloading std::forward for set of n arguments cheaper than overloading std::move while perfect forwarding? 

Arup Kumar Chattopadhyay

unread,
Apr 15, 2023, 12:55:28 AM4/15/23
to Discussion forum for Programming in Modern C++, Aakash Mishra
Forwarded. 

Aakash Mishra

unread,
May 2, 2023, 12:57:01 PM5/2/23
to Discussion forum for Programming in Modern C++, Arup Kumar Chattopadhyay, Aakash Mishra
Sir are there any updates on solution ?
Reply all
Reply to author
Forward
0 new messages