This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
[pointer.conversion]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#pointer.conversion)
### 20.2.4 Pointer conversion [pointer.conversion]
[🔗](#lib:to_address)
`template<class T> constexpr T* to_address(T* p) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L916)
*Mandates*: T is not a function type[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L920)
*Returns*: p[.](#2.sentence-1)
[🔗](#lib:to_address_)
`template<class Ptr> constexpr auto to_address(const Ptr& p) noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L931)
*Returns*: pointer_traits<Ptr>::to_address(p) if that expression is well-formed
(see [[pointer.traits.optmem]](pointer.traits.optmem "20.2.3.4Optional members")),
otherwise to_address(p.operator->())[.](#3.sentence-1)

165
cppdraft/pointer/traits.md Normal file
View File

@@ -0,0 +1,165 @@
[pointer.traits]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#pointer.traits)
### 20.2.3 Pointer traits [pointer.traits]
#### [20.2.3.1](#general) General [[pointer.traits.general]](pointer.traits.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L745)
The class template pointer_traits supplies a uniform interface to certain
attributes of pointer-like types[.](#general-1.sentence-1)
[🔗](#lib:pointer_traits)
namespace std {template<class Ptr> struct pointer_traits {*see below*; }; template<class T> struct pointer_traits<T*> {using pointer = T*; using element_type = T; using difference_type = ptrdiff_t; template<class U> using rebind = U*; static constexpr pointer pointer_to(*see below* r) noexcept; };}
#### [20.2.3.2](#types) Member types [[pointer.traits.types]](pointer.traits.types)
[1](#types-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L770)
The definitions in this subclause make use of
the following exposition-only class template and concept:template<class T>struct *ptr-traits-elem* // *exposition only*{ };
template<class T> requires requires { typename T::element_type; }struct *ptr-traits-elem*<T>{ using type = typename T::element_type; };
template<template<class...> class SomePointer, class T, class... Args>requires (!requires { typename SomePointer<T, Args...>::element_type; })struct *ptr-traits-elem*<SomePointer<T, Args...>>{ using type = T; };
template<class Ptr>concept [*has-elem-type*](#concept:has-elem-type "20.2.3.2Member types[pointer.traits.types]") = // *exposition only*requires { typename *ptr-traits-elem*<Ptr>::type; }
[2](#types-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L792)
If Ptr satisfies [*has-elem-type*](#concept:has-elem-type "20.2.3.2Member types[pointer.traits.types]"),
a specialization pointer_traits<Ptr> generated from the pointer_traits primary template
has the following members
as well as those described in [[pointer.traits.functions]](#functions "20.2.3.3Member functions");
otherwise, such a specialization has no members by any of those names[.](#types-2.sentence-1)
[🔗](#lib:pointer,pointer_traits)
`using pointer = see below;
`
[3](#types-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L806)
*Type*: Ptr[.](#types-3.sentence-1)
[🔗](#lib:element_type,pointer_traits)
`using element_type = see below;
`
[4](#types-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L816)
*Type*: typename *ptr-traits-elem*<Ptr>::type[.](#types-4.sentence-1)
[🔗](#lib:difference_type,pointer_traits)
`using difference_type = see below;
`
[5](#types-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L826)
*Type*: Ptr::difference_type if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Ptr::difference_type is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,ptrdiff_t[.](#types-5.sentence-1)
[🔗](#lib:rebind,pointer_traits)
`template<class U> using rebind = see below;
`
[6](#types-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L839)
*Alias template*: Ptr::rebind<U> if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Ptr::rebind<U> is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,SomePointer<U, Args> ifPtr is a class template instantiation of the form SomePointer<T, Args>,
where Args is zero or more type arguments; otherwise, the instantiation ofrebind is ill-formed[.](#types-6.sentence-1)
#### [20.2.3.3](#functions) Member functions [[pointer.traits.functions]](pointer.traits.functions)
[🔗](#lib:pointer_to,pointer_traits)
`static pointer pointer_traits::pointer_to(see below r);
static constexpr pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
`
[1](#functions-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L858)
*Mandates*: For the first member function,Ptr::pointer_to(r) is well-formed[.](#functions-1.sentence-1)
[2](#functions-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L863)
*Preconditions*: For the first member function,Ptr::pointer_to(r) returns a pointer to r through which indirection is valid[.](#functions-2.sentence-1)
[3](#functions-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L869)
*Returns*: The first member function returns Ptr::pointer_to(r)[.](#functions-3.sentence-1)
The second member function returns addressof(r)[.](#functions-3.sentence-2)
[4](#functions-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L874)
*Remarks*: If element_type is cv void, the type ofr is unspecified; otherwise, it is element_type&[.](#functions-4.sentence-1)
#### [20.2.3.4](#optmem) Optional members [[pointer.traits.optmem]](pointer.traits.optmem)
[1](#optmem-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L882)
Specializations of pointer_traits may define the member declared
in this subclause to customize the behavior of the standard library[.](#optmem-1.sentence-1)
A specialization generated from the pointer_traits primary template
has no member by this name[.](#optmem-1.sentence-2)
[🔗](#lib:to_address,pointer_traits)
`static element_type* to_address(pointer p) noexcept;
`
[2](#optmem-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L894)
*Returns*: A pointer of type element_type* that references
the same location as the argument p[.](#optmem-2.sentence-1)
[3](#optmem-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L899)
[*Note [1](#optmem-note-1)*:
This function is intended to be the inverse of pointer_to[.](#optmem-3.sentence-1)
If defined, it customizes the behavior of
the non-member functionto_address ([[pointer.conversion]](pointer.conversion "20.2.4Pointer conversion"))[.](#optmem-3.sentence-2)
— *end note*]

View File

@@ -0,0 +1,41 @@
[pointer.traits.functions]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#pointer.traits.functions)
### 20.2.3 Pointer traits [[pointer.traits]](pointer.traits#functions)
#### 20.2.3.3 Member functions [pointer.traits.functions]
[🔗](#lib:pointer_to,pointer_traits)
`static pointer pointer_traits::pointer_to(see below r);
static constexpr pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L858)
*Mandates*: For the first member function,Ptr::pointer_to(r) is well-formed[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L863)
*Preconditions*: For the first member function,Ptr::pointer_to(r) returns a pointer to r through which indirection is valid[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L869)
*Returns*: The first member function returns Ptr::pointer_to(r)[.](#3.sentence-1)
The second member function returns addressof(r)[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L874)
*Remarks*: If element_type is cv void, the type ofr is unspecified; otherwise, it is element_type&[.](#4.sentence-1)

View File

@@ -0,0 +1,20 @@
[pointer.traits.general]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#pointer.traits.general)
### 20.2.3 Pointer traits [[pointer.traits]](pointer.traits#general)
#### 20.2.3.1 General [pointer.traits.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L745)
The class template pointer_traits supplies a uniform interface to certain
attributes of pointer-like types[.](#1.sentence-1)
[🔗](#lib:pointer_traits)
namespace std {template<class Ptr> struct pointer_traits {*see below*; }; template<class T> struct pointer_traits<T*> {using pointer = T*; using element_type = T; using difference_type = ptrdiff_t; template<class U> using rebind = U*; static constexpr pointer pointer_to(*see below* r) noexcept; };}

View File

@@ -0,0 +1,44 @@
[pointer.traits.optmem]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#pointer.traits.optmem)
### 20.2.3 Pointer traits [[pointer.traits]](pointer.traits#optmem)
#### 20.2.3.4 Optional members [pointer.traits.optmem]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L882)
Specializations of pointer_traits may define the member declared
in this subclause to customize the behavior of the standard library[.](#1.sentence-1)
A specialization generated from the pointer_traits primary template
has no member by this name[.](#1.sentence-2)
[🔗](#lib:to_address,pointer_traits)
`static element_type* to_address(pointer p) noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L894)
*Returns*: A pointer of type element_type* that references
the same location as the argument p[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L899)
[*Note [1](#note-1)*:
This function is intended to be the inverse of pointer_to[.](#3.sentence-1)
If defined, it customizes the behavior of
the non-member functionto_address ([[pointer.conversion]](pointer.conversion "20.2.4Pointer conversion"))[.](#3.sentence-2)
— *end note*]

View File

@@ -0,0 +1,81 @@
[pointer.traits.types]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#pointer.traits.types)
### 20.2.3 Pointer traits [[pointer.traits]](pointer.traits#types)
#### 20.2.3.2 Member types [pointer.traits.types]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L770)
The definitions in this subclause make use of
the following exposition-only class template and concept:template<class T>struct *ptr-traits-elem* // *exposition only*{ };
template<class T> requires requires { typename T::element_type; }struct *ptr-traits-elem*<T>{ using type = typename T::element_type; };
template<template<class...> class SomePointer, class T, class... Args>requires (!requires { typename SomePointer<T, Args...>::element_type; })struct *ptr-traits-elem*<SomePointer<T, Args...>>{ using type = T; };
template<class Ptr>concept [*has-elem-type*](#concept:has-elem-type "20.2.3.2Member types[pointer.traits.types]") = // *exposition only*requires { typename *ptr-traits-elem*<Ptr>::type; }
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L792)
If Ptr satisfies [*has-elem-type*](#concept:has-elem-type "20.2.3.2Member types[pointer.traits.types]"),
a specialization pointer_traits<Ptr> generated from the pointer_traits primary template
has the following members
as well as those described in [[pointer.traits.functions]](pointer.traits.functions "20.2.3.3Member functions");
otherwise, such a specialization has no members by any of those names[.](#2.sentence-1)
[🔗](#lib:pointer,pointer_traits)
`using pointer = see below;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L806)
*Type*: Ptr[.](#3.sentence-1)
[🔗](#lib:element_type,pointer_traits)
`using element_type = see below;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L816)
*Type*: typename *ptr-traits-elem*<Ptr>::type[.](#4.sentence-1)
[🔗](#lib:difference_type,pointer_traits)
`using difference_type = see below;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L826)
*Type*: Ptr::difference_type if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Ptr::difference_type is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,ptrdiff_t[.](#5.sentence-1)
[🔗](#lib:rebind,pointer_traits)
`template<class U> using rebind = see below;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L839)
*Alias template*: Ptr::rebind<U> if
the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Ptr::rebind<U> is valid and denotes a
type ([[temp.deduct]](temp.deduct "13.10.3Template argument deduction")); otherwise,SomePointer<U, Args> ifPtr is a class template instantiation of the form SomePointer<T, Args>,
where Args is zero or more type arguments; otherwise, the instantiation ofrebind is ill-formed[.](#6.sentence-1)