From Jason Turner

[memory]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp0mp1540v/{from.md → to.md} +52 -40
tmp/tmp0mp1540v/{from.md → to.md} RENAMED
@@ -2,20 +2,20 @@
2
 
3
  ### In general <a id="memory.general">[[memory.general]]</a>
4
 
5
  This subclause describes the contents of the header `<memory>` (
6
  [[memory.syn]]) and some of the contents of the C headers `<cstdlib>`
7
- and `cstring>` ([[c.malloc]]).
8
 
9
  ### Header `<memory>` synopsis <a id="memory.syn">[[memory.syn]]</a>
10
 
11
  The header `<memory>` defines several types and function templates that
12
  describe properties of pointers and pointer-like types, manage memory
13
  for containers and other template types, and construct multiple objects
14
  in uninitialized memory buffers ([[pointer.traits]]–
15
  [[specialized.algorithms]]). The header also defines the templates
16
- `unique_ptr`, `shared_ptr`, `weak_ptr`, and various template functions
17
  that operate on objects of these types ([[smartptr]]).
18
 
19
  ``` cpp
20
  namespace std {
21
  // [pointer.traits], pointer traits
@@ -34,11 +34,11 @@ namespace std {
34
  void* align(std::size_t alignment, std::size_t size,
35
  void*& ptr, std::size_t& space);
36
 
37
  // [allocator.tag], allocator argument tag
38
  struct allocator_arg_t { };
39
- constexpr allocator_arg_t allocator_arg = allocator_arg_t();
40
 
41
  // [allocator.uses], uses_allocator
42
  template <class T, class Alloc> struct uses_allocator;
43
 
44
  // [allocator.traits], allocator traits
@@ -79,10 +79,16 @@ namespace std {
79
  template <class T> struct default_delete;
80
  template <class T> struct default_delete<T[]>;
81
  template <class T, class D = default_delete<T>> class unique_ptr;
82
  template <class T, class D> class unique_ptr<T[], D>;
83
 
 
 
 
 
 
 
84
  template <class T1, class D1, class T2, class D2>
85
  bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
86
  template <class T1, class D1, class T2, class D2>
87
  bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
88
  template <class T1, class D1, class T2, class D2>
@@ -123,10 +129,15 @@ namespace std {
123
  class bad_weak_ptr;
124
 
125
  // [util.smartptr.shared], class template shared_ptr:
126
  template<class T> class shared_ptr;
127
 
 
 
 
 
 
128
  // [util.smartptr.shared.cmp], shared_ptr comparisons:
129
  template<class T, class U>
130
  bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
131
  template<class T, class U>
132
  bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
@@ -300,18 +311,18 @@ arguments; otherwise, the instantiation of `rebind` is ill-formed.
300
  ``` cpp
301
  static pointer pointer_traits::pointer_to(see below r);
302
  static pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
303
  ```
304
 
305
- if `element_type` is (possibly cv-qualified) `void`, the type of `r` is
306
  unspecified; otherwise, it is `element_type&`.
307
 
308
- *Returns:* The first member function returns a dereferenceable pointer
309
- to `r` obtained by calling `Ptr::pointer_to(r)`; an instantiation of
310
- this function is ill-formed if `Ptr` does not have a matching
311
- `pointer_to` static member function. The second member function returns
312
- `std::addressof(r)`.
313
 
314
  ### Pointer safety <a id="util.dynamic.safety">[[util.dynamic.safety]]</a>
315
 
316
  A complete object is *declared reachable* while the number of calls to
317
  `declare_reachable` with an argument referencing the object exceeds the
@@ -362,15 +373,15 @@ object must be live until the corresponding `undeclare_no_pointers()`
362
  call. In a garbage-collecting implementation, the fact that a region in
363
  an object is registered with `declare_no_pointers()` should not prevent
364
  the object from being collected.
365
 
366
  *Effects:* The `n` bytes starting at `p` no longer contain traceable
367
- pointer locations, independent of their type. Hence pointers located
368
- there may not be dereferenced if the object they point to was created by
369
- global `operator new` and not previously declared reachable. This may be
370
- used to inform a garbage collector or leak detector that this region of
371
- memory need not be traced.
372
 
373
  *Throws:* Nothing.
374
 
375
  Under some conditions implementations may need to allocate memory.
376
  However, the request can be ignored if memory allocation fails.
@@ -427,11 +438,11 @@ arguments for the same buffer.
427
  ### Allocator argument tag <a id="allocator.tag">[[allocator.tag]]</a>
428
 
429
  ``` cpp
430
  namespace std {
431
  struct allocator_arg_t { };
432
- constexpr allocator_arg_t allocator_arg = allocator_arg_t();
433
  }
434
  ```
435
 
436
  The `allocator_arg_t` struct is an empty structure type used as a unique
437
  type to disambiguate constructor and function overloading. Specifically,
@@ -525,11 +536,11 @@ namespace std {
525
  static void construct(Alloc& a, T* p, Args&&... args);
526
 
527
  template <class T>
528
  static void destroy(Alloc& a, T* p);
529
 
530
- static size_type max_size(const Alloc& a);
531
 
532
  static Alloc select_on_container_copy_construction(const Alloc& rhs);
533
  };
534
  }
535
  ```
@@ -574,11 +585,11 @@ typedef see below difference_type;
574
  ``` cpp
575
  typedef see below size_type;
576
  ```
577
 
578
  *Type:* `Alloc::size_type` if such a type exists; otherwise,
579
- `make_unsigned<difference_type>::type`.
580
 
581
  ``` cpp
582
  typedef see below propagate_on_container_copy_assignment;
583
  ```
584
 
@@ -647,11 +658,11 @@ template <class T>
647
 
648
  *Effects:* calls `a.destroy(p)` if that call is well-formed; otherwise,
649
  invokes `p->~T()`.
650
 
651
  ``` cpp
652
- static size_type max_size(Alloc& a);
653
  ```
654
 
655
  *Returns:* `a.max_size()` if that expression is well-formed; otherwise,
656
  `numeric_limits<size_type>::max()`.
657
 
@@ -686,10 +697,11 @@ namespace std {
686
  typedef const T* const_pointer;
687
  typedef T& reference;
688
  typedef const T& const_reference;
689
  typedef T value_type;
690
  template <class U> struct rebind { typedef allocator<U> other; };
 
691
 
692
  allocator() noexcept;
693
  allocator(const allocator&) noexcept;
694
  template <class U> allocator(const allocator<U>&) noexcept;
695
  ~allocator();
@@ -761,11 +773,12 @@ void deallocate(pointer p, size_type n);
761
  shall equal the value passed as the first argument to the invocation of
762
  allocate which returned `p`.
763
 
764
  *Effects:* Deallocates the storage referenced by `p` .
765
 
766
- *Remarks:* Uses `::operator delete(void*)` ([[new.delete]]), but it is
 
767
  unspecified when this function is called.
768
 
769
  ``` cpp
770
  size_type max_size() const noexcept;
771
  ```
@@ -804,11 +817,11 @@ template <class T1, class T2>
804
  *Returns:* `false`.
805
 
806
  ### Raw storage iterator <a id="storage.iterator">[[storage.iterator]]</a>
807
 
808
  `raw_storage_iterator` is provided to enable algorithms to store their
809
- results into uninitialized memory. The formal template parameter
810
  `OutputIterator` is required to have its `operator*` return an object
811
  for which `operator&` is defined and returns a pointer to `T`, and is
812
  also required to satisfy the requirements of an output iterator (
813
  [[output.iterators]]).
814
 
@@ -818,14 +831,14 @@ namespace std {
818
  class raw_storage_iterator
819
  : public iterator<output_iterator_tag,void,void,void,void> {
820
  public:
821
  explicit raw_storage_iterator(OutputIterator x);
822
 
823
- raw_storage_iterator<OutputIterator,T>& operator*();
824
- raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
825
- raw_storage_iterator<OutputIterator,T>& operator++();
826
- raw_storage_iterator<OutputIterator,T> operator++(int);
827
  };
828
  }
829
  ```
830
 
831
  ``` cpp
@@ -834,33 +847,33 @@ explicit raw_storage_iterator(OutputIterator x);
834
 
835
  *Effects:* Initializes the iterator to point to the same value to which
836
  `x` points.
837
 
838
  ``` cpp
839
- raw_storage_iterator<OutputIterator,T>& operator*();
840
  ```
841
 
842
  *Returns:* `*this`
843
 
844
  ``` cpp
845
- raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
846
  ```
847
 
848
  *Effects:* Constructs a value from `element` at the location to which
849
  the iterator points.
850
 
851
  *Returns:* A reference to the iterator.
852
 
853
  ``` cpp
854
- raw_storage_iterator<OutputIterator,T>& operator++();
855
  ```
856
 
857
  *Effects:* Pre-increment: advances the iterator and returns a reference
858
  to the updated iterator.
859
 
860
  ``` cpp
861
- raw_storage_iterator<OutputIterator,T> operator++(int);
862
  ```
863
 
864
  *Effects:* Post-increment: advances the iterator and returns the old
865
  value of the iterator.
866
 
@@ -888,22 +901,21 @@ template <class T> void return_temporary_buffer(T* p);
888
  *Requires:* The buffer shall have been previously allocated by
889
  `get_temporary_buffer`.
890
 
891
  ### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
892
 
893
- All the iterators that are used as formal template parameters in the
894
- following algorithms are required to have their `operator*` return an
895
- object for which `operator&` is defined and returns a pointer to `T`. In
896
- the algorithm `uninitialized_copy`, the formal template parameter
897
- `InputIterator` is required to satisfy the requirements of an input
898
- iterator ([[input.iterators]]). In all of the following algorithms, the
899
- formal template parameter `ForwardIterator` is required to satisfy the
900
- requirements of a forward iterator ([[forward.iterators]]), and is
901
- required to have the property that no exceptions are thrown from
902
- increment, assignment, comparison, or dereference of valid iterators. In
903
- the following algorithms, if an exception is thrown there are no
904
- effects.
905
 
906
  #### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
907
 
908
  ``` cpp
909
  template <class T> T* addressof(T& r) noexcept;
 
2
 
3
  ### In general <a id="memory.general">[[memory.general]]</a>
4
 
5
  This subclause describes the contents of the header `<memory>` (
6
  [[memory.syn]]) and some of the contents of the C headers `<cstdlib>`
7
+ and `<cstring>` ([[c.malloc]]).
8
 
9
  ### Header `<memory>` synopsis <a id="memory.syn">[[memory.syn]]</a>
10
 
11
  The header `<memory>` defines several types and function templates that
12
  describe properties of pointers and pointer-like types, manage memory
13
  for containers and other template types, and construct multiple objects
14
  in uninitialized memory buffers ([[pointer.traits]]–
15
  [[specialized.algorithms]]). The header also defines the templates
16
+ `unique_ptr`, `shared_ptr`, `weak_ptr`, and various function templates
17
  that operate on objects of these types ([[smartptr]]).
18
 
19
  ``` cpp
20
  namespace std {
21
  // [pointer.traits], pointer traits
 
34
  void* align(std::size_t alignment, std::size_t size,
35
  void*& ptr, std::size_t& space);
36
 
37
  // [allocator.tag], allocator argument tag
38
  struct allocator_arg_t { };
39
+ constexpr allocator_arg_t allocator_arg{};
40
 
41
  // [allocator.uses], uses_allocator
42
  template <class T, class Alloc> struct uses_allocator;
43
 
44
  // [allocator.traits], allocator traits
 
79
  template <class T> struct default_delete;
80
  template <class T> struct default_delete<T[]>;
81
  template <class T, class D = default_delete<T>> class unique_ptr;
82
  template <class T, class D> class unique_ptr<T[], D>;
83
 
84
+ template <class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
85
+ template <class T> unique_ptr<T> make_unique(size_t n);
86
+ template <class T, class... Args> unspecified make_unique(Args&&...) = delete;
87
+
88
+ template <class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
89
+
90
  template <class T1, class D1, class T2, class D2>
91
  bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
92
  template <class T1, class D1, class T2, class D2>
93
  bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
94
  template <class T1, class D1, class T2, class D2>
 
129
  class bad_weak_ptr;
130
 
131
  // [util.smartptr.shared], class template shared_ptr:
132
  template<class T> class shared_ptr;
133
 
134
+ // [util.smartptr.shared.create], shared_ptr creation
135
+ template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
136
+ template<class T, class A, class... Args>
137
+ shared_ptr<T> allocate_shared(const A& a, Args&&... args);
138
+
139
  // [util.smartptr.shared.cmp], shared_ptr comparisons:
140
  template<class T, class U>
141
  bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
142
  template<class T, class U>
143
  bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
 
311
  ``` cpp
312
  static pointer pointer_traits::pointer_to(see below r);
313
  static pointer pointer_traits<T*>::pointer_to(see below r) noexcept;
314
  ```
315
 
316
+ If `element_type` is (possibly cv-qualified) `void`, the type of `r` is
317
  unspecified; otherwise, it is `element_type&`.
318
 
319
+ *Returns:* The first member function returns a pointer to `r` obtained
320
+ by calling `Ptr::pointer_to(r)` through which indirection is valid; an
321
+ instantiation of this function is ill-formed if `Ptr` does not have a
322
+ matching `pointer_to` static member function. The second member function
323
+ returns `std::addressof(r)`.
324
 
325
  ### Pointer safety <a id="util.dynamic.safety">[[util.dynamic.safety]]</a>
326
 
327
  A complete object is *declared reachable* while the number of calls to
328
  `declare_reachable` with an argument referencing the object exceeds the
 
373
  call. In a garbage-collecting implementation, the fact that a region in
374
  an object is registered with `declare_no_pointers()` should not prevent
375
  the object from being collected.
376
 
377
  *Effects:* The `n` bytes starting at `p` no longer contain traceable
378
+ pointer locations, independent of their type. Hence indirection through
379
+ a pointer located there is undefined if the object it points to was
380
+ created by global `operator new` and not previously declared reachable.
381
+ This may be used to inform a garbage collector or leak detector that
382
+ this region of memory need not be traced.
383
 
384
  *Throws:* Nothing.
385
 
386
  Under some conditions implementations may need to allocate memory.
387
  However, the request can be ignored if memory allocation fails.
 
438
  ### Allocator argument tag <a id="allocator.tag">[[allocator.tag]]</a>
439
 
440
  ``` cpp
441
  namespace std {
442
  struct allocator_arg_t { };
443
+ constexpr allocator_arg_t allocator_arg{};
444
  }
445
  ```
446
 
447
  The `allocator_arg_t` struct is an empty structure type used as a unique
448
  type to disambiguate constructor and function overloading. Specifically,
 
536
  static void construct(Alloc& a, T* p, Args&&... args);
537
 
538
  template <class T>
539
  static void destroy(Alloc& a, T* p);
540
 
541
+ static size_type max_size(const Alloc& a) noexcept;
542
 
543
  static Alloc select_on_container_copy_construction(const Alloc& rhs);
544
  };
545
  }
546
  ```
 
585
  ``` cpp
586
  typedef see below size_type;
587
  ```
588
 
589
  *Type:* `Alloc::size_type` if such a type exists; otherwise,
590
+ `make_unsigned_t<difference_type>`.
591
 
592
  ``` cpp
593
  typedef see below propagate_on_container_copy_assignment;
594
  ```
595
 
 
658
 
659
  *Effects:* calls `a.destroy(p)` if that call is well-formed; otherwise,
660
  invokes `p->~T()`.
661
 
662
  ``` cpp
663
+ static size_type max_size(const Alloc& a) noexcept;
664
  ```
665
 
666
  *Returns:* `a.max_size()` if that expression is well-formed; otherwise,
667
  `numeric_limits<size_type>::max()`.
668
 
 
697
  typedef const T* const_pointer;
698
  typedef T& reference;
699
  typedef const T& const_reference;
700
  typedef T value_type;
701
  template <class U> struct rebind { typedef allocator<U> other; };
702
+ typedef true_type propagate_on_container_move_assignment;
703
 
704
  allocator() noexcept;
705
  allocator(const allocator&) noexcept;
706
  template <class U> allocator(const allocator<U>&) noexcept;
707
  ~allocator();
 
773
  shall equal the value passed as the first argument to the invocation of
774
  allocate which returned `p`.
775
 
776
  *Effects:* Deallocates the storage referenced by `p` .
777
 
778
+ *Remarks:* Uses
779
+ `::operator delete(void*, std::size_t)` ([[new.delete]]), but it is
780
  unspecified when this function is called.
781
 
782
  ``` cpp
783
  size_type max_size() const noexcept;
784
  ```
 
817
  *Returns:* `false`.
818
 
819
  ### Raw storage iterator <a id="storage.iterator">[[storage.iterator]]</a>
820
 
821
  `raw_storage_iterator` is provided to enable algorithms to store their
822
+ results into uninitialized memory. The template parameter
823
  `OutputIterator` is required to have its `operator*` return an object
824
  for which `operator&` is defined and returns a pointer to `T`, and is
825
  also required to satisfy the requirements of an output iterator (
826
  [[output.iterators]]).
827
 
 
831
  class raw_storage_iterator
832
  : public iterator<output_iterator_tag,void,void,void,void> {
833
  public:
834
  explicit raw_storage_iterator(OutputIterator x);
835
 
836
+ raw_storage_iterator& operator*();
837
+ raw_storage_iterator& operator=(const T& element);
838
+ raw_storage_iterator& operator++();
839
+ raw_storage_iterator operator++(int);
840
  };
841
  }
842
  ```
843
 
844
  ``` cpp
 
847
 
848
  *Effects:* Initializes the iterator to point to the same value to which
849
  `x` points.
850
 
851
  ``` cpp
852
+ raw_storage_iterator& operator*();
853
  ```
854
 
855
  *Returns:* `*this`
856
 
857
  ``` cpp
858
+ raw_storage_iterator& operator=(const T& element);
859
  ```
860
 
861
  *Effects:* Constructs a value from `element` at the location to which
862
  the iterator points.
863
 
864
  *Returns:* A reference to the iterator.
865
 
866
  ``` cpp
867
+ raw_storage_iterator& operator++();
868
  ```
869
 
870
  *Effects:* Pre-increment: advances the iterator and returns a reference
871
  to the updated iterator.
872
 
873
  ``` cpp
874
+ raw_storage_iterator operator++(int);
875
  ```
876
 
877
  *Effects:* Post-increment: advances the iterator and returns the old
878
  value of the iterator.
879
 
 
901
  *Requires:* The buffer shall have been previously allocated by
902
  `get_temporary_buffer`.
903
 
904
  ### Specialized algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
905
 
906
+ All the iterators that are used as template parameters in the following
907
+ algorithms are required to have their `operator*` return an object for
908
+ which `operator&` is defined and returns a pointer to `T`. In the
909
+ algorithm `uninitialized_copy`, the template parameter `InputIterator`
910
+ is required to satisfy the requirements of an input iterator (
911
+ [[input.iterators]]). In all of the following algorithms, the template
912
+ parameter `ForwardIterator` is required to satisfy the requirements of a
913
+ forward iterator ([[forward.iterators]]), and is required to have the
914
+ property that no exceptions are thrown from increment, assignment,
915
+ comparison, or indirection through valid iterators. In the following
916
+ algorithms, if an exception is thrown there are no effects.
 
917
 
918
  #### `addressof` <a id="specialized.addressof">[[specialized.addressof]]</a>
919
 
920
  ``` cpp
921
  template <class T> T* addressof(T& r) noexcept;