Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.iso-c++ > #1999

Re: Move semantics und operator overloading

From ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups de.comp.lang.iso-c++
Subject Re: Move semantics und operator overloading
Date 2017-01-10 17:32 +0000
Organization Stefan Ram
Message-ID <operator-overloading-20170110181549@ram.dialup.fu-berlin.de> (permalink)
References (4 earlier) <30d04616-3615-44c7-a4aa-9f6a50d3b8af@googlegroups.com> <move-20170108232127@ram.dialup.fu-berlin.de> <8722e69a-16cc-4d7f-a3ee-baed2b66a56b@googlegroups.com> <RVO-20170109212221@ram.dialup.fu-berlin.de> <ba558c05-47af-46b8-a4c2-381ecc8251da@googlegroups.com>

Show all headers | View raw


Helmut Zeisel <zei2011@liwest.at> writes:
>Fuer kommutative Opratoren ist damit klar, dass die
>4-Overload-Version gewaehlt werden sollte. 

  Ich orientiere mich in solchen Fälle manchmal an den
  Lösungen Herb Sutters, der 2013

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

  schrieb (also genau /eine/ Überladung). Wenn es gut
  genug für Herb Sutter ist, ist es gut genug für mich.

  In 20.17.5.5, duration arithmetic findet man auch nur

constexpr operator+
( const duration< Rep1, Period1 >& lhs, 
  const duration< Rep2, Period2 >& rhs );

  Allerdings in 21.3 (vereinfacht)

operator +( const string &  lhs, const string &  rhs );
operator +(       string && lhs, const string &  rhs );
operator +( const string &  lhs,       string && rhs );
operator +(       string && lhs,       string && rhs );

>Das fuehrt dann aber auf die naechste Frage: was ist mit
>nichtkommutativen Operatoren? Es ist ja nicht einzusehen,
>warum
>"(a-b)-c" weniger copies/moves brauchen soll als "a-(b+c)"

  Ich verstehe jetzt nicht, warum die Kommutativität hier
  eine Rolle spielt. Aber, falls es für Dich eine Hilfe 
  ist: der oben gezeigte »::std::string::operator +« ist
  ja nicht-kommutativ.

  Guidelines:

F.15: Prefer simple and conventional ways of passing
information

      Using "unusual and clever" techniques causes surprises,
      slows understanding by other programmers, and encourages
      bugs. If you really feel the need for an optimization
      beyond the common techniques, measure to ensure that it
      really is an improvement

F.16: For "in" parameters, pass cheaply-copied types by
value and others by reference to const

      Avoid "esoteric techniques" such as:

      Passing arguments as T&& "for efficiency". Most rumors
      about performance advantages from passing by && are
      false or brittle

Back to de.comp.lang.iso-c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-06 23:53 -0800
  Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-07 15:38 +0000
  Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-07 16:36 +0000
    Re: Move semantics und operator overloading Helmut Zeisel <helmut.zeisel@gmail.com> - 2017-01-07 12:10 -0800
      Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-08 14:00 +0000
        Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-08 07:27 -0800
          Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-08 22:26 +0000
            Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-09 00:50 -0800
              Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-09 20:26 +0000
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-09 22:59 -0800
                Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-10 17:32 +0000
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-10 09:56 -0800
                Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-11 00:21 +0000
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-10 23:41 -0800
                Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-11 10:04 +0000
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-11 02:33 -0800
                Re: Move semantics und operator overloading Bonita Montero <Bonita.Montero@gmail.com> - 2017-01-11 15:43 +0100
                Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-11 22:27 +0000
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-11 22:22 -0800
                Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-12 18:15 +0000
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-12 12:34 -0800
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-13 03:30 -0800
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-11 23:53 -0800
                Re: Move semantics und operator overloading ram@zedat.fu-berlin.de (Stefan Ram) - 2017-01-12 20:23 +0000
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-13 00:47 -0800
                Re: Move semantics und operator overloading Helmut Zeisel <zei2011@liwest.at> - 2017-01-11 00:15 -0800

csiph-web