名前空間
変種
操作

std::pointer_traits

提供: cppreference.com
< cpp‎ | memory

 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
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>=
ペアとタプル
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.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
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.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
動的なメモリ管理
低レベルのメモリ管理
アロケータ
Original:
Allocators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
allocator
allocator_traits(C++11)
allocator_arg_t(C++11)
allocator_arg(C++11)
uses_allocator(C++11)
scoped_allocator_adaptor(C++11)
ストレージを初期化されていない
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.
uninitialized_copy
uninitialized_copy_n(C++11)
uninitialized_fill
uninitialized_fill_n
raw_storage_iterator
get_temporary_buffer
return_temporary_buffer
スマートポインタ
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.
unique_ptr(C++11)
shared_ptr(C++11)
weak_ptr(C++11)
auto_ptr(廃止予定)
owner_less(C++11)
enable_shared_from_this(C++11)
bad_weak_ptr(C++11)
default_delete(C++11)
ガベージコレクションをサポートしています
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.
declare_reachable(C++11)
undeclare_reachable(C++11)
declare_no_pointers(C++11)
undeclare_no_pointers(C++11)
pointer_safety(C++11)
get_pointer_safety(C++11)
その他
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)
addressof(C++11)
align(C++11)
Cライブラリ
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.
 
Defined in header <memory>
template< class Ptr > struct pointer_traits;
(1) (C + + 11以来)
template< class T > struct pointer_traits<T*>;
(2) (C + + 11以来)
pointer_traitsクラステンプレートはポインタのような型の特定のプロパティにアクセスするための標準化された方法を提供します。標準テンプレートstd::allocator_traitsは、様々な型定義のデフォルトを決定するためにpointer_traitsに依存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)
非専門pointer_traitsは、次の種類を宣言します
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.

目次

[編集] メンバータイプ

タイプ
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存在する場合。さもなければT場合PtrテンプレートインスタンスTemplate<T, Args...>です
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存在する場合、それ以外の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.

[編集] メンバーの別名のテンプレート

テンプレート
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>存在する場合、それ以外の場合Tempate<U, Args...>PtrテンプレートインスタンスTemplate<T, Args...>です
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.

[編集] メンバ関数

[静的]
その引数にdereferencableポインタを取得します
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.

(公共の静的メンバ関数)
2)
専門分野は、ポインタ型、T*、次の型を宣言するために設けられている
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.

[編集] メンバータイプ

タイプ
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

[編集] メンバーの別名のテンプレート

テンプレート
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*

[編集] メンバ関数

[静的]
}は引数にdereferencableポインタを取得します
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.

(公共の静的メンバ関数)

[編集] ノート

REBINDメンバテンプレートの別名がTに点が、例えばUに点、同じポインタのようなタイプを得るためには、そのポインタのような型を指定し、それが可能になります
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>の> :: REBIND <double>には、std :: unique_ptrを<double>に> ::値)、 "")
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.

[編集]

#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';
}

Output:

​0​

[編集] も参照してください

アロケータの種類についての情報を提供します
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.

(クラステンプレート) [edit]
(C++11)
演算子がオーバーロードされた場合でも、オブジェクトの実際のアドレスを取得します
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.

(関数テンプレート) [edit]