Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

c++ - Which std types are guaranteed to be empty/null after being used as arg in move constructor

I know shared_ptr, unique_ptr, weak_ptr are guaranteed to be empty after used as RVR argument in the constructor of the same type, but I wonder does standard specifies this for some other std:: types beside the ones I mentioned.

Please note that I know that elements after move are left in valid but unspecified state, I am here interested for which types state is specified.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Types leaving moved-from objects in "empty" state are smart pointers, locks ([thread.lock.unique.cons]/21, [thread.lock.shared.cons]/21), file streams ([filebuf.cons]/(4.2)), futures ([futures.unique_future]/(8.2), [futures.shared_future]/10), promises ([futures.promise]/6), packaged tasks ([futures.task]/7), threads ([thread.thread.constr]/10), …

By contrast, templates leaving the moved-from objects with unspecified values are function ([func.wrap.func.con]/6), basic_regex ([re.regex.construct]/13), basic_string ([string.cons]/2), containers…


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...