Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/experimental/resource adaptor"

From cppreference.com
m (Text replace - "{{concept" to "{{named req")
m
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{cpp/experimental/pmr/title|resource_adaptor}}
+
{{title|{{small|std::experimental::pmr::}}resource_adaptor, {{small|std::pmr::experimental::}}resource_adaptor}}
 
{{cpp/experimental/lib extensions/pmr/navbar}}
 
{{cpp/experimental/lib extensions/pmr/navbar}}
 
+
{{dcl begin}}
{{ddcl | since=libfund_ts | header=experimental/memory_resource |1=
+
{{dcl header | experimental/memory_resource}}
template < class Alloc >
+
{{dcl | since=libfund_ts | 1=
class resource_adaptor_imp : public memory_resource; // for exposition only
+
template< class Alloc >
 
+
using resource_adaptor = /*resource-adaptor-imp*/<
template < class Allocator >
+
                             typename std::allocator_traits<Alloc>::
using resource_adaptor = resource_adaptor_imp<
+
                             typename std::allocator_traits<Allocator>::
+
 
                             template rebind_alloc<char>>;
 
                             template rebind_alloc<char>>;
 
}}
 
}}
 +
{{dcl | since=libfund_ts |
 +
template< class Alloc >
 +
class /*resource-adaptor-imp*/ : public memory_resource; // for exposition only
 +
}}
 +
{{dcl end}}
  
The alias template {{tt|resource_adaptor}} adapts the allocator type {{tt|Allocator}} with a {{tt|memory_resource}} interface. The allocator is rebound to a {{tt|char}} value type before it is actually adapted (using the ''{{tt|resource_adaptor_imp}}'' class template), so that adapting specializations of the same allocator template always yields the same type, regardless of the value type the allocator template is originally instantiated with.
+
The alias template {{tt|resource_adaptor}} adapts the allocator type {{tt|Alloc}} with a {{tt|memory_resource}} interface. The allocator is rebound to a {{tt|char}} value type before it is actually adapted (using the ''{{tt|resource-adaptor-imp}}'' class template), so that adapting specializations of the same allocator template always yields the same type, regardless of the value type the allocator template is originally instantiated with.
  
''{{tt|resource_adaptor_imp}}'' is a class template whose members are described below. The name ''{{tt|resource_adaptor_imp}}'' is for exposition purposes only and not normative.
+
{{rrev multi
 +
|since1=libfund_ts|rev1=
 +
{{tt|resource_adaptor}} is defined in namespace {{tt|std::experimental::pmr}}, and the base type {{tt|memory_resorce}} in this page is {{lc|std::experimental::pmr::memory_resource}}.
 +
|since2=libfund_ts_3|rev2=
 +
{{tt|resource_adaptor}} is defined in namespace {{tt|std::pmr::experimental}}, and the base type {{tt|memory_resorce}} in this page is {{lc|std::pmr::memory_resource}}.
 +
}}
  
In addition to meeting the {{named req|Allocator}} requirements, {{tt|Allocator}} must additionally satisfy the following requirements:
+
''{{tt|resource-adaptor-imp}}'' is a class template whose members are described below. The name ''{{tt|resource-adaptor-imp}}'' is for exposition purposes only and not normative.
  
* Its {{tt|pointer}} shall be identical to {{tt|value_type*}}.
+
In addition to meeting the {{named req|Allocator}} requirements, {{tt|Alloc}} must additionally satisfy the following requirements:
* Its {{tt|const_pointer}} shall be identical to {{tt|value_type const*}}.
+
* Its {{tt|void_pointer}} shall be identical to {{tt|void*}}.
+
* Its {{tt|const_void_pointer}} shall be identical to {{tt|void const*}}.
+
  
=== Member types of ''resource_adaptor_imp'' ===
+
* {{c|std::allocator_traits<Alloc>::pointer}} shall be identical to {{c|Alloc::value_type*}}.
 +
* {{c|std::allocator_traits<Alloc>::const_pointer}} shall be identical to {{c|Alloc::value_type const*}}.
 +
* {{c|std::allocator_traits<Alloc>::void_pointer}} shall be identical to {{c|void*}}.
 +
* {{c|std::allocator_traits<Alloc>::const_const_pointer}} shall be identical to {{c|void const*}}.
 +
 
 +
===Member types of ''resource-adaptor-imp''===
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc hitem| Member type | Definition}}
 
{{dsc hitem| Member type | Definition}}
Line 29: Line 39:
 
{{dsc end}}
 
{{dsc end}}
  
=== Member functions of ''resource_adaptor_imp'' ===
+
===Member functions of ''resource-adaptor-imp''===
{{member|{{small|std::experimental::pmr::''resource_adaptor_imp''::}}''resource_adaptor_imp''
+
{{member|{{small|''resource-adaptor-imp''::}}''resource-adaptor-imp''
 
|
 
|
 
{{dcl begin}}
 
{{dcl begin}}
 
{{dcl| num = 1 |  since=libfund_ts |1=
 
{{dcl| num = 1 |  since=libfund_ts |1=
  resource_adaptor_imp() = default;
+
/*resource-adaptor-imp*/() = default;
 
}}
 
}}
 
{{dcl | num = 2 |  since=libfund_ts |1=
 
{{dcl | num = 2 |  since=libfund_ts |1=
  resource_adaptor_imp(const resource_adaptor_imp& other) = default;
+
/*resource-adaptor-imp*/(const /*resource-adaptor-imp*/& other)
 +
    = default;
 
}}
 
}}
 
{{dcl | num = 3 |  since=libfund_ts |1=
 
{{dcl | num = 3 |  since=libfund_ts |1=
  resource_adaptor_imp(resource_adaptor_imp&& other) = default;
+
/*resource-adaptor-imp*/(/*resource-adaptor-imp*/&& other)
 +
    = default;
 
}}
 
}}
 
{{dcl | num = 4 |  since=libfund_ts |1=
 
{{dcl | num = 4 |  since=libfund_ts |1=
  explicit resource_adaptor_imp(const Alloc& a2);
+
explicit /*resource-adaptor-imp*/(const Alloc& a2);
 
}}
 
}}
 
{{dcl | num = 5 |  since=libfund_ts |1=
 
{{dcl | num = 5 |  since=libfund_ts |1=
  explicit resource_adaptor_imp(Alloc&& a2);
+
explicit /*resource-adaptor-imp*/(Alloc&& a2);
 
}}
 
}}
 
{{dcl end}}
 
{{dcl end}}
Line 57: Line 69:
 
====Parameters====
 
====Parameters====
 
{{par begin}}
 
{{par begin}}
{{par | other | another ''{{tt|resource_adaptor_imp}}'' object to copy or move from }}
+
{{par | other | another ''{{tt|resource-adaptor-imp}}'' object to copy or move from }}
 
{{par | a2 | another {{tt|Alloc}} object to copy or move from }}
 
{{par | a2 | another {{tt|Alloc}} object to copy or move from }}
 
{{par end}}
 
{{par end}}
 
}}
 
}}
  
{{member|{{small|std::experimental::pmr::''resource_adaptor_imp''::}}get_allocator
+
{{member|{{small|''resource-adaptor-imp''::}}get_allocator
 
|
 
|
 
{{ddcl |  since=libfund_ts |1=
 
{{ddcl |  since=libfund_ts |1=
    allocator_type get_allocator() const;  
+
allocator_type get_allocator() const;  
 
}}
 
}}
 
Returns a copy of the wrapped allocator.
 
Returns a copy of the wrapped allocator.
 
}}
 
}}
  
{{member|{{small|std::experimental::pmr::''resource_adaptor_imp''::}}operator{{=}}
+
{{member|{{small|''resource-adaptor-imp''::}}operator{{=}}
 
|
 
|
 
{{ddcl |  since=libfund_ts |1=
 
{{ddcl |  since=libfund_ts |1=
    resource_adaptor_imp& operator=(const resource_adaptor_imp& other) = default;  
+
/*resource-adaptor-imp*/& operator=(const /*resource-adaptor-imp*/& other)
 +
    = default;  
 
}}
 
}}
 
Defaulted copy assignment operator. Copy assigns the wrapped allocator from that of {{tt|other}}.
 
Defaulted copy assignment operator. Copy assigns the wrapped allocator from that of {{tt|other}}.
 
}}
 
}}
  
{{member|{{small|std::experimental::pmr::''resource_adaptor_imp''::}}do_allocate
+
{{member|{{small|''resource-adaptor-imp''::}}do_allocate
 
|
 
|
 
{{ddcl |  since=libfund_ts |1=
 
{{ddcl |  since=libfund_ts |1=
    virtual void* do_allocate(std::size_t bytes, std::size_t alignment);
+
protected:
 +
virtual void* do_allocate(std::size_t bytes, std::size_t alignment);
 
}}
 
}}
 
Allocates memory using the {{tt|allocate}} member function of the wrapped allocator.
 
Allocates memory using the {{tt|allocate}} member function of the wrapped allocator.
 
}}
 
}}
  
{{member|{{small|std::experimental::pmr::''resource_adaptor_imp''::}}do_deallocate
+
{{member|{{small|''resource-adaptor-imp''::}}do_deallocate
 
|
 
|
{{ddcl |  since=libfund_ts |1=
+
{{ddcl |  since=libfund_ts |
    virtual void do_deallocate(void *p, std::size_t bytes, std::size_t alignment);
+
protected:
 +
virtual void do_deallocate(void *p, std::size_t bytes, std::size_t alignment);
 
}}
 
}}
Deallocates the storage pointed to by {{tt|p}} using the {{tt|deallocate}} member function of the wrapped allocator. {{tt|p}} must have been allocated using the {{tt|allocate}} member function of an allocator that compares equal to the wrapped allocator, and must not have been subsequently deallocated.
+
Deallocates the storage pointed to by {{tt|p}} using the {{tt|deallocate}} member function of the wrapped allocator.
 +
 
 +
{{tt|p}} must have been allocated using the {{tt|allocate}} member function of an allocator that compares equal to the wrapped allocator, and must not have been subsequently deallocated.
 
}}
 
}}
  
{{member|{{small|std::experimental::pmr::''resource_adaptor_imp''::}}do_is_equal
+
{{member|{{small|''resource-adaptor-imp''::}}do_is_equal
 
|
 
|
{{ddcl |  since=libfund_ts |1=
+
{{ddcl |  since=libfund_ts |
    virtual bool do_is_equal(const memory_resource& other);
+
protected:
 +
virtual bool do_is_equal(const memory_resource& other) const noexcept;
 
}}
 
}}
Let {{tt|p}} be {{c|dynamic_cast<const resource_adaptor_imp*>(&other)}}. If {{tt|p}} is {{tt|nullptr}}, returns {{tt|false}}. Otherwise, return the result of comparing the allocators wrapped by {{tt|*p}} and {{tt|*this}} using {{tt|operator{{==}}}}.
+
Let {{tt|p}} be {{c|dynamic_cast<const /*resource-adaptor-imp*/*>(&other)}}. If {{tt|p}} is a null pointer value, returns {{c|false}}. Otherwise, return the result of comparing the allocators wrapped by {{c|*p}} and {{c|*this}} using {{c|1=operator==}}.
 
+
 
}}
 
}}
  
{{langlinks|zh}}
+
{{langlinks|de|es|ja|ru|zh}}

Latest revision as of 18:20, 9 April 2023

 
 
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
 
 
 
template< class Alloc >

using resource_adaptor = /*resource-adaptor-imp*/<
                             typename std::allocator_traits<Alloc>::

                             template rebind_alloc<char>>;
(library fundamentals TS)
template< class Alloc >
class /*resource-adaptor-imp*/ : public memory_resource; // for exposition only
(library fundamentals TS)

The alias template resource_adaptor adapts the allocator type Alloc with a memory_resource interface. The allocator is rebound to a char value type before it is actually adapted (using the resource-adaptor-imp class template), so that adapting specializations of the same allocator template always yields the same type, regardless of the value type the allocator template is originally instantiated with.

resource_adaptor is defined in namespace std::experimental::pmr, and the base type memory_resorce in this page is std::experimental::pmr::memory_resource.

(library fundamentals TS)
(until library fundamentals TS v3)

resource_adaptor is defined in namespace std::pmr::experimental, and the base type memory_resorce in this page is std::pmr::memory_resource.

(library fundamentals TS v3)

resource-adaptor-imp is a class template whose members are described below. The name resource-adaptor-imp is for exposition purposes only and not normative.

In addition to meeting the Allocator requirements, Alloc must additionally satisfy the following requirements:

[edit] Member types of resource-adaptor-imp

Member type Definition
allocator_type Alloc

[edit] Member functions of resource-adaptor-imp

resource-adaptor-imp::resource-adaptor-imp

/*resource-adaptor-imp*/() = default;
(1) (library fundamentals TS)
/*resource-adaptor-imp*/(const /*resource-adaptor-imp*/& other)
    = default;
(2) (library fundamentals TS)
/*resource-adaptor-imp*/(/*resource-adaptor-imp*/&& other)
    = default;
(3) (library fundamentals TS)
explicit /*resource-adaptor-imp*/(const Alloc& a2);
(4) (library fundamentals TS)
explicit /*resource-adaptor-imp*/(Alloc&& a2);
(5) (library fundamentals TS)
1) Default constructor. Default constructs the wrapped allocator.
2) Copy constructor. Copy constructs the wrapped allocator from the allocator wrapped by other.
3) Move constructor. Move constructs the wrapped allocator from the allocator wrapped by other.
4) Initializes the wrapped allocator with a2.
5) Initializes the wrapped allocator with std::move(a2).

Parameters

other - another resource-adaptor-imp object to copy or move from
a2 - another Alloc object to copy or move from

resource-adaptor-imp::get_allocator

allocator_type get_allocator() const;
(library fundamentals TS)

Returns a copy of the wrapped allocator.

resource-adaptor-imp::operator=

/*resource-adaptor-imp*/& operator=(const /*resource-adaptor-imp*/& other)
    = default;
(library fundamentals TS)

Defaulted copy assignment operator. Copy assigns the wrapped allocator from that of other.

resource-adaptor-imp::do_allocate

protected:
virtual void* do_allocate(std::size_t bytes, std::size_t alignment);
(library fundamentals TS)

Allocates memory using the allocate member function of the wrapped allocator.

resource-adaptor-imp::do_deallocate

protected:
virtual void do_deallocate(void *p, std::size_t bytes, std::size_t alignment);
(library fundamentals TS)

Deallocates the storage pointed to by p using the deallocate member function of the wrapped allocator.

p must have been allocated using the allocate member function of an allocator that compares equal to the wrapped allocator, and must not have been subsequently deallocated.

resource-adaptor-imp::do_is_equal

protected:
virtual bool do_is_equal(const memory_resource& other) const noexcept;
(library fundamentals TS)

Let p be dynamic_cast<const /*resource-adaptor-imp*/*>(&other). If p is a null pointer value, returns false. Otherwise, return the result of comparing the allocators wrapped by *p and *this using operator==.