std::slice
De cppreference.com
![]() | Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate. La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
Definido en el archivo de encabezado <valarray> | ||
class slice; | ||
std::slice
es el selector de clase que identifica un subconjunto de std::valarray similar a la rebanada BLAS. Un objeto de std::slice
tipo tiene tres valores: el índice de inicio, la zancada, y el número total de valores en el subconjunto. Objetos std::slice
tipo se puede utilizar como índices con operator[]
valarray de .Original:
std::slice
is the selector class that identifies a subset of std::valarray similar to BLAS slice. An object of type std::slice
holds three values: the starting index, the stride, and the total number of values in the subset. Objects of type std::slice
can be used as indexes with valarray's operator[]
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar]Las funciones miembro
construye una rebanada Original: constructs a slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro pública) | |
accede al inicio de la rebanada Original: accesses the start of the slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro pública) | |
accede al tamaño del segmento Original: accesses the size of the slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro pública) | |
accede al paso de la rebanada Original: accesses the stride of the slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro pública) |
[editar]Ejemplo
Barebones valarray respaldado por Matrix clase con una función de cálculo de rastrear .
Original:
Barebones valarray-backed Matrix class with a rastrear calculating function.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ejecuta este código
#include <iostream>#include <valarray>class Matrix {std::valarray<int> data;int dim;public: Matrix(int r, int c): data(r*c), dim(c){}int& operator()(int r, int c){return data[r*dim + c];}int trace()const{return data[std::slice(0, dim, dim+1)].sum();}};int main(){ Matrix m(3,3);int n =0;for(int r=0; r<3;++r)for(int c=0; c<3;++c) m(r, c)=++n;std::cout<<"Trace of the matrix (1,2,3) (4,5,6) (7,8,9) is "<< m.trace()<<'\n';}
Salida:
Trace of the matrix (1,2,3) (4,5,6) (7,8,9) is 15
[editar]Ver también
obtener / establecer un elemento de valarray, sector o máscara (función miembro pública) | |
rebanada generalizada de un valarray: Índice de partida, establecida de longitudes, un conjunto de pasos Original: generalized slice of a valarray: starting index, set of lengths, set of strides The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (clase) | |
proxy para un subconjunto de un valarray después de la aplicación de una rebanada Original: proxy to a subset of a valarray after applying a slice The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de clase) |