Skip to content

C++: FP in cpp/large-parameter with overloaded binary oeprators #1269

@rdmarsh2

Description

@rdmarsh2

In C++, one pattern for implementing operator+ and other overloaded binary operators is the following:

Type operator+(Type lhs, Type const& rhs ) {
   lhs += rhs;
   return lhs;
}

Exactly how this is compiled depends on both compiler version and optimization level, but it seems not to involve an additional copy at -O2 or -O3 on recent versions of the major compilers. See https://godbolt.org/z/W7BXKk for some experimentation with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions