Prevent unnecessary copies of C++ functor objects

后端 未结 5 1145
野的像风
野的像风 2020-12-09 10:39

I have a class which accumulates information about a set of objects, and can act as either a functor or an output iterator. This allows me to do things like:



        
5条回答
  •  半阙折子戏
    2020-12-09 10:59

    Just a quick note, for_each, accumulate, transform (2nd form), provide no order guarantee when traversing the provided range.

    This makes sense for implementers to provide mulit-threaded/concurrent versions of these functions.

    Hence it is reasonable that the algorithm be able to provide an equivalent instance (a new copy) of the functor passed in.

    Be wary when making stateful functors.

提交回复
热议问题