Ask Your Question
3

What is a solution for being unable to move objects from initializer_list?

asked 2023-05-05 22:26:34 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-05 22:52:02 +0000

bukephalos gravatar image

One solution for being unable to move objects from initializerlist is to copy the objects instead. This can be done by iterating over the initializerlist and copying each object into a new container, such as a vector or list. Alternatively, if the objects in the initializerlist are move-only types, it may be necessary to modify the constructor of the class using the initializerlist to accept rvalue references, so that move operations can be performed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-05 22:26:34 +0000

Seen: 17 times

Last updated: May 05 '23