Is it possible to ensure copy elision?

前端 未结 3 1975
别跟我提以往
别跟我提以往 2021-01-18 03:58

Copy elision is a neat optimization technique and in some cases relying on copy elision can actually be faster than passing around references \"by hand\".

So, let\'s

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 05:03

    In C++1z (expected 2017), some cases will be required to guarantee copy elision:

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html

    Per the communal cppreference.com compiler feature support wiki GCC 7+ and Clang 4+ ensure this.

    The optimization side of this fortunately should not require enabling newer language support, since it's a pure optimization (following older language standard allowances).

    Also allowing the copy constructor to be unavailable when the optimization applies probably will require the newer language standard to be enabled during compilation, or use of a loose or extended mode that doesn't demand strict conformance (e.g. potentially GCC's -fpermissive).

提交回复
热议问题