Namensräume
Varianten
Aktionen

copy elision

Aus cppreference.com
< cpp‎ | language

 
 
Sprache C + +
Allgemeine Themen
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Flusskontrolle
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bedingte Ausführung Aussagen
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterationsanweisungen
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Gehe Aussagen
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktion Erklärung
Lambda-Funktion Erklärung
Funktions-Template
inline-Spezifizierer
Exception-Spezifikationen (veraltet)
noexcept Spezifizierer (C++11)
Ausnahmen
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
Specifiers
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv Planer
Lagerdauer Planer
constexpr Spezifizierer (C++11)
auto Spezifizierer (C++11)
alignas Spezifizierer (C++11)
Initialisierung
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literale
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressions
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alternative Darstellungen
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
Typ Aliasdeklaration (C++11)
Attribute (C++11)
Wirft
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
impliziten Konvertierungen
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-Stil und funktionale Besetzung
Speicherzuweisung
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Class-spezifische Funktion Eigenschaften
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
explizit (C++11)
statisch
Besondere Member-Funktionen
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Templates
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Klassen-Template
Funktions-Template
Template-Spezialisierung
Parameter Packs (C++11)
Verschiedenes
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Inline Montage
 
Optimiert von copy-and move-Konstruktoren, was zero-copy pass-by-value-Semantik .
Original:
Optimizes out copy- and move-constructors, resulting in zero-copy pass-by-value semantics.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten] Erklärung

Unter den folgenden Umständen werden die Compiler gestattet, die copy-and move-Konstruktoren der Klasse Objekte auch wenn copy / move Konstruktor und der Destruktor haben Nebenwirkungen beobachtet weglassen .
Original:
Under the following circumstances, the compilers are permitted to omit the copy- and move-constructors of class objects even if copy/move constructor and the destructor have observable side-effects.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Wenn eine Funktion eine Klasse Art von Wert, und die return Anweisung Ausdruck ist der Name eines nicht-flüchtigen Objekt mit automatischer Lagerdauer, die nicht die Funktion Parameter oder eine catch-Klausel Parameter und die die gleiche ist cv- unqualifizierte Typ wie der Rückgabetyp der Funktion, dann Kopieren / Verschieben wird ausgelassen. Wenn das lokale Variable konstruiert wird, wird es direkt in dem Speicher, wo der Funktion Rückgabewert anderweitig bewegt würde oder kopiert werden gebaut. Diese Variante der Kopie elision als NRVO bekannt ist ", benannt Rückgabewert Optimierung" .
    Original:
    If a function returns a class type by value, and the return statement's expression is the name of a non-volatile object with automatic storage duration, which isn't the function parameter, or a catch clause parameter, and which has the same cv-unqualified type as the return type of the function, then copy/move is omitted. When that local variable is constructed, it is constructed directly in the storage where the function's return value would otherwise be moved or copied to. This variant of copy elision is known as NRVO, "named return value optimization".
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Wenn eine namenlose temporäre, nicht für alle Verweise gebunden, würde verschoben oder in ein Objekt des gleichen cv-unqualifizierten Typs kopiert werden, wird das Kopieren / Verschieben weggelassen. Wenn dieser temporären aufgebaut ist, wird es direkt in der Speichereinheit aufgebaut, wo es anderweitig bewegt würde oder kopiert werden. Wenn der namenlose temporäre das Argument einer return-Anweisung ist, diese Variante der Kopie elision als RVO bekannt ist, "Rückgabewert Optimierung" .
    Original:
    When a nameless temporary, not bound to any references, would be moved or copied into an object of the same cv-unqualified type, the copy/move is omitted. When that temporary is constructed, it is constructed directly in the storage where it would otherwise be moved or copied to. When the nameless temporary is the argument of a return statement, this variant of copy elision is known as RVO, "return value optimization".
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • In einer Einwurf-Expression, wenn der Operand der Name eines nichtflüchtigen Objekt mit dynamischem Speicher Dauer, die nicht der Funktionsparameter oder ein Fang-Klausel Parameter und deren Umfang nicht über die innerste Try-Block erstrecken beträgt ( wenn es einen try-Block), dann copy / move wird ausgelassen. Wenn das lokale Variable konstruiert wird, wird es direkt in dem Speicher, wo das Exception-Objekt anderweitig bewegt würde oder kopiert werden gebaut. (seit C++11)
    Original:
    In a throw-expression, if the operand is the name of a non-volatile object with automatic storage duration, which isn't the function parameter, or a catch clause parameter, and whose scope does not extend past the innermost try-block (if there is a try-block), then copy/move is omitted. When that local variable is constructed, it is constructed directly in the storage where the exception object would otherwise be moved or copied to. (seit C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Beim Umgang mit eine Ausnahme, wenn das Argument der catch-Klausel ist von der gleichen Art (mit Ausnahme von cv-Qualifikation) als die Ausnahme-Objekt ausgelöst, wird das Kopieren / Verschieben weggelassen und der Körper der catch-Klausel greift die Ausnahme Objekt direkt, wie wenn es per Referenz übergeben. (seit C++11)
    Original:
    When handling an exception, if the argument of the catch clause is of the same type (except for cv-qualification) as the exception object thrown, the copy/move is omitted and the body of the catch clause accesses the exception object directly, as if it was passed by reference. (seit C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Mehrfachkopien Auslassungen können verkettet werden, um mehrere Kopien zu beseitigen .
Original:
Multiple copy elisions may be chained to eliminate multiple copies.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Notes

Kopieren Auslassung ist die einzige erlaubte Form der Optimierung, die die beobachtbaren Nebenwirkungen ändern können. Da einige Compiler nicht durchführen copy elision in jeder Situation, wo es erlaubt ist, sind Programme, die auf die Nebenwirkungen von copy / move Konstruktoren und Destruktoren verlassen nicht tragbar .
Original:
Copy elision is the only allowed form of optimization that can change the observable side-effects. Because some compilers do not perform copy elision in every situation where it is allowed, programs that rely on the side-effects of copy/move constructors and destructors are not portable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Auch beim Kopieren elision stattfindet und die copy-/move-constructor wird nicht aufgerufen, es muss vorhanden und zugänglich, ansonsten ist das Programm schlecht gebildet .
Original:
Even when copy elision takes place and the copy-/move-constructor is not called, it must be present and accessible, otherwise the program is ill-formed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiel

#include <vector>
#include <iostream>
 
struct Noisy {
    Noisy() {std::cout << "constructed\n"; }
    Noisy(const Noisy&) { std::cout << "copied\n"; }
    Noisy(Noisy&&) { std::cout << "moved\n"; }
    ~Noisy() {std::cout << "destructed\n"; }
};
 
std::vector<Noisy> f()
{
    std::vector<Noisy> v = std::vector<Noisy>(3); // copy elision from temporary to v
    return v; // NRVO from v to the nameless temporary that is returned
}
 
void fn_by_val(std::vector<Noisy> arg)
{
    std::cout << "arg.size() = " << arg.size() << '\n';
}
 
int main()
{
    std::vector<Noisy> v = f(); // copy elision from returned temporary to v
    fn_by_val(f());             // and from temporary to the argument of fn_by_val()
}

Possible output:

constructed
constructed
constructed
constructed
constructed
constructed
arg.size() = 3
destructed
destructed
destructed
destructed
destructed
destructed

[Bearbeiten] Siehe auch