Understanding the benefits of move semantics vs template metaprogramming

后端 未结 5 757
孤独总比滥情好
孤独总比滥情好 2020-12-13 10:58

I\'ve read some descriptions about move semantics in C++11 and I wonder in what context it could be used. Currently, many C++ math libraries use template metaprogramming to

5条回答
  •  一生所求
    2020-12-13 11:03

    They are two different beasts. Move semantics is about appropriating resources from a value that is going to be destroyed. When mixed with expression templates of say big ints (which need dynamic memory allocation), one would simply appropriate of such memory instead of making a copy of something that is about to be destroyed.

    Move semantics are also important for objects that are inherently not copyable (like fstreams) but makes sense to make moveable.

提交回复
热议问题