std::pointer_traits - cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Definido no cabeçalho <memory> |
||
|
|
(1) | (desde C++11) |
|
|
(2) | (desde C++11) |
O modelo de classe pointer_traits fornece a maneira padronizada para acessar certas propriedades do ponteiro-como tipos. O std::allocator_traits modelo padrão depende pointer_traits para determinar os padrões para vários typedefs requer por Allocator.
Original:
The pointer_traits class template provides the standardized way to access certain properties of pointer-like types. The standard template std::allocator_traits relies on pointer_traits to determine the defaults for various typedefs requires by Allocator.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
O pointer_traits não especializado declara os seguintes tipos:
Original:
The non-specialized pointer_traits declares the following types:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos de membro
Tipo Original: Type The text has been machine-translated via Google Translate. |
Definition |
pointer
|
Ptr
|
element_type
|
Original:
The text has been machine-translated via Google Translate. |
difference_type
|
Original:
The text has been machine-translated via Google Translate. |
Membros apelido modelos
Modelo Original: Template The text has been machine-translated via Google Translate. |
Definition |
| template <class U> using rebind |
Original:
The text has been machine-translated via Google Translate. |
Funções de membro
obtém um ponteiro dereferencable a sua tese Original: obtains a dereferencable pointer to its argument The text has been machine-translated via Google Translate. (função public static membro) | |
2)
A especialização é fornecido para tipos de ponteiro, T*, que declara os seguintes tipos
Original:
A specialization is provided for pointer types, T*, which declares the following types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos de membro
Tipo Original: Type The text has been machine-translated via Google Translate. |
Definition |
pointer
|
T*
|
element_type
|
T
|
difference_type
|
std::ptrdiff_t |
Membros apelido modelos
Modelo Original: Template The text has been machine-translated via Google Translate. |
Definition |
| template< class U > using rebind | U*
|
Funções de membro
obtém um ponteiro dereferencable ao seu argumento} Original: obtains a dereferencable pointer to its argument} The text has been machine-translated via Google Translate. (função public static membro) | |
Notas
O alias modelo religar membros torna possível, dado um tipo de ponteiro-como que aponta para T, para obter o tipo de ponteiro-like mesmo que aponta para U. por exemplo,
Original:
The rebind member template alias makes it possible, given a pointer-like type that points to T, to obtain the same pointer-like type that points to U. For example,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std :: is_same <std :: pointer_traits <std :: shared_ptr <int>> :: reativação <double>, std :: unique_ptr <double>> :: value), "")
Original:
std::is_same<std::pointer_traits< std::shared_ptr<int>>::rebind<double>, std::unique_ptr<double> >::value), "")
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exemplo
#include <memory> #include <iostream> template <class Ptr> struct BlockList { // Predefine a memory block struct block; // Define a pointer to a memory block from the kind of pointer Ptr s // If Ptr is any kind of T*, block_ptr_t is block* // If Ptr is smart_ptr<T>, block_ptr_t is smart_ptr<block> typedef typename std::pointer_traits<Ptr>::template rebind<block> block_ptr_t; struct block { std::size_t size; block_ptr_t next_block; }; block_ptr_t free_blocks; }; int main() { BlockList<int*> bl1; // The type of bl1.free_blocks is block* BlockList<std::shared_ptr<char>> bl2; // The type of bl2.free_blocks is std::shared_ptr<block> std::cout << bl2.free_blocks.use_count() << '\n'; }
Saída:
Veja também
fornece informações sobre os tipos de alocador Original: provides information about allocator types The text has been machine-translated via Google Translate. (modelo de classe) [edit] | |
obtém o endereço real de um objeto, mesmo se o operador &' está sobrecarregado Original: obtains actual address of an object, even if the & operator is overloaded The text has been machine-translated via Google Translate. (modelo de função) [edit] | |