Espacios de nombres
Variantes
Acciones

copy elision

De cppreference.com
< cpp‎ | language

 
 
Lenguaje C++
Los temas generales
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.
Control de flujo
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.
Sentencias condicionales ejecución
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.
Instrucciones de iteración
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.
Ir declaraciones
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.
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaración de la función
lambda declaración de la función
función de plantilla
especificador inline
especificaciones de excepción (obsoleto)
noexcept especificador (C++11)
Excepciones
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los espacios de nombres
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
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)
Los especificadores
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 especificadores
almacenamiento duración especificadores
constexpr especificador (C++11)
auto especificador (C++11)
alignas especificador (C++11)
Inicialización
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los literales
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expresiones
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representaciones alternativas
Utilidades
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
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
alias de tipo de declaración (C++11)
atributos (C++11)
Lanza
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversiones implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-cast estilo y funcional
De asignación de memoria
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.
Clases
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clase propiedades específicas de la función
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.
Funciones especiales miembro
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.
Plantillas
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clase de plantilla
función de plantilla
plantilla de especialización
paquetes de parámetros (C++11)
Varios
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaje en línea
 
Optimiza la salida de copiar y mover-constructores, lo que resulta en el paso por valor de copia cero semántica .
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.

Contenido

[editar] Explicación

En los siguientes casos, los compiladores se les permite omitir el copiar y mover-constructores de los objetos de la clase, incluso si copiar / mover constructor y el destructor han observables los efectos secundarios .
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.
  • Si una función devuelve un tipo de clase de valor, y la expresión de la declaración return es el nombre de un objeto no volátil con una duración de almacenamiento automático, que no es el parámetro de función o un parámetro de captura cláusula, y que tiene la misma cv- tipo calificado como el tipo de retorno de la función, a continuación, copiar / mover omite. Cuando esa variable local se construye, se construye directamente en el almacén donde el valor devuelto por la función de otro modo se mueven o copian. Esta variante de la elisión copia se conoce como NRVO ", llamado optimización valor de retorno" .
    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.
  • Cuando un sin nombre temporal, no vinculado a ninguna referencia, se pueden mover o copiar un objeto de la misma cv-tipo incondicional, la copia / movimiento es omitido. Cuando temporal que se construye, se construye directamente en el almacenamiento en el que de otro modo se mueve o se copia. Cuando los sin nombre temporal es el argumento de una instrucción de retorno, esta variante de la elisión copia se conoce como RVO, "devolver la optimización de valor" .
    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.
  • En una banda expresión, si el operando es el nombre de un objeto no volátil con una duración de almacenamiento automático, que no es el parámetro de función o un parámetro de captura cláusula, y cuyo alcance no se extiende más allá de la más interior probar-bloque ( si hay un intento de bloque), entonces copia / movimiento se omite. Cuando esa variable local se construye, se construye directamente en el almacenamiento en el objeto de excepción de otro modo se mueven o copian. (desde 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. (desde C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Al manejar una excepción, si el argumento de la cláusula catch es del mismo tipo (a excepción de cv-calificación) como el objeto de la excepción lanzada, la copia / movimiento se omite y el cuerpo de la cláusula catch acceso al objeto de excepción, como si se pasa por referencia. (desde 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. (desde C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Elisiones múltiples copias pueden ser encadenados para eliminar múltiples copias .
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.

[editar] Notas

Copia elisión es la única forma permitida de optimización que puede cambiar los observables efectos secundarios. Debido a que algunos compiladores no realizar elisión copia en cada situación en la que se permite, los programas que se basan en los efectos secundarios de los constructores de copia / movimiento y destructores no son portátiles .
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.
Incluso cuando elisión copia se lleva a cabo y el copy-/move-constructor no se llama, que debe estar presente y accesible, de lo contrario el programa es mal formado .
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.

[editar] Ejemplo

#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

[editar] Ver también