Is it okay to “Move” an object from a queue, if you're about to pop from it?

前端 未结 4 1510
耶瑟儿~
耶瑟儿~ 2021-01-01 11:15

I\'ve been working on a parser for commands (which are fancy wrappers around large arrays of data), and have a queue that unhandled commands reside on. If I nee

4条回答
  •  庸人自扰
    2021-01-01 11:53

    It depends on what the move constructor for your type does. If it leaves the original object in a state that can safely be destroyed, then all is well. If not, then you may be in trouble. Note that the comments about preconditions and valid states are about constraints on types defined in the standard library. Types that you define do not have those constraints, except to the extent that they use types from the standard library. So look at your move constructor to sort out what you can and can't do with a moved-from object.

提交回复
热议问题