The following code works on my computer, but is this guaranteed to work by the C++ standard?
void do_stuff(std::string);
std::string s;
while(std::cin >> s){
do_stuff(std::move(s));
}
From my understanding of the standard, objects that are moved from are left in a valid but unspecified state, and are only worthy of destruction. Hence, the code isn't guaranteed to work.
As an extension, is the following valid, given the knowledge of the Notification
class and the fact that get_notification
overwrites the member details
?
struct Notification{
string details;
};
string get_string();
void do_more_stuff(Notification);
void get_notification(Notification& n){
n.details = get_string();
}
Notification n;
while(get_notification(n)){
do_more_stuff(std::move(n));
}