Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 1.49 KB

pointer_to.md

File metadata and controls

59 lines (43 loc) · 1.49 KB

pointer_to

  • memory[meta header]
  • std[meta namespace]
  • pointer_traits[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
static pointer pointer_traits::pointer_to(element_type& r);           // (1) C++11
static constexpr pointer pointer_traits::pointer_to(element_type& r); // (1) C++20


static pointer pointer_traits<T*>::pointer_to(element_type& r) noexcept;           // (2) C++11
static constexpr pointer pointer_traits<T*>::pointer_to(element_type& r) noexcept; // (2) C++20

概要

変数へのポインタを取得する。

戻り値

  • (1) : 型Ptrが静的メンバ関数pointer_to()を持っていればPtr::pointer_to(r)を呼び出してその戻り値を返す。持っていなければ、この関数のインスタンス化は不適格となる。
  • (2) : addressof(r)を返す。

#include <memory>
#include <iostream>

int main()
{
  int value = 3;
  int* p = std::pointer_traits<int*>::pointer_to(value);

  std::cout << *p << std::endl;
}
  • pointer_to[color ff0000]

出力

3

バージョン

言語

  • C++11

処理系

  • Clang: 3.0 [mark verified]
  • GCC: 4.7.3 [mark verified]
  • ICC: ??
  • Visual C++: 2012 [mark verified], 2013 [mark verified]

参照