STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
stl_construct.h File Reference
#include <new>
#include <bits/move.h>
#include <ext/alloc_traits.h>

Go to the source code of this file.

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers. Do not attempt to use it directly. {memory}

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

Constructs an object in existing memory by invoking an allocated object's constructor with an initializer.

Destroy the object pointed to by a pointer type.

Destroy a range of objects. If the value_type of the object has a trivial destructor, the compiler should optimize all of this away, otherwise the objects' destructors must be invoked.

Destroy a range of objects using the supplied allocator. For nondefault allocators we do not optimize away invocation of destroy() even if _Tp has a trivial destructor.

64 {
65 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 
71 #if __cplusplus >= 201103L
72  template<typename _T1, typename... _Args>
73  inline void
74  _Construct(_T1* __p, _Args&&... __args)
75  { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
76 #else
77  template<typename _T1, typename _T2>
78  inline void
79  _Construct(_T1* __p, const _T2& __value)
80  {
81  // _GLIBCXX_RESOLVE_LIB_DEFECTS
82  // 402. wrong new expression in [some_]allocator::construct
83  ::new(static_cast<void*>(__p)) _T1(__value);
84  }
85 #endif
86 
90  template<typename _Tp>
91  inline void
92  _Destroy(_Tp* __pointer)
93  { __pointer->~_Tp(); }
94 
95  template<bool>
96  struct _Destroy_aux
97  {
98  template<typename _ForwardIterator>
99  static void
100  __destroy(_ForwardIterator __first, _ForwardIterator __last)
101  {
102  for (; __first != __last; ++__first)
103  std::_Destroy(std::__addressof(*__first));
104  }
105  };
106 
107  template<>
108  struct _Destroy_aux<true>
109  {
110  template<typename _ForwardIterator>
111  static void
112  __destroy(_ForwardIterator, _ForwardIterator) { }
113  };
114 
120  template<typename _ForwardIterator>
121  inline void
122  _Destroy(_ForwardIterator __first, _ForwardIterator __last)
123  {
124  typedef typename iterator_traits<_ForwardIterator>::value_type
125  _Value_type;
126  std::_Destroy_aux<__has_trivial_destructor(_Value_type)>::
127  __destroy(__first, __last);
128  }
129 
136  template<typename _ForwardIterator, typename _Allocator>
137  void
138  _Destroy(_ForwardIterator __first, _ForwardIterator __last,
139  _Allocator& __alloc)
140  {
141  typedef __gnu_cxx::__alloc_traits<_Allocator> __traits;
142  for (; __first != __last; ++__first)
143  __traits::destroy(__alloc, std::__addressof(*__first));
144  }
145 
146  template<typename _ForwardIterator, typename _Tp>
147  inline void
148  _Destroy(_ForwardIterator __first, _ForwardIterator __last,
149  allocator<_Tp>&)
150  {
151  _Destroy(__first, __last);
152  }
153 
154 _GLIBCXX_END_NAMESPACE_VERSION
155 } // namespace std
#define true
Definition: stdbool.h:34