Espacios de nombres
Variantes
Acciones

std::chrono::duration

De cppreference.com
< cpp‎ | chrono


 
 
Utilidades de la biblioteca
Escriba apoyo (basic types, RTTI, type traits)
Gestión de memoria dinámica
Gestión de errores
Programa de servicios públicos
Funciones variadic
Fecha y hora
Objetos Function
(C++11)
Operadores relacionales
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Pares y tuplas
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Cambiar, hacia adelante y mover
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
 
 
std::chrono::duration
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Terceros funciones
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clases de ayuda
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Definido en la cabecera <chrono>
template<

    class Rep,
    class Period = std::ratio<1>

> class duration;
(desde C++11)

Class template std::chrono::duration represents a time interval.

It consists of a count of ticks of type Rep and a tick period, where the tick period is a compile-time rational constant representing the number of seconds from one tick to the next.

The only data stored in a duration is a tick count of type Rep. If Rep is floating point, then the duration can represent fractions of ticks. Period is included as part of the duration's type, and is only used when converting between different durations.

Contenido

[editar] Tipos de miembros

Miembro de tipo
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
rep Rep, an arithmetic type representing the number of ticks
period Period, a std::ratio representing the tick period (i.e. the number of seconds per tick)

[editar] Las funciones miembro

construye nueva duración
Original:
constructs new duration
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úblico) [editar]
asigna el contenido
Original:
assigns the contents
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úblico) [editar]
devuelve el número de ticks
Original:
returns the count of ticks
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úblico) [editar]
[estático]
returns the special duration value zero
(función miembro público estático) [editar]
[estático]
devuelve el valor especial de duración min
Original:
returns the special duration value min
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úblico estático) [editar]
[estático]
devuelve el valor máximo de duración especial
Original:
returns the special duration value max
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úblico estático) [editar]
implementa + unario y - unario
Original:
implements unary + and unary -
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úblico) [editar]
aumenta o disminuye el contador
Original:
increments or decrements the tick count
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úblico) [editar]
implementa asignación compuesta entre dos duraciones
Original:
implements compound assignment between two durations
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úblico) [editar]

[editar] Non-member types

Tipo
Original:
Type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
std::chrono::nanoseconds duration type with Period std::nano
std::chrono::microseconds duration type with Period std::micro
std::chrono::milliseconds duration type with Period std::milli
std::chrono::seconds duration type with Period std::ratio<1>
std::chrono::minutes duration type with Period std::ratio<60>
std::chrono::hours duration type with Period std::ratio<3600>

[editar] Terceros funciones

se especializa el rasgo std::common_type
Original:
specializes the std::common_type trait
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(especialización de plantilla de clase) [editar]
implementa las operaciones aritméticas con duraciones como argumentos
Original:
implements arithmetic operations with durations as arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de función) [editar]
compara dos duraciones
Original:
compares two durations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de función) [editar]
convierte una duración a otra, con un intervalo de garrapata diferente
Original:
converts a duration to another, with a different tick interval
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(plantilla de función) [editar]

[editar] Clases de ayuda

indicates that a duration is convertible to duration with different tick period
(plantilla de clase)
constructs zero, min, and max values of a tick count of given type
(plantilla de clase)

[editar] Ejemplo

This example shows how to define several custom duration types and convert between types:

#include <iostream>
#include <chrono>
 
int main()
{
    typedef std::chrono::duration<int, std::ratio<1, 100000000>> shakes;
    typedef std::chrono::duration<int, std::centi> jiffies;
    typedef std::chrono::duration<float, std::ratio<12096,10000>> microfortnights;
    typedef std::chrono::duration<float, std::ratio<3155,1000>> nanocenturies;
 
    std::chrono::seconds sec(1);
 
    std::cout << "1 second is:\n";
 
    std::cout << std::chrono::duration_cast<shakes>(sec).count()
              << " shakes\n";
    std::cout << std::chrono::duration_cast<jiffies>(sec).count()
              << " jiffies\n";
    std::cout << std::chrono::duration_cast<microfortnights>(sec).count()
              << " microfortnights\n";
    std::cout << std::chrono::duration_cast<nanocenturies>(sec).count()
              << " nanocenturies\n";
}

Salida:

1 second is:
100000000 shakes
100 jiffies
0.82672 microfortnights
0.316957 nanocenturies