std::pointer_traits
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| Déclaré dans l'en-tête <memory>
|
||
template< class Ptr > struct pointer_traits; |
(1) | (depuis C++11) |
template< class T > struct pointer_traits<T*>; |
(2) | (depuis C++11) |
Le modèle de classe
pointer_traits fournit le moyen standard d'accéder à certaines propriétés du pointeur en forme de types. Le std::allocator_traits modèle standard repose sur pointer_traits pour déterminer les valeurs par défaut pour les différents typedefs nécessite par 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.
You can help to correct and verify the translation. Click here for instructions.
1)
Le
pointer_traits non spécialisé déclare les types suivants: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.
You can help to correct and verify the translation. Click here for instructions.
Types de membres
Type d'
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 si elle est présente. Sinon T si Ptr est un Template<T, Args...> instanciation du modèle 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 si présent, sinon 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. |
Membres alias modèles
Modèle
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> si elle existe, sinon Tempate<U, Args...> si Ptr est un Template<T, Args...> instanciation du modèle 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. |
Fonctions membres
[ statique ]Original: static The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
obtient un pointeur dereferencable à son argument 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. (fonction membre publique statique) |
2)
Une spécialisation est prévue pour les types pointeur,
T*, qui déclare les types suivantsOriginal:
A specialization is provided for pointer types,
T*, which declares the following typesThe 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.
Types de membres
Type d'
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 |
Membres alias modèles
Modèle
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*
|
Fonctions membres
[ statique ]Original: static The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
obtient un pointeur dereferencable à son argument} 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. (fonction membre publique statique) |
Notes
L'alias REBIND modèle membres permet, étant donné un type de pointeur en forme de T qui pointe vers, pour obtenir le même pointeur comme le type qui pointe vers U. Par exemple,
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.
You can help to correct and verify the translation. Click here for instructions.
std :: is_same <std :: pointer_traits <std :: shared_ptr <int>> :: rebind <double>, std :: unique_ptr <double>> :: valeur), "")
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.
You can help to correct and verify the translation. Click here for instructions.
Exemple
#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';
}
Résultat :
0
Voir aussi
(C++11) |
fournit des informations sur les types d'allocateur (classe générique) |
(C++11) |
obtient l'adresse réelle d'un objet, même si l'opérateur & est surchargé 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. (fonction générique) |