Espaços nominais
Variantes
Acções

std::pointer_traits

Da cppreference.com
< cpp‎ | memory

 
 
Biblioteca de utilitários
Digite apoio (basic types, RTTI, type traits)
Gerenciamento de memória dinâmica
De tratamento de erros
Utilidades do programa
Variadic funções
Data e hora
Objetos de função
(C++11)
Os operadores relacionais
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.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Pares e 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)
Troque, avançar e avançar
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)
 
Gerenciamento de memória dinâmica
Gerenciamento de memória de baixo nível
Alocadores
Original:
Allocators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Uninitialized armazenamento
Original:
Uninitialized storage
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ponteiros inteligentes
Original:
Smart pointers
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)
(obsoleta)
(C++11)
Apoio a coleta de lixo
Original:
Garbage collection support
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pointer_traits
(C++11)
(C++11)
(C++11)
C Library
Original:
C Library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Definido no cabeçalho <memory>
template< class Ptr > struct pointer_traits;
(1) (desde C++11)
template< class T > struct pointer_traits<T*>;
(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.

Índice

[editar] Tipos de membro

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
pointer Ptr
element_type
Ptr::element_type se presente. Caso contrário T se Ptr é um Template<T, Args...> instanciação do modelo
Original:
Ptr::element_type if present. Otherwise T if Ptr is a template instantiation Template<T, Args...>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
difference_type
Ptr::difference_type se presente, caso contrário std::ptrdiff_t
Original:
Ptr::difference_type if present, otherwise std::ptrdiff_t
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Membros apelido modelos

Modelo
Original:
Template
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
template <class U> using rebind
Ptr::rebind<U> se existir, caso contrário Tempate<U, Args...> se Ptr é um Template<T, Args...> instanciação do modelo
Original:
Ptr::rebind<U> if exists, otherwise Tempate<U, Args...> if Ptr is a template instantiation Template<T, Args...>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Funções de membro

[estática]
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.
You can help to correct and verify the translation. Click here for instructions.

(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.

[editar] Tipos de membro

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
pointer T*
element_type T
difference_type std::ptrdiff_t

[editar] Membros apelido modelos

Modelo
Original:
Template
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
template< class U > using rebind U*

[editar] Funções de membro

[estática]
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.
You can help to correct and verify the translation. Click here for instructions.

(função public static membro)

[editar] 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.

[editar] 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:

​0​

[editar] 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.
You can help to correct and verify the translation. Click here for instructions.

(modelo de classe) [edit]
(C++11)
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.
You can help to correct and verify the translation. Click here for instructions.

(modelo de função) [edit]