Copy elision for pass-by-value arguments

前端 未结 4 784
渐次进展
渐次进展 2020-12-17 09:09

Given

struct Range{
    Range(double from, double to) : from(from), to(to) {}
    double from;
    double to;
};

struct Box{
    Box(Range x, Range y) : x(x         


        
4条回答
  •  庸人自扰
    2020-12-17 09:45

    The fact that it can, doesn't mean it most certainly will. See it in this Demo, it's obvious you are creating two copies. Hint, the output contains twice :

    copy made

    copy made

提交回复
热议问题