eliminate unnecessary copies when calling C++/STL algorithms

前端 未结 2 1276
悲哀的现实
悲哀的现实 2021-02-10 05:12
  • I\'ve coded the following example in order to better illustrate my questions.

  • In the code below, I introduce a function object (i.e., funObj

2条回答
  •  一生所求
    2021-02-10 05:38

    The move semantics introduced in C++11 exist to largely alleviate this set of 'unnecessary' copies. If you define a move constructor for your function-objects the STL will move the function-object (even/especially if it is a temporary) which will prevent the copy from occurring. This will allow you to use the STL algorithms with value-semantics without sacrificing too much in the way of performance. It will also allow you to use temporary function-objects as desired.

提交回复
热议问题