1 : // memory standard header
2 : #pragma once
3 : #ifndef _MEMORY_
4 : #define _MEMORY_
5 : #ifndef RC_INVOKED
6 : #include <iterator>
7 : #include <xmemory>
8 :
9 : #ifdef _MSC_VER
10 : #pragma pack(push,_CRT_PACKING)
11 : #pragma warning(push,3)
12 : #endif /* _MSC_VER */
13 : _STD_BEGIN
14 :
15 : // TEMPLATE FUNCTION get_temporary_buffer
16 : template<class _Ty> inline
17 : pair<_Ty _FARQ *, _PDFT>
18 : get_temporary_buffer(_PDFT _Count)
19 : { // get raw temporary buffer of up to _Count elements
20 : _Ty _FARQ *_Pbuf;
21 :
22 : if (_Count <= 0)
23 : _Count = 0;
24 : else if (((size_t)(-1) / _Count) < sizeof (_Ty))
25 : _THROW_NCEE(std::bad_alloc, NULL);
26 :
27 : for (_Pbuf = 0; 0 < _Count; _Count /= 2)
28 : if ((_Pbuf = (_Ty _FARQ *)operator new(
29 : (_SIZT)_Count * sizeof (_Ty), nothrow)) != 0)
30 : break;
31 :
32 : return (pair<_Ty _FARQ *, _PDFT>(_Pbuf, _Count));
33 : }
34 :
35 : // TEMPLATE FUNCTION return_temporary_buffer
36 : template<class _Ty> inline
37 : void return_temporary_buffer(_Ty *_Pbuf)
38 : { // delete raw temporary buffer
39 : operator delete(_Pbuf);
40 : }
41 :
42 : // TEMPLATE FUNCTION uninitialized_copy
43 : template<class _InIt,
44 : class _FwdIt> inline
45 : _FwdIt _Uninit_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
46 : _Nonscalar_ptr_iterator_tag, _Range_checked_iterator_tag)
47 : { // copy [_First, _Last) to raw _Dest, arbitrary type
48 : _DEBUG_RANGE(_First, _Last);
49 : _DEBUG_POINTER(_Dest);
50 : _FwdIt _Next = _Dest;
51 :
52 : _TRY_BEGIN
53 : for (; _First != _Last; ++_Dest, ++_First)
54 : _Construct(&*_Dest, *_First);
55 : _CATCH_ALL
56 : for (; _Next != _Dest; ++_Next)
57 : _Destroy(&*_Next);
58 : _RERAISE;
59 : _CATCH_END
60 : return (_Dest);
61 : }
62 :
63 : template<class _Ty1,
64 : class _Ty2> inline
65 : _Ty2 _Uninit_copy(_Ty1 _First, _Ty1 _Last, _Ty2 _Dest,
66 : _Scalar_ptr_iterator_tag, _Range_checked_iterator_tag)
67 : { // copy [_First, _Last) to raw _Dest, scalar type
68 : _DEBUG_RANGE(_First, _Last);
69 : _DEBUG_POINTER(_Dest);
70 : size_t _Count = (size_t)(_Last - _First);
71 : _Ty2 _Result = _Dest + _Count;
72 : if (_Count > 0)
73 : _CRT_SECURE_MEMMOVE(&*_Dest,
74 : _Count * sizeof (*_First), &*_First,
75 : _Count * sizeof (*_First)); // NB: non-overlapping move
76 : return (_Result);
77 : }
78 :
79 : #if _SECURE_SCL
80 :
81 : template<class _InIt,
82 : class _FwdIt> inline
83 : _IF_CHK(_FwdIt) uninitialized_copy(_InIt _First, _InIt _Last, _FwdIt _Dest)
84 : { // copy [_First, _Last) to raw _Dest
85 : return (_Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Dest,
86 : _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
87 : }
88 :
89 : template<class _InIt, class _FwdElem, size_t _Size>
90 : inline
91 : _FwdElem* uninitialized_copy(_InIt _First, _InIt _Last, _FwdElem (&_Dest)[_Size])
92 : { // copy [_First, _Last) to raw _Dest
93 : return (uninitialized_copy(_First, _Last,
94 : _STDEXT make_checked_array_iterator(_Dest, _Size)).base());
95 : }
96 :
97 : template<class _InIt,
98 : class _FwdIt> inline
99 : _SCL_INSECURE_DEPRECATE
100 : _IF_NOT_CHK(_FwdIt) uninitialized_copy(_InIt _First, _InIt _Last, _FwdIt _Dest)
101 : { // copy [_First, _Last) to raw _Dest
102 : return (_Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Dest,
103 : _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
104 : }
105 :
106 : #else
107 :
108 : template<class _InIt,
109 : class _FwdIt> inline
110 : _FwdIt uninitialized_copy(_InIt _First, _InIt _Last, _FwdIt _Dest)
111 : { // copy [_First, _Last) to raw _Dest
112 : return (_Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Dest,
113 : _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
114 : }
115 :
116 : #endif
117 :
118 : // TEMPLATE FUNCTION _Uninitialized_copy WITH ALLOCATOR
119 : template<class _InIt,
120 : class _FwdIt,
121 : class _Alloc> inline
122 : _FwdIt _Uninit_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
123 : _Alloc& _Al, _Nonscalar_ptr_iterator_tag, _Range_checked_iterator_tag)
124 2 : { // copy [_First, _Last) to raw _Dest, using _Al, arbitrary type
125 2 : _DEBUG_RANGE(_First, _Last);
126 2 : _DEBUG_POINTER(_Dest);
127 2 : _FwdIt _Next = _Dest;
128 :
129 2 : _TRY_BEGIN
130 2 : for (; _First != _Last; ++_Dest, ++_First)
131 2 : _Al.construct(_Dest, *_First);
132 : _CATCH_ALL
133 0 : for (; _Next != _Dest; ++_Next)
134 0 : _Al.destroy(_Next);
135 0 : _RERAISE;
136 0 : _CATCH_END
137 2 : return (_Dest);
138 2 : }
139 :
140 : template<class _InIt,
141 : class _FwdIt,
142 : class _Alloc> inline
143 : _FwdIt _Uninit_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
144 : _Alloc&, _Scalar_ptr_iterator_tag, _Range_checked_iterator_tag)
145 42 : { // copy [_First, _Last) to raw _Dest, scalar type
146 42 : _DEBUG_RANGE(_First, _Last);
147 42 : _DEBUG_POINTER(_Dest);
148 42 : size_t _Count = (size_t)(_Last - _First);
149 42 : _FwdIt _Result = _Dest + _Count;
150 42 : if (_Count > 0)
151 26 : _CRT_SECURE_MEMMOVE(&*_Dest, _Count * sizeof (*_First), &*_First, _Count * sizeof (*_First)); // NB: non-overlapping move
152 42 : return (_Result);
153 42 : }
154 :
155 : #if _SECURE_SCL
156 :
157 : template<class _InIt,
158 : class _FwdIt,
159 : class _Alloc> inline
160 : _IF_CHK(_FwdIt) _Uninitialized_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
161 : _Alloc& _Al)
162 : { // copy [_First, _Last) to raw _Dest, using _Al
163 : return (_Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Dest, _Al,
164 : _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
165 : }
166 :
167 : template<class _InIt, class _FwdElem, class _Alloc, size_t _Size>
168 : inline
169 : _FwdElem* _Uninitialized_copy(_InIt _First, _InIt _Last, _FwdElem (&_Dest)[_Size],
170 : _Alloc& _Al)
171 : { // copy [_First, _Last) to raw _Dest, using _Al
172 : return (_Uninitialized_copy(_First, _Last,
173 : _STDEXT make_checked_array_iterator(_Dest, _Size), _Al).base());
174 : }
175 :
176 : template<class _InIt,
177 : class _FwdIt,
178 : class _Alloc> inline
179 : _SCL_INSECURE_DEPRECATE
180 : _IF_NOT_CHK(_FwdIt) _Uninitialized_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
181 : _Alloc& _Al)
182 : { // copy [_First, _Last) to raw _Dest, using _Al
183 : return (_Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Dest, _Al,
184 : _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
185 : }
186 :
187 : #else
188 :
189 : template<class _InIt,
190 : class _FwdIt,
191 : class _Alloc> inline
192 : _FwdIt _Uninitialized_copy(_InIt _First, _InIt _Last, _FwdIt _Dest,
193 : _Alloc& _Al)
194 : { // copy [_First, _Last) to raw _Dest, using _Al
195 : return (_Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Dest, _Al,
196 : _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
197 : }
198 :
199 : #endif
200 :
201 : // TEMPLATE FUNCTION _Uninitialized_move WITH ALLOCATOR
202 : template<class _InIt, class _FwdIt, class _Alloc, class _MoveCatTy>
203 : inline
204 : _FwdIt _Uninit_move(_InIt _First, _InIt _Last, _FwdIt _Dest,
205 : _Alloc& _Al, _MoveCatTy, _Range_checked_iterator_tag)
206 43 : { // move defaults to copy if there is not a more effecient way
207 43 : return (_STDEXT unchecked_uninitialized_copy(_First, _Last, _Dest, _Al));
208 43 : }
209 :
210 : template<class _InIt, class _FwdIt, class _Alloc>
211 : inline
212 : _FwdIt _Uninit_move(_InIt _First, _InIt _Last, _FwdIt _Dest,
213 : _Alloc& _Al, _Swap_move_tag, _Range_checked_iterator_tag)
214 11 : { // use swap to instead of the copy constructor
215 11 : _DEBUG_RANGE(_First, _Last);
216 11 : _DEBUG_POINTER(_Dest);
217 11 : _FwdIt _Next = _Dest;
218 : // empty value used in the construction
219 11 : typename _Alloc::value_type _Val;
220 :
221 11 : _TRY_BEGIN
222 11 : for (; _First != _Last; ++_Dest, ++_First)
223 : {
224 5 : _Al.construct(_Dest, _Val);
225 5 : _STD _Swap_adl(*_Dest, *_First);
226 11 : }
227 : _CATCH_ALL
228 0 : for (; _Next != _Dest; ++_Next)
229 0 : _Al.destroy(_Next);
230 0 : _RERAISE;
231 0 : _CATCH_END
232 11 : return (_Dest);
233 11 : }
234 :
235 : #if _SECURE_SCL
236 :
237 : template<class _InIt, class _FwdIt, class _Alloc>
238 : inline
239 : _IF_CHK(_FwdIt) _Uninitialized_move(_InIt _First, _InIt _Last, _FwdIt _Dest,
240 : _Alloc& _Al)
241 : { // move [_First, _Last) to raw _Dest, using _Al
242 : return (_Uninit_move(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Dest, _Al,
243 : _Move_cat(_Dest), _STD _Range_checked_iterator_tag()));
244 : }
245 :
246 : template<class _InIt, class _FwdElem, class _Alloc, size_t _Size>
247 : inline
248 : _FwdElem* _Uninitialized_move(_InIt _First, _InIt _Last, _FwdElem (&_Dest)[_Size],
249 : _Alloc& _Al)
250 : { // move [_First, _Last) to raw _Dest, using _Al
251 : return (_Uninitialized_move(_First, _Last,
252 : _STDEXT make_checked_array_iterator(_Dest, _Size), _Al).base());
253 : }
254 :
255 : template<class _InIt, class _FwdIt, class _Alloc>
256 : inline
257 : _SCL_INSECURE_DEPRECATE
258 : _IF_NOT_CHK(_FwdIt) _Uninitialized_move(_InIt _First, _InIt _Last, _FwdIt _Dest,
259 : _Alloc& _Al)
260 : { // move [_First, _Last) to raw _Dest, using _Al
261 : return (_Uninit_move(_CHECKED_BASE(_First),
262 : _CHECKED_BASE(_Last), _Dest, _Al,
263 : _Move_cat(_Dest), _STD _Range_checked_iterator_tag()));
264 : }
265 :
266 : #else
267 :
268 : template<class _InIt, class _FwdIt, class _Alloc>
269 : inline
270 : _FwdIt _Uninitialized_move(_InIt _First, _InIt _Last, _FwdIt _Dest,
271 : _Alloc& _Al)
272 : { // move [_First, _Last) to raw _Dest, using _Al
273 : return (_Uninit_move(_CHECKED_BASE(_First),
274 : _CHECKED_BASE(_Last), _Dest, _Al,
275 : _Move_cat(_Dest), _STD _Range_checked_iterator_tag()));
276 : }
277 :
278 : #endif
279 :
280 : // TEMPLATE FUNCTION uninitialized_fill
281 : template<class _FwdIt,
282 : class _Tval> inline
283 : void _Uninit_fill(_FwdIt _First, _FwdIt _Last, const _Tval& _Val,
284 : _Nonscalar_ptr_iterator_tag)
285 : { // copy _Val throughout raw [_First, _Last), arbitrary type
286 : _DEBUG_RANGE(_First, _Last);
287 : _FwdIt _Next = _First;
288 :
289 : _TRY_BEGIN
290 : for (; _First != _Last; ++_First)
291 : _Construct(&*_First, _Val);
292 : _CATCH_ALL
293 : for (; _Next != _First; ++_Next)
294 : _Destroy(&*_Next);
295 : _RERAISE;
296 : _CATCH_END
297 : }
298 :
299 : template<class _Ty,
300 : class _Tval> inline
301 : void _Uninit_fill(_Ty *_First, _Ty *_Last, const _Tval& _Val,
302 : _Scalar_ptr_iterator_tag)
303 : { // copy _Val throughout raw [_First, _Last), scalar type
304 : std::fill(_First, _Last, _Val);
305 : }
306 :
307 : template<class _FwdIt,
308 : class _Tval> inline
309 : void uninitialized_fill(_FwdIt _First, _FwdIt _Last, const _Tval& _Val)
310 : { // copy _Val throughout raw [_First, _Last)
311 : _Uninit_fill(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Val, _Ptr_cat(_First, _First));
312 : }
313 :
314 : // TEMPLATE FUNCTION uninitialized_fill_n
315 : template<class _FwdIt,
316 : class _Diff,
317 : class _Tval> inline
318 : void _Uninit_fill_n(_FwdIt _First, _Diff _Count, const _Tval& _Val,
319 : _Nonscalar_ptr_iterator_tag, _Range_checked_iterator_tag)
320 : { // copy _Count *_Val to raw _First, arbitrary type
321 :
322 : #if _HAS_ITERATOR_DEBUGGING
323 : // if (_Count < 0)
324 : // _DEBUG_ERROR("negative count in uninitialized fill");
325 : #endif /* _HAS_ITERATOR_DEBUGGING */
326 :
327 : _FwdIt _Next = _First;
328 :
329 : _TRY_BEGIN
330 : for (; 0 < _Count; --_Count, ++_First)
331 : _Construct(&*_First, _Val);
332 : _CATCH_ALL
333 : for (; _Next != _First; ++_Next)
334 : _Destroy(&*_Next);
335 : _RERAISE;
336 : _CATCH_END
337 : }
338 :
339 : template<class _FwdIt,
340 : class _Diff,
341 : class _Tval> inline
342 : void _Uninit_fill_n(_FwdIt _First, _Diff _Count, const _Tval& _Val,
343 : _Scalar_ptr_iterator_tag, _Range_checked_iterator_tag)
344 : { // copy _Count *_Val to raw _First, scalar type
345 : _STDEXT unchecked_fill_n(&*_First, _Count, _Val);
346 : }
347 :
348 : #if _SECURE_SCL
349 :
350 : template<class _FwdIt,
351 : class _Diff,
352 : class _Tval> inline
353 : _IF_CHK_(_FwdIt, void) uninitialized_fill_n(_FwdIt _First, _Diff _Count, const _Tval& _Val)
354 : { // copy _Count *_Val to raw _First
355 : _Uninit_fill_n(_First, _Count, _Val, _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
356 : }
357 :
358 : template<class _FwdElem, class _Diff, class _Tval, size_t _Size>
359 : inline
360 : void uninitialized_fill_n(_FwdElem (&_First)[_Size], _Diff _Count, const _Tval& _Val)
361 : { // copy _Count *_Val to raw _First
362 : uninitialized_fill_n(_STDEXT make_checked_array_iterator(_First, _Size), _Count, _Val);
363 : }
364 :
365 : template<class _FwdIt,
366 : class _Diff,
367 : class _Tval> inline
368 : _SCL_INSECURE_DEPRECATE
369 : _IF_NOT_CHK_(_FwdIt, void) uninitialized_fill_n(_FwdIt _First, _Diff _Count, const _Tval& _Val)
370 : { // copy _Count *_Val to raw _First
371 : _Uninit_fill_n(_First, _Count, _Val, _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
372 : }
373 :
374 : #else
375 :
376 : template<class _FwdIt,
377 : class _Diff,
378 : class _Tval> inline
379 : void uninitialized_fill_n(_FwdIt _First, _Diff _Count, const _Tval& _Val)
380 : { // copy _Count *_Val to raw _First
381 : _Uninit_fill_n(_First, _Count, _Val, _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
382 : }
383 :
384 : #endif
385 :
386 : // TEMPLATE FUNCTION _Uninitialized_fill_n WITH ALLOCATOR
387 : template<class _FwdIt,
388 : class _Diff,
389 : class _Tval,
390 : class _Alloc> inline
391 : void _Uninit_fill_n(_FwdIt _First, _Diff _Count,
392 : const _Tval& _Val, _Alloc& _Al, _Nonscalar_ptr_iterator_tag, _Range_checked_iterator_tag)
393 13 : { // copy _Count *_Val to raw _First, using _Al, arbitrary type
394 :
395 : #if _HAS_ITERATOR_DEBUGGING
396 : // if (_Count < 0)
397 : // _DEBUG_ERROR("negative count in uninitialized fill");
398 : #endif /* _HAS_ITERATOR_DEBUGGING */
399 :
400 13 : _FwdIt _Next = _First;
401 :
402 13 : _TRY_BEGIN
403 13 : for (; 0 < _Count; --_Count, ++_First)
404 13 : _Al.construct(_First, _Val);
405 : _CATCH_ALL
406 0 : for (; _Next != _First; ++_Next)
407 0 : _Al.destroy(_Next);
408 0 : _RERAISE;
409 0 : _CATCH_END
410 13 : }
411 :
412 : template<class _FwdIt,
413 : class _Diff,
414 : class _Tval,
415 : class _Alloc> inline
416 : void _Uninit_fill_n(_FwdIt _First, _Diff _Count,
417 : const _Tval& _Val, _Alloc&, _Scalar_ptr_iterator_tag, _Range_checked_iterator_tag)
418 41 : { // copy _Count *_Val to raw _First, using _Al, scalar type
419 41 : _STDEXT unchecked_fill_n(_First, _Count, _Val);
420 41 : }
421 :
422 : #if _SECURE_SCL
423 :
424 : template<class _FwdIt,
425 : class _Diff,
426 : class _Tval,
427 : class _Alloc> inline
428 : _IF_CHK_(_FwdIt, void) _Uninitialized_fill_n(_FwdIt _First, _Diff _Count,
429 : const _Tval& _Val, _Alloc& _Al)
430 : { // copy _Count *_Val to raw _First, using _Al
431 : _Uninit_fill_n(_First, _Count, _Val, _Al,
432 : _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
433 : }
434 :
435 : template<class _FwdElem, class _Diff, class _Tval, class _Alloc, size_t _Size>
436 : inline
437 : void _Uninitialized_fill_n(_FwdElem (&_First)[_Size], _Diff _Count,
438 : const _Tval& _Val, _Alloc& _Al)
439 : { // copy _Count *_Val to raw _First, using _Al
440 : _Uninitialized_fill_n(_STDEXT make_checked_array_iterator(_First, _Size), _Count, _Val, _Al);
441 : }
442 :
443 : template<class _FwdIt,
444 : class _Diff,
445 : class _Tval,
446 : class _Alloc> inline
447 : _SCL_INSECURE_DEPRECATE
448 : _IF_NOT_CHK_(_FwdIt, void) _Uninitialized_fill_n(_FwdIt _First, _Diff _Count,
449 : const _Tval& _Val, _Alloc& _Al)
450 : { // copy _Count *_Val to raw _First, using _Al
451 : _Uninit_fill_n(_First, _Count, _Val, _Al,
452 : _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
453 : }
454 :
455 : #else
456 :
457 : template<class _FwdIt,
458 : class _Diff,
459 : class _Tval,
460 : class _Alloc> inline
461 : void _Uninitialized_fill_n(_FwdIt _First, _Diff _Count,
462 : const _Tval& _Val, _Alloc& _Al)
463 : { // copy _Count *_Val to raw _First, using _Al
464 : _Uninit_fill_n(_First, _Count, _Val, _Al,
465 : _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
466 : }
467 :
468 : #endif
469 :
470 : // TEMPLATE CLASS raw_storage_iterator
471 : template<class _FwdIt,
472 : class _Ty>
473 : class raw_storage_iterator
474 : : public _Outit
475 : { // wrap stores to raw buffer as output iterator
476 : public:
477 : typedef _FwdIt iterator_type; // retained
478 : typedef _FwdIt iter_type; // retained
479 : typedef _Ty element_type; // retained
480 :
481 : explicit raw_storage_iterator(_FwdIt _First)
482 : : _Next(_First)
483 : { // construct with iterator
484 : }
485 :
486 : raw_storage_iterator<_FwdIt, _Ty>& operator*()
487 : { // pretend to return designated value
488 : return (*this);
489 : }
490 :
491 : raw_storage_iterator<_FwdIt, _Ty>& operator=(const _Ty& _Val)
492 : { // construct value designated by stored iterator
493 : _Construct(&*_Next, _Val);
494 : return (*this);
495 : }
496 :
497 : raw_storage_iterator<_FwdIt, _Ty>& operator++()
498 : { // preincrement
499 : ++_Next;
500 : return (*this);
501 : }
502 :
503 : raw_storage_iterator<_FwdIt, _Ty> operator++(int)
504 : { // postincrement
505 : raw_storage_iterator<_FwdIt, _Ty> _Ans = *this;
506 : ++_Next;
507 : return (_Ans);
508 : }
509 :
510 : private:
511 : _FwdIt _Next; // the stored iterator
512 : };
513 :
514 : // TEMPLATE CLASS _Temp_iterator
515 : template<class _Ty>
516 : class _Temp_iterator
517 : : public _Outit
518 : { // wrap stores to temporary buffer as output iterator
519 : public:
520 : typedef _Ty _FARQ *_Pty;
521 :
522 : #if _SECURE_SCL
523 : typedef _Range_checked_iterator_tag _Checked_iterator_category;
524 : #endif
525 :
526 : _Temp_iterator(_PDFT _Count = 0)
527 : { // construct from desired temporary buffer size
528 : _Buf._Begin = 0;
529 : _Buf._Current = 0;
530 : _Buf._Hiwater = 0;
531 : _Buf._Size = _Count; // memorize size for lazy allocation
532 : _Pbuf = &_Buf;
533 : }
534 :
535 : _Temp_iterator(const _Temp_iterator<_Ty>& _Right)
536 : { // construct from _Right (share active buffer)
537 : _Buf._Begin = 0; // clear stored buffer, for safe destruction
538 : _Buf._Current = 0;
539 : _Buf._Hiwater = 0;
540 : _Buf._Size = 0;
541 : *this = _Right;
542 : }
543 :
544 : ~_Temp_iterator()
545 : { // destroy the object
546 : if (_Buf._Begin != 0)
547 : { // destroy any constructed elements in buffer
548 : for (_Pty _Next = _Buf._Begin;
549 : _Next != _Buf._Hiwater; ++_Next)
550 : _Destroy(&*_Next);
551 : std::return_temporary_buffer(_Buf._Begin);
552 : }
553 : }
554 :
555 : _Temp_iterator<_Ty>& operator=(const _Temp_iterator<_Ty>& _Right)
556 : { // assign _Right (share active buffer)
557 : _Pbuf = _Right._Pbuf;
558 : return (*this);
559 : }
560 :
561 : _Temp_iterator<_Ty>& operator=(const _Ty& _Val)
562 : { // assign or construct value into active buffer, and increment
563 : if (_Pbuf->_Current < _Pbuf->_Hiwater)
564 : *_Pbuf->_Current++ = _Val; // below high water mark, assign
565 : else
566 : { // above high water mark, construct
567 : _SCL_SECURE_VALIDATE((_Pbuf->_Current - _Pbuf->_Begin) < _Pbuf->_Size);
568 : _Pty _Ptr = &*_Pbuf->_Current;
569 : _Construct(_Ptr, _Val);
570 : _Pbuf->_Hiwater = ++_Pbuf->_Current;
571 : }
572 : return (*this);
573 : }
574 :
575 : _Temp_iterator<_Ty>& operator*()
576 : { // pretend to return designated value
577 : return (*this);
578 : }
579 :
580 : _Temp_iterator<_Ty>& operator++()
581 : { // pretend to preincrement
582 : return (*this);
583 : }
584 :
585 : _Temp_iterator<_Ty>& operator++(int)
586 : { // pretend to postincrement
587 : return (*this);
588 : }
589 :
590 : _Temp_iterator<_Ty>& _Init()
591 : { // set pointer at beginning of buffer
592 : _Pbuf->_Current = _Pbuf->_Begin;
593 : return (*this);
594 : }
595 :
596 : _Pty _First() const
597 : { // return pointer to beginning of buffer
598 : return (_Pbuf->_Begin);
599 : }
600 :
601 : _Pty _Last() const
602 : { // return pointer past end of buffer contents
603 : return (_Pbuf->_Current);
604 : }
605 :
606 : _PDFT _Maxlen()
607 : { // return size of buffer
608 : if (_Pbuf->_Begin == 0 && 0 < _Pbuf->_Size)
609 : { // allocate buffer on first size query
610 : pair<_Pty, _PDFT> _Pair =
611 : std::get_temporary_buffer<_Ty>(_Pbuf->_Size);
612 :
613 : _Pbuf->_Begin = _Pair.first;
614 : _Pbuf->_Current = _Pair.first;
615 : _Pbuf->_Hiwater = _Pair.first;
616 : _Pbuf->_Size = _Pair.second;
617 : }
618 : return (_Pbuf->_Size);
619 : }
620 :
621 : static void _Xinvarg()
622 : { // report an invalid_argument error
623 : _THROW(invalid_argument, "invalid _Temp_iterator<T> argument");
624 : }
625 :
626 : private:
627 : struct _Bufpar
628 : { // control information for a temporary buffer
629 : _Pty _Begin; // pointer to beginning of buffer
630 : _Pty _Current; // pointer to next available element
631 : _Pty _Hiwater; // pointer to first unconstructed element
632 : _PDFT _Size; // length of buffer
633 : };
634 : _Bufpar _Buf; // buffer control stored in iterator
635 : _Bufpar *_Pbuf; // pointer to active buffer control
636 : };
637 :
638 : // TEMPLATE CLASS auto_ptr
639 : template<class _Ty>
640 : class auto_ptr;
641 :
642 : template<class _Ty>
643 : struct auto_ptr_ref
644 : { // proxy reference for auto_ptr copying
645 : explicit auto_ptr_ref(_Ty *_Right)
646 : : _Ref(_Right)
647 : { // construct from generic pointer to auto_ptr ptr
648 : }
649 :
650 : _Ty *_Ref; // generic pointer to auto_ptr ptr
651 : };
652 :
653 : template<class _Ty>
654 : class auto_ptr
655 : { // wrap an object pointer to ensure destruction
656 : public:
657 : typedef _Ty element_type;
658 :
659 : explicit auto_ptr(_Ty *_Ptr = 0) _THROW0()
660 : : _Myptr(_Ptr)
661 : { // construct from object pointer
662 : }
663 :
664 : auto_ptr(auto_ptr<_Ty>& _Right) _THROW0()
665 : : _Myptr(_Right.release())
666 : { // construct by assuming pointer from _Right auto_ptr
667 : }
668 :
669 : auto_ptr(auto_ptr_ref<_Ty> _Right) _THROW0()
670 : { // construct by assuming pointer from _Right auto_ptr_ref
671 : _Ty *_Ptr = _Right._Ref;
672 : _Right._Ref = 0; // release old
673 : _Myptr = _Ptr; // reset this
674 : }
675 :
676 : template<class _Other>
677 : operator auto_ptr<_Other>() _THROW0()
678 : { // convert to compatible auto_ptr
679 : return (auto_ptr<_Other>(*this));
680 : }
681 :
682 : template<class _Other>
683 : operator auto_ptr_ref<_Other>() _THROW0()
684 : { // convert to compatible auto_ptr_ref
685 : _Other *_Cvtptr = _Myptr; // test implicit conversion
686 : auto_ptr_ref<_Other> _Ans(_Cvtptr);
687 : _Myptr = 0; // pass ownership to auto_ptr_ref
688 : return (_Ans);
689 : }
690 :
691 :
692 : template<class _Other>
693 : auto_ptr<_Ty>& operator=(auto_ptr<_Other>& _Right) _THROW0()
694 : { // assign compatible _Right (assume pointer)
695 : reset(_Right.release());
696 : return (*this);
697 : }
698 :
699 : template<class _Other>
700 : auto_ptr(auto_ptr<_Other>& _Right) _THROW0()
701 : : _Myptr(_Right.release())
702 : { // construct by assuming pointer from _Right
703 : }
704 :
705 : auto_ptr<_Ty>& operator=(auto_ptr<_Ty>& _Right) _THROW0()
706 : { // assign compatible _Right (assume pointer)
707 : reset(_Right.release());
708 : return (*this);
709 : }
710 :
711 : auto_ptr<_Ty>& operator=(auto_ptr_ref<_Ty> _Right) _THROW0()
712 : { // assign compatible _Right._Ref (assume pointer)
713 : _Ty *_Ptr = _Right._Ref;
714 : _Right._Ref = 0; // release old
715 : reset(_Ptr); // set new
716 : return (*this);
717 : }
718 :
719 : ~auto_ptr()
720 : { // destroy the object
721 : delete _Myptr;
722 : }
723 :
724 : _Ty& operator*() const _THROW0()
725 : { // return designated value
726 :
727 : #if _HAS_ITERATOR_DEBUGGING
728 : if (_Myptr == 0)
729 : _DEBUG_ERROR("auto_ptr not dereferencable");
730 : #endif /* _HAS_ITERATOR_DEBUGGING */
731 :
732 : __analysis_assume(_Myptr);
733 :
734 : return (*get());
735 : }
736 :
737 : _Ty *operator->() const _THROW0()
738 : { // return pointer to class object
739 :
740 : #if _HAS_ITERATOR_DEBUGGING
741 : if (_Myptr == 0)
742 : _DEBUG_ERROR("auto_ptr not dereferencable");
743 : #endif /* _HAS_ITERATOR_DEBUGGING */
744 :
745 : return (get());
746 : }
747 :
748 : _Ty *get() const _THROW0()
749 : { // return wrapped pointer
750 : return (_Myptr);
751 : }
752 :
753 : _Ty *release() _THROW0()
754 : { // return wrapped pointer and give up ownership
755 : _Ty *_Tmp = _Myptr;
756 : _Myptr = 0;
757 : return (_Tmp);
758 : }
759 :
760 : void reset(_Ty* _Ptr = 0)
761 : { // destroy designated object and store new pointer
762 : if (_Ptr != _Myptr)
763 : delete _Myptr;
764 : _Myptr = _Ptr;
765 : }
766 :
767 : private:
768 : _Ty *_Myptr; // the wrapped object pointer
769 : };
770 : _STD_END
771 :
772 : _STDEXT_BEGIN
773 :
774 : template<class _InIt,
775 : class _FwdIt> inline
776 : _FwdIt unchecked_uninitialized_copy(_InIt _First, _InIt _Last,
777 : _FwdIt _Dest)
778 : { // copy [_First, _Last) to raw _Dest
779 : return (_STD _Uninit_copy(_CHECKED_BASE(_First),
780 : _CHECKED_BASE(_Last), _Dest,
781 : _STD _Ptr_cat(_First, _Dest),
782 : _STD _Range_checked_iterator_tag()));
783 : }
784 :
785 : template<class _InIt,
786 : class _FwdIt> inline
787 : _IF_CHK(_FwdIt) checked_uninitialized_copy(_InIt _First, _InIt _Last,
788 : _FwdIt _Dest)
789 : { // copy [_First, _Last) to raw _Dest
790 : return (_STD _Uninit_copy(_CHECKED_BASE(_First),
791 : _CHECKED_BASE(_Last), _Dest,
792 : _STD _Ptr_cat(_First, _Dest),
793 : _STD _Range_checked_iterator_tag()));
794 : }
795 :
796 : template<class _InIt, class _FwdElem, size_t _Size> inline
797 : _FwdElem *checked_uninitialized_copy(_InIt _First, _InIt _Last,
798 : _FwdElem (&_Dest)[_Size])
799 : { // copy [_First, _Last) to raw _Dest
800 : return (checked_uninitialized_copy(_First, _Last,
801 : _STDEXT make_checked_array_iterator(_Dest, _Size)).base());
802 : }
803 :
804 : template<class _InIt,
805 : class _FwdIt> inline
806 : _SCL_CHECKED_ALGORITHM_WARN _IF_NOT_CHK(_FwdIt)
807 : checked_uninitialized_copy(_InIt _First, _InIt _Last, _FwdIt _Dest)
808 : { // copy [_First, _Last) to raw _Dest
809 : return (_STD _Uninit_copy(_CHECKED_BASE(_First),
810 : _CHECKED_BASE(_Last), _Dest,
811 : _STD _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
812 : }
813 :
814 : template<class _InIt,
815 : class _FwdIt,
816 : class _Alloc> inline
817 : _FwdIt unchecked_uninitialized_copy(_InIt _First, _InIt _Last,
818 : _FwdIt _Dest, _Alloc& _Al)
819 44 : { // copy [_First, _Last) to raw _Dest, using _Al
820 : return (_STD _Uninit_copy(_CHECKED_BASE(_First),
821 : _CHECKED_BASE(_Last), _Dest, _Al,
822 44 : _STD _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
823 44 : }
824 :
825 : template<class _InIt,
826 : class _FwdIt,
827 : class _Alloc> inline
828 : _IF_CHK(_FwdIt) checked_uninitialized_copy(_InIt _First, _InIt _Last,
829 : _FwdIt _Dest, _Alloc& _Al)
830 : { // copy [_First, _Last) to raw _Dest, using _Al
831 : return (_STD _Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last),
832 : _Dest, _Al,
833 : _STD _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
834 : }
835 :
836 : template<class _InIt, class _FwdElem, class _Alloc, size_t _Size> inline
837 : _FwdElem *checked_uninitialized_copy(_InIt _First, _InIt _Last,
838 : _FwdElem (&_Dest)[_Size], _Alloc& _Al)
839 : { // copy [_First, _Last) to raw _Dest, using _Al
840 : return (checked_uninitialized_copy(_First, _Last,
841 : _STDEXT make_checked_array_iterator(_Dest, _Size), _Al).base());
842 : }
843 :
844 : template<class _InIt,
845 : class _FwdIt,
846 : class _Alloc> inline
847 : _SCL_CHECKED_ALGORITHM_WARN _IF_NOT_CHK(_FwdIt)
848 : checked_uninitialized_copy(_InIt _First, _InIt _Last,
849 : _FwdIt _Dest, _Alloc& _Al)
850 : { // copy [_First, _Last) to raw _Dest, using _Al
851 : return (_STD _Uninit_copy(_CHECKED_BASE(_First), _CHECKED_BASE(_Last),
852 : _Dest, _Al,
853 : _STD _Ptr_cat(_First, _Dest), _STD _Range_checked_iterator_tag()));
854 : }
855 :
856 : template<class _InIt,
857 : class _FwdIt,
858 : class _Alloc> inline
859 : _FwdIt _Unchecked_uninitialized_move(_InIt _First, _InIt _Last,
860 : _FwdIt _Dest, _Alloc& _Al)
861 54 : { // move [_First, _Last) to raw _Dest, using _Al
862 : return (_STD _Uninit_move(_CHECKED_BASE(_First),
863 : _CHECKED_BASE(_Last), _Dest, _Al,
864 54 : _STD _Move_cat(_Dest), _STD _Range_checked_iterator_tag()));
865 54 : }
866 :
867 : template<class _InIt, class _FwdIt, class _Alloc> inline
868 : _IF_CHK(_FwdIt) _Checked_uninitialized_move(_InIt _First, _InIt _Last,
869 : _FwdIt _Dest, _Alloc& _Al)
870 : { // move [_First, _Last) to raw _Dest, using _Al
871 : return (_STD _Uninit_move(_CHECKED_BASE(_First), _CHECKED_BASE(_Last),
872 : _Dest, _Al,
873 : _STD _Move_cat(_Dest), _STD _Range_checked_iterator_tag()));
874 : }
875 :
876 : template<class _InIt, class _FwdElem, class _Alloc, size_t _Size> inline
877 : _FwdElem *_Checked_uninitialized_move(_InIt _First, _InIt _Last,
878 : _FwdElem (&_Dest)[_Size], _Alloc& _Al)
879 : { // move [_First, _Last) to raw _Dest, using _Al
880 : return (_Checked_uninitialized_move(_First, _Last,
881 : _STDEXT make_checked_array_iterator(_Dest, _Size), _Al).base());
882 : }
883 :
884 : template<class _InIt, class _FwdIt, class _Alloc> inline
885 : _SCL_CHECKED_ALGORITHM_WARN _IF_NOT_CHK(_FwdIt)
886 : _Checked_uninitialized_move(_InIt _First, _InIt _Last,
887 : _FwdIt _Dest, _Alloc& _Al)
888 : { // move [_First, _Last) to raw _Dest, using _Al
889 : return (_STD _Uninit_move(_CHECKED_BASE(_First), _CHECKED_BASE(_Last),
890 : _Dest, _Al,
891 : _STD _Move_cat(_Dest), _STD _Range_checked_iterator_tag()));
892 : }
893 :
894 : template<class _FwdIt,
895 : class _Diff,
896 : class _Tval> inline
897 : void unchecked_uninitialized_fill_n(_FwdIt _First, _Diff _Count,
898 : const _Tval& _Val)
899 : { // copy _Count *_Val to raw _First
900 : _STD _Uninit_fill_n(_First, _Count, _Val,
901 : _STD _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
902 : }
903 :
904 : template<class _FwdIt,
905 : class _Diff,
906 : class _Tval> inline
907 : _IF_CHK_(_FwdIt, void)
908 : checked_uninitialized_fill_n(_FwdIt _First, _Diff _Count,
909 : const _Tval& _Val)
910 : { // copy _Count *_Val to raw _First
911 : _STD _Uninit_fill_n(_First, _Count, _Val,
912 : _STD _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
913 : }
914 :
915 : template<class _FwdElem, class _Diff, class _Tval, size_t _Size> inline
916 : void checked_uninitialized_fill_n(_FwdElem (&_First)[_Size],
917 : _Diff _Count, const _Tval& _Val)
918 : { // copy _Count *_Val to raw _First
919 : checked_uninitialized_fill_n(
920 : _STDEXT make_checked_array_iterator(_First, _Size), _Count, _Val);
921 : }
922 :
923 : template<class _FwdIt,
924 : class _Diff,
925 : class _Tval> inline
926 : _SCL_CHECKED_ALGORITHM_WARN _IF_NOT_CHK_(_FwdIt, void)
927 : checked_uninitialized_fill_n(_FwdIt _First, _Diff _Count,
928 : const _Tval& _Val)
929 : { // copy _Count *_Val to raw _First
930 : _STD _Uninit_fill_n(_First, _Count, _Val,
931 : _STD _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
932 : }
933 :
934 : template<class _FwdIt,
935 : class _Diff,
936 : class _Tval,
937 : class _Alloc> inline
938 : void unchecked_uninitialized_fill_n(_FwdIt _First, _Diff _Count,
939 : const _Tval& _Val, _Alloc& _Al)
940 54 : { // copy _Count *_Val to raw _First, using _Al
941 : _STD _Uninit_fill_n(_First, _Count, _Val, _Al,
942 54 : _STD _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
943 54 : }
944 :
945 : template<class _FwdIt,
946 : class _Diff,
947 : class _Tval,
948 : class _Alloc> inline
949 : _IF_CHK_(_FwdIt, void)
950 : checked_uninitialized_fill_n(_FwdIt _First, _Diff _Count,
951 : const _Tval& _Val, _Alloc& _Al)
952 : { // copy _Count *_Val to raw _First, using _Al
953 : _STD _Uninit_fill_n(_First, _Count, _Val, _Al,
954 : _STD _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
955 : }
956 :
957 : template<class _FwdElem,
958 : class _Diff,
959 : class _Tval,
960 : class _Alloc,
961 : size_t _Size> inline
962 : void checked_uninitialized_fill_n(_FwdElem (&_First)[_Size],
963 : _Diff _Count, const _Tval& _Val, _Alloc& _Al)
964 : { // copy _Count *_Val to raw _First, using _Al
965 : checked_uninitialized_fill_n(
966 : _STDEXT make_checked_array_iterator(_First, _Size),
967 : _Count, _Val, _Al);
968 : }
969 :
970 : template<class _FwdIt,
971 : class _Diff,
972 : class _Tval,
973 : class _Alloc> inline
974 : _SCL_CHECKED_ALGORITHM_WARN _IF_NOT_CHK_(_FwdIt, void)
975 : checked_uninitialized_fill_n(_FwdIt _First, _Diff _Count,
976 : const _Tval& _Val, _Alloc& _Al)
977 : { // copy _Count *_Val to raw _First, using _Al
978 : _STD _Uninit_fill_n(_First, _Count, _Val, _Al,
979 : _STD _Ptr_cat(_First, _First), _STD _Range_checked_iterator_tag());
980 : }
981 :
982 : _STDEXT_END
983 :
984 : #if _HAS_TR1
985 : #ifndef _XSTD2
986 : #define _XSTD2
987 : #endif /* _XSTD2 */
988 :
989 : #include <exception>
990 : #include <typeinfo>
991 :
992 : #ifndef _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY
993 : extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedIncrement(volatile long *);
994 : extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedDecrement(volatile long *);
995 : extern "C" long __CLRCALL_PURE_OR_CDECL _InterlockedCompareExchange(volatile long *,
996 : long, long);
997 :
998 : #pragma intrinsic(_InterlockedIncrement)
999 : #pragma intrinsic(_InterlockedDecrement)
1000 : #pragma intrinsic(_InterlockedCompareExchange)
1001 : #endif /* _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY */
1002 :
1003 : #define _MT_INCR(mtx, x) _InterlockedIncrement(&x)
1004 : #define _MT_DECR(mtx, x) _InterlockedDecrement(&x)
1005 : #define _MT_CMPX(x, y, z) _InterlockedCompareExchange(&x, y, z)
1006 :
1007 : _STD_BEGIN
1008 : namespace tr1 { // TR1 additions
1009 :
1010 : // CLASS bad_weak_ptr
1011 : class bad_weak_ptr
1012 : : public _XSTD exception
1013 : { // exception type for invalid use of expired weak_ptr object
1014 : public:
1015 : explicit bad_weak_ptr(const char * = 0)
1016 : { // construct with ignored message
1017 : }
1018 :
1019 : virtual const char *__CLR_OR_THIS_CALL what() const _THROW0()
1020 : { // return pointer to message string
1021 : return ("tr1::bad_weak_ptr");
1022 : }
1023 : };
1024 :
1025 : _CRTIMP2_PURE __declspec(noreturn) void __CLRCALL_PURE_OR_CDECL _Xweak();
1026 :
1027 : // CLASS _Ref_count_base
1028 : class _Ref_count_base
1029 : { // common code for reference counting
1030 : private:
1031 : virtual void _Destroy() = 0;
1032 : virtual void _Delete_this() = 0;
1033 :
1034 : const volatile void *_Ptr;
1035 : long _Uses;
1036 : long _Weaks;
1037 :
1038 : protected:
1039 : _Ref_count_base(const volatile void *_Px)
1040 : : _Ptr(_Px), _Uses(0), _Weaks(1)
1041 : { // construct
1042 : }
1043 :
1044 : public:
1045 : virtual ~_Ref_count_base()
1046 : { // ensure that derived classes can be destroyed properly
1047 : }
1048 :
1049 : bool _Incref_nz()
1050 : { // increment use count if not zero, return true if successful
1051 : for (; ; )
1052 : { // loop until state is known
1053 : long _Count = (volatile long&)_Uses;
1054 : if (_Count == 0)
1055 : return (false);
1056 : if (_MT_CMPX(_Uses, _Count + 1, _Count) == _Count)
1057 : return (true);
1058 : }
1059 : }
1060 :
1061 : void _Incref()
1062 : { // increment use count
1063 : _MT_INCR(_Mtx, _Uses);
1064 : }
1065 :
1066 : void _Incwref()
1067 : { // increment weak reference count
1068 : _MT_INCR(_Mtx, _Weaks);
1069 : }
1070 :
1071 : void _Decref()
1072 : { // decrement use count
1073 : if (_MT_DECR(_Mtx, _Uses) == 0)
1074 : { // destroy managed resource, decrement weak reference count
1075 : _Destroy();
1076 : _Decwref();
1077 : }
1078 : }
1079 :
1080 : void _Decwref()
1081 : { // decrement weak reference count
1082 : if (_MT_DECR(_Mtx, _Weaks) == 0)
1083 : _Delete_this();
1084 : }
1085 :
1086 : long _Use_count() const
1087 : { // return use count
1088 : return (_Uses);
1089 : }
1090 :
1091 : bool _Expired() const
1092 : { // return true if _Uses == 0
1093 : return (_Uses == 0);
1094 : }
1095 :
1096 : virtual void *_Get_deleter(const _XSTD2 type_info&) const
1097 : { // return address of deleter object
1098 : return (0);
1099 : }
1100 :
1101 : const volatile void *_Getptr() const
1102 : { // return stored pointer
1103 : return (_Ptr);
1104 : }
1105 : };
1106 :
1107 : // TEMPLATE CLASS _Ref_count, _Ref_count_d
1108 : template<class _Ty>
1109 : class _Ref_count
1110 : : public _Ref_count_base
1111 : { // handle reference counting for object without deleter
1112 : public:
1113 : _Ref_count(_Ty *_Px)
1114 : : _Ref_count_base(_Px)
1115 : { // construct
1116 : }
1117 :
1118 : private:
1119 : virtual void _Destroy()
1120 : { // destroy managed resource
1121 : delete (_Ty *)_Getptr();
1122 : }
1123 :
1124 : virtual void _Delete_this()
1125 : { // destroy self
1126 : delete this;
1127 : }
1128 : };
1129 :
1130 : template<class _Ty,
1131 : class _Dx,
1132 : class _Alloc = std::allocator<int> >
1133 : class _Ref_count_d
1134 : : public _Ref_count_base
1135 : { // handle reference counting for object with deleter
1136 : public:
1137 : typedef _Ref_count_d<_Ty, _Dx, _Alloc> _Myty;
1138 : typedef typename _Alloc::template rebind<_Myty>::other _Myalty;
1139 :
1140 : _Ref_count_d(_Ty *_Px, _Dx _Dt, _Myalty _Al = _Myalty())
1141 : : _Ref_count_base(_Px), _Dtor(_Dt), _Myal(_Al)
1142 : { // construct
1143 : }
1144 :
1145 : void *_Get_deleter(const _XSTD2 type_info& _Type) const
1146 : { // return address of deleter object
1147 : return ((void*)(_Type == typeid(_Dx) ? &_Dtor : 0));
1148 : }
1149 :
1150 : private:
1151 : virtual void _Destroy()
1152 : { // destroy managed resource
1153 : _Dtor((_Ty *)_Getptr());
1154 : }
1155 :
1156 : virtual void _Delete_this()
1157 : { // destroy self
1158 : _Myalty _Al = _Myal;
1159 : _Al.destroy(this);
1160 : _Al.deallocate(this, 1);
1161 : }
1162 :
1163 : _Myalty _Myal;
1164 : _Dx _Dtor;
1165 : };
1166 :
1167 : // DECLARATIONS
1168 : template<class _Ty>
1169 : class weak_ptr;
1170 : template<class _Ty>
1171 : class shared_ptr;
1172 : template<class _Ty>
1173 : class enable_shared_from_this;
1174 : struct _Static_tag {};
1175 : struct _Const_tag {};
1176 : struct _Dynamic_tag {};
1177 :
1178 : template<class _Ty1,
1179 : class _Ty2>
1180 : void _Do_enable(_Ty1*, enable_shared_from_this<_Ty2>*, _Ref_count_base*);
1181 :
1182 : template<class _Ty>
1183 : inline void _Enable_shared(_Ty *_Ptr, _Ref_count_base *_Refptr,
1184 : typename _Ty::_EStype* = 0)
1185 : { // reset internal weak pointer
1186 : if (_Ptr)
1187 : _Do_enable(_Ptr,
1188 : (enable_shared_from_this<typename _Ty::_EStype>*)_Ptr, _Refptr);
1189 : }
1190 :
1191 : inline void _Enable_shared(const volatile void *, const volatile void *)
1192 : { // not derived from enable_shared_from_this; do nothing
1193 : }
1194 :
1195 : // TEMPLATE CLASS _Ptr_base
1196 : template<class _Ty>
1197 : class _Ptr_base
1198 : { // base class for shared_ptr and weak_ptr
1199 : public:
1200 : typedef _Ty _Elem;
1201 : typedef _Elem element_type;
1202 :
1203 : _Ptr_base()
1204 : : _Ptr(0), _Rep(0)
1205 : { // construct
1206 : }
1207 :
1208 : long use_count() const
1209 : { // return use count
1210 : return (_Rep ? _Rep->_Use_count() : 0);
1211 : }
1212 :
1213 : void _Swap(_Ptr_base& _Other)
1214 : { // swap pointers
1215 : _STD swap(_Rep, _Other._Rep);
1216 : _STD swap(_Ptr, _Other._Ptr);
1217 : }
1218 :
1219 : template<class _Ty2>
1220 : bool _Cmp(const _Ptr_base<_Ty2>& _Right) const
1221 : { // compare addresses of manager objects
1222 : return (_Rep < _Right._Rep);
1223 : }
1224 :
1225 : void *_Get_deleter(const _XSTD2 type_info& _Type) const
1226 : { // return pointer to deleter object if its type is _Type
1227 : return (_Rep ? _Rep->_Get_deleter(_Type) : 0);
1228 : }
1229 :
1230 : _Ty *_Get() const
1231 : { // return pointer to resource
1232 : return (_Ptr);
1233 : }
1234 :
1235 : bool _Expired() const
1236 : {
1237 : return (!_Rep || _Rep->_Expired());
1238 : }
1239 :
1240 : void _Decref()
1241 : { // decrement reference count
1242 : if (_Rep != 0)
1243 : _Rep->_Decref();
1244 : }
1245 :
1246 : void _Reset()
1247 : { // release resource
1248 : _Reset(0, 0);
1249 : }
1250 :
1251 : template<class _Ty2>
1252 : void _Reset(const _Ptr_base<_Ty2>& _Other)
1253 : { // release resource and take ownership of _Other._Ptr
1254 : _Reset(_Other._Ptr, _Other._Rep);
1255 : }
1256 :
1257 : template<class _Ty2>
1258 : void _Reset(const _Ptr_base<_Ty2>& _Other, bool _Throw)
1259 : { // release resource and take ownership from weak_ptr _Other._Ptr
1260 : _Reset(_Other._Ptr, _Other._Rep, _Throw);
1261 : }
1262 :
1263 : template<class _Ty2>
1264 : void _Reset(const _Ptr_base<_Ty2>& _Other, const _Static_tag&)
1265 : { // release resource and take ownership of _Other._Ptr
1266 : _Reset(static_cast<_Elem*>(_Other._Ptr), _Other._Rep);
1267 : }
1268 :
1269 : template<class _Ty2>
1270 : void _Reset(const _Ptr_base<_Ty2>& _Other, const _Const_tag&)
1271 : { // release resource and take ownership of _Other._Ptr
1272 : _Reset(const_cast<_Elem*>(_Other._Ptr), _Other._Rep);
1273 : }
1274 : template<class _Ty2>
1275 : void _Reset(const _Ptr_base<_Ty2>& _Other, const _Dynamic_tag&)
1276 : { // release resource and take ownership of _Other._Ptr
1277 : _Elem *_Ptr = dynamic_cast<_Elem*>(_Other._Ptr);
1278 : if (_Ptr)
1279 : _Reset(_Ptr, _Other._Rep);
1280 : else
1281 : _Reset();
1282 : }
1283 :
1284 : template<class _Ty2>
1285 : void _Reset(auto_ptr<_Ty2>& _Other)
1286 : { // release resource and take _Other.get()
1287 : _Ty2 *_Px = _Other.get();
1288 : _Reset(_Px, new _Ref_count<_Elem>(_Px));
1289 : _Other.release();
1290 : }
1291 :
1292 : void _Reset(_Ty *_Other_ptr, _Ref_count_base *_Other_rep)
1293 : { // release resource and take _Other_ptr through _Other_rep
1294 : if (_Other_rep)
1295 : _Other_rep->_Incref();
1296 : if (_Rep != 0)
1297 : _Rep->_Decref();
1298 : _Rep = _Other_rep;
1299 : _Ptr = _Other_ptr;
1300 : }
1301 :
1302 : void _Reset(_Ty *_Other_ptr, _Ref_count_base *_Other_rep, bool _Throw)
1303 : { // take _Other_ptr through _Other_rep from weak_ptr if not expired
1304 : // otherwise, leave in default state if !_Throw,
1305 : // otherwise throw exception
1306 : if (_Other_rep && _Other_rep->_Incref_nz())
1307 : { // take pointers
1308 : if (_Rep != 0)
1309 : _Rep->_Decref();
1310 : _Rep = _Other_rep;
1311 : _Ptr = _Other_ptr;
1312 : }
1313 : else if (_Throw)
1314 : _Xweak();
1315 : }
1316 :
1317 : void _Decwref()
1318 : { // decrement weak reference count
1319 : if (_Rep != 0)
1320 : _Rep->_Decwref();
1321 : }
1322 :
1323 : void _Resetw()
1324 : { // release weak reference to resource
1325 : _Resetw((_Elem*)0, 0);
1326 : }
1327 :
1328 : template<class _Ty2>
1329 : void _Resetw(const _Ptr_base<_Ty2>& _Other)
1330 : { // release weak reference to resource and take _Other._Ptr
1331 : _Resetw(_Other._Ptr, _Other._Rep);
1332 : }
1333 :
1334 : template<class _Ty2>
1335 : void _Resetw(const _Ty2 *_Other_ptr, _Ref_count_base *_Other_rep)
1336 : { // point to _Other_ptr through _Other_rep
1337 : _Resetw(const_cast<_Ty2*>(_Other_ptr), _Other_rep);
1338 : }
1339 :
1340 : template<class _Ty2>
1341 : void _Resetw(_Ty2 *_Other_ptr, _Ref_count_base *_Other_rep)
1342 : { // point to _Other_ptr through _Other_rep
1343 : if (_Other_rep)
1344 : _Other_rep->_Incwref();
1345 : if (_Rep != 0)
1346 : _Rep->_Decwref();
1347 : _Rep = _Other_rep;
1348 : _Ptr = _Other_ptr;
1349 : }
1350 :
1351 : private:
1352 : _Ty *_Ptr;
1353 : _Ref_count_base *_Rep;
1354 : template<class _Ty0>
1355 : friend class _Ptr_base;
1356 : };
1357 :
1358 : // HELPER TEMPLATE CLASS _Ref
1359 : template<class _Ty>
1360 : struct _Ref
1361 : { // ref for _Ty
1362 : typedef _Ty& _Type;
1363 : };
1364 :
1365 : template<> struct
1366 : _Ref<void>
1367 : { // ref for void
1368 : typedef void _Type;
1369 : };
1370 :
1371 : template<>
1372 : struct _Ref<const void>
1373 : { // ref for const void
1374 : typedef void _Type;
1375 : };
1376 :
1377 : template<>
1378 : struct _Ref<volatile void>
1379 : { // ref for volatile void
1380 : typedef void _Type;
1381 : };
1382 :
1383 : template<>
1384 : struct _Ref<const volatile void>
1385 : { // ref for const volatile void
1386 : typedef void _Type;
1387 : };
1388 :
1389 : // TEMPLATE CLASS shared_ptr
1390 : template<class _Ty>
1391 : class shared_ptr
1392 : : public _Ptr_base<_Ty>
1393 : { // class for reference counted resource management
1394 : public:
1395 : shared_ptr()
1396 : { // construct empty shared_ptr object
1397 : this->_Reset();
1398 : }
1399 :
1400 : template<class _Ux>
1401 : explicit shared_ptr(_Ux *_Px)
1402 : { // construct shared_ptr object that owns *_Px
1403 : _Resetp(_Px);
1404 : }
1405 :
1406 : template<class _Ux,
1407 : class _Dx>
1408 : shared_ptr(_Ux *_Px, _Dx _Dt)
1409 : { // construct with *_Px, deleter
1410 : _Resetp(_Px, _Dt);
1411 : }
1412 :
1413 : template<class _Ux,
1414 : class _Dx,
1415 : class _Alloc>
1416 : shared_ptr(_Ux *_Px, _Dx _Dt, _Alloc _Ax)
1417 : { // construct with *_Px, deleter, allocator
1418 : _Resetp(_Px, _Dt, _Ax);
1419 : }
1420 :
1421 : shared_ptr(const shared_ptr& _Other)
1422 : { // construct shared_ptr object that owns same resource as _Other
1423 : this->_Reset(_Other);
1424 : }
1425 :
1426 : template<class _Ty2>
1427 : shared_ptr(const shared_ptr<_Ty2>& _Other)
1428 : { // construct shared_ptr object that owns same resource as _Other
1429 : this->_Reset(_Other);
1430 : }
1431 :
1432 : template<class _Ty2>
1433 : explicit shared_ptr(const weak_ptr<_Ty2>& _Other,
1434 : bool _Throw = true)
1435 : { // construct shared_ptr object that owns resource *_Other
1436 : this->_Reset(_Other, _Throw);
1437 : }
1438 :
1439 : template<class _Ty2>
1440 : explicit shared_ptr(auto_ptr<_Ty2>& _Other)
1441 : { // construct shared_ptr object that owns *_Other.get()
1442 : this->_Reset(_Other);
1443 : }
1444 :
1445 : template<class _Ty2>
1446 : shared_ptr(const shared_ptr<_Ty2>& _Other, const _Static_tag& _Tag)
1447 : { // construct shared_ptr object for static_pointer_cast
1448 : this->_Reset(_Other, _Tag);
1449 : }
1450 :
1451 : template<class _Ty2>
1452 : shared_ptr(const shared_ptr<_Ty2>& _Other, const _Const_tag& _Tag)
1453 : { // construct shared_ptr object for const_pointer_cast
1454 : this->_Reset(_Other, _Tag);
1455 : }
1456 :
1457 : template<class _Ty2>
1458 : shared_ptr(const shared_ptr<_Ty2>& _Other, const _Dynamic_tag& _Tag)
1459 : { // construct shared_ptr object for dynamic_pointer_cast
1460 : this->_Reset(_Other, _Tag);
1461 : }
1462 :
1463 : ~shared_ptr()
1464 : { // release resource
1465 : this->_Decref();
1466 : }
1467 :
1468 : shared_ptr& operator=(const shared_ptr& _Right)
1469 : { // assign shared ownership of resource owned by _Right
1470 : this->_Reset(_Right);
1471 : return (*this);
1472 : }
1473 :
1474 : template<class _Ty2>
1475 : shared_ptr& operator=(const shared_ptr<_Ty2>& _Right)
1476 : { // assign shared ownership of resource owned by _Right
1477 : this->_Reset(_Right);
1478 : return (*this);
1479 : }
1480 :
1481 : template<class _Ty2>
1482 : shared_ptr& operator=(auto_ptr<_Ty2>& _Right)
1483 : { // assign ownership of resource pointed to by _Right
1484 : this->_Reset(_Right);
1485 : return (*this);
1486 : }
1487 :
1488 : void reset()
1489 : { // release resource and convert to empty shared_ptr object
1490 : this->_Reset();
1491 : }
1492 :
1493 : template<class _Ux>
1494 : void reset(_Ux *_Px)
1495 : { // release, take ownership of _Px
1496 : _Resetp(_Px);
1497 : }
1498 :
1499 : template<class _Ux,
1500 : class _Dx>
1501 : void reset(_Ux *_Px, _Dx _Dt)
1502 : { // release, take ownership of _Px, with deleter _Dt
1503 : _Resetp(_Px, _Dt);
1504 : }
1505 :
1506 : template<class _Ux,
1507 : class _Dx,
1508 : class _Alloc>
1509 : void reset(_Ux *_Px, _Dx _Dt, _Alloc _Ax)
1510 : { // release, take ownership of _Px, with deleter _Dt, allocator _Ax
1511 : _Resetp(_Px, _Dt, _Ax);
1512 : }
1513 :
1514 : void swap(shared_ptr& _Other)
1515 : { // swap pointers
1516 : this->_Swap(_Other);
1517 : }
1518 :
1519 : _Ty *get() const
1520 : { // return pointer to resource
1521 : return (this->_Get());
1522 : }
1523 :
1524 : typename _Ref<_Ty>::_Type operator*() const
1525 : { // return reference to resource
1526 : return (*this->_Get());
1527 : }
1528 :
1529 : _Ty *operator->() const
1530 : { // return pointer to resource
1531 : return (this->_Get());
1532 : }
1533 :
1534 : bool unique() const
1535 : { // return true if no other shared_ptr object owns this resource
1536 : return (this->use_count() == 1);
1537 : }
1538 :
1539 : operator _STD _Bool_type() const
1540 : { // test if shared_ptr object owns no resource
1541 : return (this->_Get() != 0 ? _CONVERTIBLE_TO_TRUE : 0);
1542 : }
1543 :
1544 : private:
1545 : template<class _Ux>
1546 : void _Resetp(_Ux *_Px)
1547 : { // release, take ownership of _Px
1548 : _TRY_BEGIN // allocate control block and reset
1549 : _Resetp0(_Px, new _Ref_count<_Ux>(_Px));
1550 : _CATCH_ALL // allocation failed, delete resource
1551 : delete _Px;
1552 : _RERAISE;
1553 : _CATCH_END
1554 : }
1555 :
1556 : template<class _Ux,
1557 : class _Dx>
1558 : void _Resetp(_Ux *_Px, _Dx _Dt)
1559 : { // release, take ownership of _Px, deleter _Dt
1560 : typedef _Ref_count_d<_Ux, _Dx> _Refd;
1561 :
1562 : _TRY_BEGIN // allocate control block and reset
1563 : _Resetp0(_Px, new _Refd(_Px, _Dt));
1564 : _CATCH_ALL // allocation failed, delete resource
1565 : _Dt(_Px);
1566 : _RERAISE;
1567 : _CATCH_END
1568 : }
1569 :
1570 : template<class _Ux,
1571 : class _Dx,
1572 : class _Alloc>
1573 : void _Resetp(_Ux *_Px, _Dx _Dt, _Alloc _Ax)
1574 : { // release, take ownership of _Px, deleter _Dt, allocator _Ax
1575 : typedef _Ref_count_d<_Ux, _Dx, _Alloc> _Refd;
1576 : typename _Alloc::template rebind<_Refd>::other _Al = _Ax;
1577 :
1578 : _TRY_BEGIN // allocate control block and reset
1579 : _Refd *_Ptr = _Al.allocate(1);
1580 : new (_Ptr) _Refd(_Px, _Dt, _Al);
1581 : _Resetp0(_Px, _Ptr);
1582 : _CATCH_ALL // allocation failed, delete resource
1583 : _Dt(_Px);
1584 : _RERAISE;
1585 : _CATCH_END
1586 : }
1587 :
1588 : template<class _Ux>
1589 : void _Resetp0(_Ux *_Px, _Ref_count_base *_Rx)
1590 : { // release resource and take ownership of _Px
1591 : this->_Reset(_Px, _Rx);
1592 : _Enable_shared(_Px, _Rx);
1593 : }
1594 : };
1595 :
1596 : template<class _Ty1,
1597 : class _Ty2>
1598 : bool operator==(const shared_ptr<_Ty1>& _S1,
1599 : const shared_ptr<_Ty2>& _S2)
1600 : { // test if shared_ptr objects hold pointers that compare equal
1601 : return (_S1.get() == _S2.get());
1602 : }
1603 :
1604 : template<class _Ty1,
1605 : class _Ty2>
1606 : bool operator!=(const shared_ptr<_Ty1>& _S1,
1607 : const shared_ptr<_Ty2>& _S2)
1608 : { // test if shared_ptr objects hold pointers that compare unequal
1609 : return (!(_S1 == _S2));
1610 : }
1611 :
1612 : template<class _Ty1,
1613 : class _Ty2>
1614 : bool operator< (const shared_ptr<_Ty1>& _S1,
1615 : const shared_ptr<_Ty2>& _S2)
1616 : { // return true if _S1 precedes _S2 (order defined by control block)
1617 : return (_S1._Cmp(_S2));
1618 : }
1619 :
1620 : template<class _Elem,
1621 : class _Traits,
1622 : class _Ty>
1623 : basic_ostream<_Elem, _Traits>&
1624 : operator<<(basic_ostream<_Elem, _Traits>& _Out,
1625 : const shared_ptr<_Ty>& _Px)
1626 : { // write contained pointer to stream
1627 : return (_Out << _Px.get());
1628 : }
1629 :
1630 : template<class _Ty>
1631 : void swap(shared_ptr<_Ty>& _S1, shared_ptr<_Ty>& _S2)
1632 : { // swap contents of _S1 and _S2
1633 : _S1.swap(_S2);
1634 : }
1635 :
1636 : template<class _Ty1,
1637 : class _Ty2>
1638 : shared_ptr<_Ty1> static_pointer_cast(const shared_ptr<_Ty2>& _Other)
1639 : { // return shared_ptr object holding static_cast<_Ty1 *)(_Other.get())
1640 : return (shared_ptr<_Ty1>(_Other, _Static_tag()));
1641 : }
1642 :
1643 : template<class _Ty1,
1644 : class _Ty2>
1645 : shared_ptr<_Ty1> const_pointer_cast(const shared_ptr<_Ty2>& _Other)
1646 : { // return shared_ptr object holding const_cast<_Ty1 *)(_Other.get())
1647 : return (shared_ptr<_Ty1>(_Other, _Const_tag()));
1648 : }
1649 :
1650 : template<class _Ty1,
1651 : class _Ty2>
1652 : shared_ptr<_Ty1> dynamic_pointer_cast(const shared_ptr<_Ty2>& _Other)
1653 : { // return shared_ptr object holding dynamic_cast<_Ty1*)(_Other.get())
1654 : return (shared_ptr<_Ty1>(_Other, _Dynamic_tag()));
1655 : }
1656 :
1657 : template<class _Dx,
1658 : class _Ty>
1659 : _Dx *get_deleter(const shared_ptr<_Ty>& _Sx)
1660 : { // return pointer to shared_ptr's deleter object if its type is _Ty
1661 : return ((_Dx *)_Sx._Get_deleter(typeid(_Dx)));
1662 : }
1663 :
1664 : // TEMPLATE CLASS weak_ptr
1665 : template<class _Ty>
1666 : class weak_ptr
1667 : : public _Ptr_base<_Ty>
1668 : { // class for pointer to reference counted resource
1669 : typedef typename _Ptr_base<_Ty>::_Elem _Elem;
1670 :
1671 : public:
1672 : weak_ptr()
1673 : { // construct empty weak_ptr object
1674 : this->_Resetw();
1675 : }
1676 :
1677 : template<class _Ty2>
1678 : weak_ptr(const shared_ptr<_Ty2>& _Other)
1679 : { // construct weak_ptr object for resource owned by _Other
1680 : this->_Resetw(_Other);
1681 : }
1682 :
1683 : weak_ptr(const weak_ptr& _Other)
1684 : { // construct weak_ptr object for resource pointed to by _Other
1685 : this->_Resetw(_Other);
1686 : }
1687 :
1688 : template<class _Ty2>
1689 : weak_ptr(const weak_ptr<_Ty2>& _Other)
1690 : { // construct weak_ptr object for resource pointed to by _Other
1691 : this->_Resetw(_Other);
1692 : }
1693 :
1694 : ~weak_ptr()
1695 : { // release resource
1696 : this->_Decwref();
1697 : }
1698 :
1699 : weak_ptr& operator=(const weak_ptr& _Right)
1700 : { // assign from _Right
1701 : this->_Resetw(_Right);
1702 : return (*this);
1703 : }
1704 :
1705 : template<class _Ty2>
1706 : weak_ptr& operator=(const weak_ptr<_Ty2>& _Right)
1707 : { // assign from _Right
1708 : this->_Resetw(_Right);
1709 : return (*this);
1710 : }
1711 :
1712 : template<class _Ty2>
1713 : weak_ptr& operator=(shared_ptr<_Ty2>& _Right)
1714 : { // assign from _Right
1715 : this->_Resetw(_Right);
1716 : return (*this);
1717 : }
1718 :
1719 : void reset()
1720 : { // release resource, convert to null weak_ptr object
1721 : this->_Resetw();
1722 : }
1723 :
1724 : void swap(weak_ptr& _Other)
1725 : { // swap pointers
1726 : this->_Swap(_Other);
1727 : }
1728 :
1729 : bool expired() const
1730 : { // return true if resource no longer exists
1731 : return (this->_Expired());
1732 : }
1733 :
1734 : shared_ptr<_Ty> lock() const
1735 : { // convert to shared_ptr
1736 : return (shared_ptr<_Elem>(*this, false));
1737 : }
1738 : };
1739 :
1740 : template<class _Ty1,
1741 : class _Ty2>
1742 : bool operator<(const weak_ptr<_Ty1>& _W1,
1743 : const weak_ptr<_Ty2>& _W2)
1744 : { // return true if _S1 precedes _S2 (order defined by control block)
1745 : return (_W1._Cmp(_W2));
1746 : }
1747 :
1748 : template<class _Ty>
1749 : void swap(weak_ptr<_Ty>& _W1, weak_ptr<_Ty>& _W2)
1750 : { // swap contents of _W1 and _W2
1751 : _W1.swap(_W2);
1752 : }
1753 :
1754 : // TEMPLATE CLASS enable_shared_from_this
1755 : template<class _Ty> class enable_shared_from_this
1756 : { // provide member functions that create shared_ptr to this
1757 : public:
1758 : typedef _Ty _EStype;
1759 :
1760 : shared_ptr<_Ty> shared_from_this()
1761 : { // return shared_ptr
1762 : return (shared_ptr<_Ty>(_Wptr));
1763 : }
1764 :
1765 : shared_ptr<const _Ty> shared_from_this() const
1766 : { // return shared_ptr
1767 : return (shared_ptr<const _Ty>(_Wptr));
1768 : }
1769 :
1770 : protected:
1771 : enable_shared_from_this()
1772 : { // construct (do nothing)
1773 : }
1774 :
1775 : enable_shared_from_this(const enable_shared_from_this&)
1776 : { // construct (do nothing)
1777 : }
1778 :
1779 : enable_shared_from_this& operator=(const enable_shared_from_this&)
1780 : { // assign (do nothing)
1781 : return (*this);
1782 : }
1783 :
1784 : ~enable_shared_from_this()
1785 : { // destroy (do nothing)
1786 : }
1787 :
1788 : private:
1789 : template<class _Ty1,
1790 : class _Ty2>
1791 : friend void _Do_enable(
1792 : _Ty1 *,
1793 : enable_shared_from_this<_Ty2>*,
1794 : _Ref_count_base *);
1795 :
1796 : mutable weak_ptr<_Ty> _Wptr;
1797 : };
1798 :
1799 : template<class _Ty1,
1800 : class _Ty2>
1801 : inline void _Do_enable(
1802 : _Ty1 *_Ptr,
1803 : enable_shared_from_this<_Ty2> *_Es,
1804 : _Ref_count_base *_Refptr)
1805 : { // reset internal weak pointer
1806 : _Es->_Wptr._Resetw(_Ptr, _Refptr);
1807 : }
1808 : } // namespace tr1
1809 :
1810 : template<class _Ty>
1811 : class _Move_operation_category<tr1::shared_ptr<_Ty> >
1812 : { // shared_ptr implements a performant swap
1813 : public:
1814 : typedef _Swap_move_tag _Move_cat;
1815 : };
1816 :
1817 : template<class _Ty>
1818 : class _Move_operation_category<tr1::weak_ptr<_Ty> >
1819 : { // weak_ptr implements a performant swap
1820 : public:
1821 : typedef _Swap_move_tag _Move_cat;
1822 : };
1823 : _STD_END
1824 : #endif /* _HAS_TR1 */
1825 :
1826 : #ifdef _MSC_VER
1827 : #pragma warning(pop)
1828 : #pragma pack(pop)
1829 : #endif /* _MSC_VER */
1830 :
1831 : #endif /* RC_INVOKED */
1832 : #endif /* _MEMORY_ */
1833 :
1834 :
1835 : /*
1836 : * Copyright (c) 1992-2008 by P.J. Plauger. ALL RIGHTS RESERVED.
1837 : * Consult your license regarding permissions and restrictions.
1838 : */
1839 :
1840 : /*
1841 : * This file is derived from software bearing the following
1842 : * restrictions:
1843 : *
1844 : * Copyright (c) 1994
1845 : * Hewlett-Packard Company
1846 : *
1847 : * Permission to use, copy, modify, distribute and sell this
1848 : * software and its documentation for any purpose is hereby
1849 : * granted without fee, provided that the above copyright notice
1850 : * appear in all copies and that both that copyright notice and
1851 : * this permission notice appear in supporting documentation.
1852 : * Hewlett-Packard Company makes no representations about the
1853 : * suitability of this software for any purpose. It is provided
1854 : * "as is" without express or implied warranty.
1855 : V5.05:0009 */
1856 :
1857 :
|