When will a C++11 compiler make RVO and NRVO outperform move semantics and const reference binding?

后端 未结 3 1939
轮回少年
轮回少年 2020-12-30 04:20

Consider the case when \"whole\" objects with move semantics enabled are returned from functions, as with std::basic_string<>:

std::wstrin         


        
3条回答
  •  情歌与酒
    2020-12-30 04:28

    What scheme is there to make a deterministic choice of these options, if any?

    There isn't one, and there never will be.

    Compilers are not required to do optimizations of any kind. The only thing you can do for certain is compile some code and see what comes out the other end.

    The most you will eventually get is a general heuristic, a community consensus where people say, "for most compilers, X seems to work fastest." But that's about it. And that will take years as compilers get up to speed with C++0x and implementations mature.

提交回复
热议问题