CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testSharedPtr.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Test compilability and basic functionality of Utility/memory.h
4 //
5 // Author: W. E. Brown, 2010-03-19, adapted from the boost library's
6 // shared_ptr and related functionality whose internal attributions bear
7 // the following various notices:
8 //
9 // Copyright (c) 2002, 2003 Peter Dimov
10 // Distributed under the Boost Software License, Version 1.0.
11 // See http://www.boost.org/LICENSE_1_0.txt
12 //
13 // ======================================================================
14 
15 
16 #include "CLHEP/Utility/memory.h"
17 
18 #include <cassert>
19 #include <map>
20 #include <vector>
21 
22 
23 using namespace CLHEP;
24 using CLHEP::shared_ptr;
25 using CLHEP::weak_ptr;
26 
27 
28 #if defined(_MSC_VER) && (_MSC_VER >= 1310)
29 # pragma warning (disable : 4675) // suppress ADL warning
30 #endif
31 
32 
33 namespace n_element_type
34 {
35 
36 void
37  f(int &)
38 { }
39 
40 void
41  test()
42 {
44  T t;
45  f(t);
46 }
47 
48 } // namespace n_element_type
49 
50 namespace n_constructors
51 {
52 
53 class incomplete;
54 
55 void
57 {
58  {
59  shared_ptr<int> pi;
60  assert(pi? false: true);
61  assert(!pi);
62  assert(pi.get() == 0);
63  assert(pi.use_count() == 0);
64  }
65 
66  {
68  assert(pv? false: true);
69  assert(!pv);
70  assert(pv.get() == 0);
71  assert(pv.use_count() == 0);
72  }
73 
74  {
76  assert(px? false: true);
77  assert(!px);
78  assert(px.get() == 0);
79  assert(px.use_count() == 0);
80  }
81 }
82 
83 struct A
84 {
85  int dummy;
86 };
87 
88 struct X
89 {
90  static long instances;
91 
92  X()
93  {
94  ++instances;
95  }
96 
97  ~X()
98  {
99  --instances;
100  }
101 
102 private:
103  X(X const &);
104  X & operator= (X const &);
105 };
106 
107 long X::instances = 0;
108 
109 // virtual inheritance stresses the implementation
110 
111 struct Y
112  : public A
113  , public virtual X
114 {
115  static long instances;
116 
117  Y()
118  {
119  ++instances;
120  }
121 
122  ~Y()
123  {
124  --instances;
125  }
126 
127 private:
128  Y(Y const &);
129  Y & operator= (Y const &);
130 };
131 
132 long Y::instances = 0;
133 
134 template< class T >
135  void
136  pc0_test(T * p)
137 {
138  assert(p == 0);
139  shared_ptr<T> pt(p);
140  assert(pt? false: true);
141  assert(!pt);
142  assert(pt.get() == 0);
143  assert(pt.use_count() == 1);
144  assert(pt.unique());
145 }
146 
147 void
149 {
150  pc0_test(static_cast<int*>(0));
151 
152  pc0_test(static_cast<int const*>(0));
153  pc0_test(static_cast<int volatile*>(0));
154  pc0_test(static_cast<int const volatile*>(0));
155 
156  {
157  shared_ptr<int const> pi(static_cast<int*>(0));
158  assert(pi? false: true);
159  assert(!pi);
160  assert(pi.get() == 0);
161  assert(pi.use_count() == 1);
162  assert(pi.unique());
163  }
164 
165  {
166  shared_ptr<int volatile> pi(static_cast<int*>(0));
167  assert(pi? false: true);
168  assert(!pi);
169  assert(pi.get() == 0);
170  assert(pi.use_count() == 1);
171  assert(pi.unique());
172  }
173 
174  {
175  shared_ptr<void> pv(static_cast<int*>(0));
176  assert(pv? false: true);
177  assert(!pv);
178  assert(pv.get() == 0);
179  assert(pv.use_count() == 1);
180  assert(pv.unique());
181  }
182 
183  {
184  shared_ptr<void const> pv(static_cast<int*>(0));
185  assert(pv? false: true);
186  assert(!pv);
187  assert(pv.get() == 0);
188  assert(pv.use_count() == 1);
189  assert(pv.unique());
190  }
191 
192  pc0_test(static_cast<X*>(0));
193  pc0_test(static_cast<X const*>(0));
194  pc0_test(static_cast<X volatile*>(0));
195  pc0_test(static_cast<X const volatile*>(0));
196 
197  {
198  shared_ptr<X const> px(static_cast<X*>(0));
199  assert(px? false: true);
200  assert(!px);
201  assert(px.get() == 0);
202  assert(px.use_count() == 1);
203  assert(px.unique());
204  }
205 
206  {
207  shared_ptr<X> px(static_cast<Y*>(0));
208  assert(px? false: true);
209  assert(!px);
210  assert(px.get() == 0);
211  assert(px.use_count() == 1);
212  assert(px.unique());
213  }
214 
215  {
216  shared_ptr<X const> px(static_cast<Y*>(0));
217  assert(px? false: true);
218  assert(!px);
219  assert(px.get() == 0);
220  assert(px.use_count() == 1);
221  assert(px.unique());
222  }
223 
224  {
225  shared_ptr<void> pv(static_cast<X*>(0));
226  assert(pv? false: true);
227  assert(!pv);
228  assert(pv.get() == 0);
229  assert(pv.use_count() == 1);
230  assert(pv.unique());
231  }
232 
233  {
234  shared_ptr<void const> pv(static_cast<X*>(0));
235  assert(pv? false: true);
236  assert(!pv);
237  assert(pv.get() == 0);
238  assert(pv.use_count() == 1);
239  assert(pv.unique());
240  }
241 
242  {
243  int * p = new int(7);
244  shared_ptr<int> pi(p);
245  assert(pi? true: false);
246  assert(!!pi);
247  assert(pi.get() == p);
248  assert(pi.use_count() == 1);
249  assert(pi.unique());
250  assert(*pi == 7);
251  }
252 
253  {
254  int * p = new int(7);
255  shared_ptr<int const> pi(p);
256  assert(pi? true: false);
257  assert(!!pi);
258  assert(pi.get() == p);
259  assert(pi.use_count() == 1);
260  assert(pi.unique());
261  assert(*pi == 7);
262  }
263 
264  {
265  int * p = new int(7);
266  shared_ptr<void> pv(p);
267  assert(pv? true: false);
268  assert(!!pv);
269  assert(pv.get() == p);
270  assert(pv.use_count() == 1);
271  assert(pv.unique());
272  }
273 
274  {
275  int * p = new int(7);
277  assert(pv? true: false);
278  assert(!!pv);
279  assert(pv.get() == p);
280  assert(pv.use_count() == 1);
281  assert(pv.unique());
282  }
283 
284  assert(X::instances == 0);
285 
286  {
287  X * p = new X;
288  shared_ptr<X> px(p);
289  assert(px? true: false);
290  assert(!!px);
291  assert(px.get() == p);
292  assert(px.use_count() == 1);
293  assert(px.unique());
294  assert(X::instances == 1);
295  }
296 
297  assert(X::instances == 0);
298 
299  {
300  X * p = new X;
301  shared_ptr<X const> px(p);
302  assert(px? true: false);
303  assert(!!px);
304  assert(px.get() == p);
305  assert(px.use_count() == 1);
306  assert(px.unique());
307  assert(X::instances == 1);
308  }
309 
310  assert(X::instances == 0);
311 
312  {
313  X * p = new X;
314  shared_ptr<void> pv(p);
315  assert(pv? true: false);
316  assert(!!pv);
317  assert(pv.get() == p);
318  assert(pv.use_count() == 1);
319  assert(pv.unique());
320  assert(X::instances == 1);
321  }
322 
323  assert(X::instances == 0);
324 
325  {
326  X * p = new X;
328  assert(pv? true: false);
329  assert(!!pv);
330  assert(pv.get() == p);
331  assert(pv.use_count() == 1);
332  assert(pv.unique());
333  assert(X::instances == 1);
334  }
335 
336  assert(X::instances == 0);
337  assert(Y::instances == 0);
338 
339  {
340  Y * p = new Y;
341  shared_ptr<X> px(p);
342  assert(px? true: false);
343  assert(!!px);
344  assert(px.get() == p);
345  assert(px.use_count() == 1);
346  assert(px.unique());
347  assert(X::instances == 1);
348  assert(Y::instances == 1);
349  }
350 
351  assert(X::instances == 0);
352  assert(Y::instances == 0);
353 
354  {
355  Y * p = new Y;
356  shared_ptr<X const> px(p);
357  assert(px? true: false);
358  assert(!!px);
359  assert(px.get() == p);
360  assert(px.use_count() == 1);
361  assert(px.unique());
362  assert(X::instances == 1);
363  assert(Y::instances == 1);
364  }
365 
366  assert(X::instances == 0);
367  assert(Y::instances == 0);
368 }
369 
370 int m = 0;
371 
372 void
373  deleter(int * p)
374 {
375  assert(p == 0);
376 }
377 
378 void
379  deleter2(int * p)
380 {
381  assert(p == &m);
382  ++*p;
383 }
384 
385 struct deleter3
386 {
388  {
389  assert(p == 0);
390  }
391 };
392 
394 
395 void
397 {
398  {
399  shared_ptr<int> pi(static_cast<int*>(0), deleter);
400  assert(pi? false: true);
401  assert(!pi);
402  assert(pi.get() == 0);
403  assert(pi.use_count() == 1);
404  assert(pi.unique());
405  }
406 
407  {
408  shared_ptr<void> pv(static_cast<int*>(0), &deleter);
409  assert(pv? false: true);
410  assert(!pv);
411  assert(pv.get() == 0);
412  assert(pv.use_count() == 1);
413  assert(pv.unique());
414  }
415 
416  {
417  shared_ptr<void const> pv(static_cast<int*>(0), deleter);
418  assert(pv? false: true);
419  assert(!pv);
420  assert(pv.get() == 0);
421  assert(pv.use_count() == 1);
422  assert(pv.unique());
423  }
424 
425  {
427  assert(px? false: true);
428  assert(!px);
429  assert(px.get() == 0);
430  assert(px.use_count() == 1);
431  assert(px.unique());
432  }
433 
434  {
436  assert(pv? false: true);
437  assert(!pv);
438  assert(pv.get() == 0);
439  assert(pv.use_count() == 1);
440  assert(pv.unique());
441  }
442 
443  {
445  assert(pv? false: true);
446  assert(!pv);
447  assert(pv.get() == 0);
448  assert(pv.use_count() == 1);
449  assert(pv.unique());
450  }
451 
452  assert(m == 0);
453 
454  {
455  shared_ptr<int> pi(&m, deleter2);
456  assert(pi? true: false);
457  assert(!!pi);
458  assert(pi.get() == &m);
459  assert(pi.use_count() == 1);
460  assert(pi.unique());
461  }
462 
463  assert(m == 1);
464 
465  {
467  assert(pi? true: false);
468  assert(!!pi);
469  assert(pi.get() == &m);
470  assert(pi.use_count() == 1);
471  assert(pi.unique());
472  }
473 
474  assert(m == 2);
475 
476  {
478  assert(pv? true: false);
479  assert(!!pv);
480  assert(pv.get() == &m);
481  assert(pv.use_count() == 1);
482  assert(pv.unique());
483  }
484 
485  assert(m == 3);
486 
487  {
489  assert(pv? true: false);
490  assert(!!pv);
491  assert(pv.get() == &m);
492  assert(pv.use_count() == 1);
493  assert(pv.unique());
494  }
495 
496  assert(m == 4);
497 }
498 
499 void
501 {
502  {
503  shared_ptr<int> pi;
504 
505  shared_ptr<int> pi2(pi);
506  assert(pi2 == pi);
507  assert(pi2? false: true);
508  assert(!pi2);
509  assert(pi2.get() == 0);
510  assert(pi2.use_count() == pi.use_count());
511 
512  shared_ptr<void> pi3(pi);
513  assert(pi3 == pi);
514  assert(pi3? false: true);
515  assert(!pi3);
516  assert(pi3.get() == 0);
517  assert(pi3.use_count() == pi.use_count());
518 
519  shared_ptr<void> pi4(pi3);
520  assert(pi4 == pi3);
521  assert(pi4? false: true);
522  assert(!pi4);
523  assert(pi4.get() == 0);
524  assert(pi4.use_count() == pi3.use_count());
525  }
526 
527  {
528  shared_ptr<void> pv;
529 
530  shared_ptr<void> pv2(pv);
531  assert(pv2 == pv);
532  assert(pv2? false: true);
533  assert(!pv2);
534  assert(pv2.get() == 0);
535  assert(pv2.use_count() == pv.use_count());
536  }
537 
538  {
540 
541  shared_ptr<incomplete> px2(px);
542  assert(px2 == px);
543  assert(px2? false: true);
544  assert(!px2);
545  assert(px2.get() == 0);
546  assert(px2.use_count() == px.use_count());
547 
548  shared_ptr<void> px3(px);
549  assert(px3 == px);
550  assert(px3? false: true);
551  assert(!px3);
552  assert(px3.get() == 0);
553  assert(px3.use_count() == px.use_count());
554  }
555 
556  {
557  shared_ptr<int> pi(static_cast<int*>(0));
558 
559  shared_ptr<int> pi2(pi);
560  assert(pi2 == pi);
561  assert(pi2? false: true);
562  assert(!pi2);
563  assert(pi2.get() == 0);
564  assert(pi2.use_count() == 2);
565  assert(!pi2.unique());
566  assert(pi2.use_count() == pi.use_count());
567  assert(!(pi < pi2 || pi2 < pi)); // shared ownership test
568 
569  shared_ptr<void> pi3(pi);
570  assert(pi3 == pi);
571  assert(pi3? false: true);
572  assert(!pi3);
573  assert(pi3.get() == 0);
574  assert(pi3.use_count() == 3);
575  assert(!pi3.unique());
576  assert(pi3.use_count() == pi.use_count());
577  assert(!(pi < pi3 || pi3 < pi)); // shared ownership test
578 
579  shared_ptr<void> pi4(pi2);
580  assert(pi4 == pi2);
581  assert(pi4? false: true);
582  assert(!pi4);
583  assert(pi4.get() == 0);
584  assert(pi4.use_count() == 4);
585  assert(!pi4.unique());
586  assert(pi4.use_count() == pi2.use_count());
587  assert(!(pi2 < pi4 || pi4 < pi2)); // shared ownership test
588 
589  assert(pi3.use_count() == pi4.use_count());
590  assert(!(pi3 < pi4 || pi4 < pi3)); // shared ownership test
591  }
592 
593  {
594  shared_ptr<X> px(static_cast<X*>(0));
595 
596  shared_ptr<X> px2(px);
597  assert(px2 == px);
598  assert(px2? false: true);
599  assert(!px2);
600  assert(px2.get() == 0);
601  assert(px2.use_count() == 2);
602  assert(!px2.unique());
603  assert(px2.use_count() == px.use_count());
604  assert(!(px < px2 || px2 < px)); // shared ownership test
605 
606  shared_ptr<void> px3(px);
607  assert(px3 == px);
608  assert(px3? false: true);
609  assert(!px3);
610  assert(px3.get() == 0);
611  assert(px3.use_count() == 3);
612  assert(!px3.unique());
613  assert(px3.use_count() == px.use_count());
614  assert(!(px < px3 || px3 < px)); // shared ownership test
615 
616  shared_ptr<void> px4(px2);
617  assert(px4 == px2);
618  assert(px4? false: true);
619  assert(!px4);
620  assert(px4.get() == 0);
621  assert(px4.use_count() == 4);
622  assert(!px4.unique());
623  assert(px4.use_count() == px2.use_count());
624  assert(!(px2 < px4 || px4 < px2)); // shared ownership test
625 
626  assert(px3.use_count() == px4.use_count());
627  assert(!(px3 < px4 || px4 < px3)); // shared ownership test
628  }
629 
630  {
631  int * p = new int(7);
632  shared_ptr<int> pi(p);
633 
634  shared_ptr<int> pi2(pi);
635  assert(pi2 == pi);
636  assert(pi2? true: false);
637  assert(!!pi2);
638  assert(pi2.get() == p);
639  assert(pi2.use_count() == 2);
640  assert(!pi2.unique());
641  assert(*pi2 == 7);
642  assert(pi2.use_count() == pi.use_count());
643  assert(!(pi < pi2 || pi2 < pi)); // shared ownership test
644  }
645 
646  {
647  int * p = new int(7);
648  shared_ptr<void> pv(p);
649  assert(pv.get() == p);
650 
651  shared_ptr<void> pv2(pv);
652  assert(pv2 == pv);
653  assert(pv2? true: false);
654  assert(!!pv2);
655  assert(pv2.get() == p);
656  assert(pv2.use_count() == 2);
657  assert(!pv2.unique());
658  assert(pv2.use_count() == pv.use_count());
659  assert(!(pv < pv2 || pv2 < pv)); // shared ownership test
660  }
661 
662  assert(X::instances == 0);
663 
664  {
665  X * p = new X;
666  shared_ptr<X> px(p);
667  assert(px.get() == p);
668 
669  shared_ptr<X> px2(px);
670  assert(px2 == px);
671  assert(px2? true: false);
672  assert(!!px2);
673  assert(px2.get() == p);
674  assert(px2.use_count() == 2);
675  assert(!px2.unique());
676 
677  assert(X::instances == 1);
678 
679  assert(px2.use_count() == px.use_count());
680  assert(!(px < px2 || px2 < px)); // shared ownership test
681 
682  shared_ptr<void> px3(px);
683  assert(px3 == px);
684  assert(px3? true: false);
685  assert(!!px3);
686  assert(px3.get() == p);
687  assert(px3.use_count() == 3);
688  assert(!px3.unique());
689  assert(px3.use_count() == px.use_count());
690  assert(!(px < px3 || px3 < px)); // shared ownership test
691 
692  shared_ptr<void> px4(px2);
693  assert(px4 == px2);
694  assert(px4? true: false);
695  assert(!!px4);
696  assert(px4.get() == p);
697  assert(px4.use_count() == 4);
698  assert(!px4.unique());
699  assert(px4.use_count() == px2.use_count());
700  assert(!(px2 < px4 || px4 < px2)); // shared ownership test
701 
702  assert(px3.use_count() == px4.use_count());
703  assert(!(px3 < px4 || px4 < px3)); // shared ownership test
704  }
705 
706  assert(X::instances == 0);
707  assert(Y::instances == 0);
708 
709  {
710  Y * p = new Y;
711  shared_ptr<Y> py(p);
712  assert(py.get() == p);
713 
714  shared_ptr<X> px(py);
715  assert(px == py);
716  assert(px? true: false);
717  assert(!!px);
718  assert(px.get() == p);
719  assert(px.use_count() == 2);
720  assert(!px.unique());
721  assert(px.use_count() == py.use_count());
722  assert(!(px < py || py < px)); // shared ownership test
723 
724  assert(X::instances == 1);
725  assert(Y::instances == 1);
726 
727  shared_ptr<void const> pv(px);
728  assert(pv == px);
729  assert(pv? true: false);
730  assert(!!pv);
731  assert(pv.get() == px.get());
732  assert(pv.use_count() == 3);
733  assert(!pv.unique());
734  assert(pv.use_count() == px.use_count());
735  assert(!(px < pv || pv < px)); // shared ownership test
736 
737  shared_ptr<void const> pv2(py);
738  assert(pv2 == py);
739  assert(pv2? true: false);
740  assert(!!pv2);
741  assert(pv2.get() == py.get());
742  assert(pv2.use_count() == 4);
743  assert(!pv2.unique());
744  assert(pv2.use_count() == py.use_count());
745  assert(!(py < pv2 || pv2 < py)); // shared ownership test
746 
747  assert(pv.use_count() == pv2.use_count());
748  assert(!(pv < pv2 || pv2 < pv)); // shared ownership test
749  }
750 
751  assert(X::instances == 0);
752  assert(Y::instances == 0);
753 }
754 
755 void
757 {
758  {
759  weak_ptr<Y> wp;
760  assert(wp.use_count() == 0);
761 
762  try
763  {
764  shared_ptr<Y> p2(wp);
765  throw "shared_ptr<Y> p2(wp) failed to throw";
766  }
767  catch(bad_weak_ptr)
768  {
769  }
770 
771  try
772  {
773  shared_ptr<X> p3(wp);
774  throw "shared_ptr<X> p3(wp) failed to throw";
775  }
776  catch(bad_weak_ptr)
777  {
778  }
779  }
780 
781  {
782  shared_ptr<Y> p;
783  weak_ptr<Y> wp(p);
784 
785  if(wp.use_count() != 0) // 0 allowed but not required
786  {
787  shared_ptr<Y> p2(wp);
788  assert(p2.use_count() == wp.use_count());
789  assert(p2.get() == 0);
790 
791  shared_ptr<X> p3(wp);
792  assert(p3.use_count() == wp.use_count());
793  assert(p3.get() == 0);
794  }
795  }
796 
797  {
798  shared_ptr<Y> p(new Y);
799  weak_ptr<Y> wp(p);
800 
801  {
802  shared_ptr<Y> p2(wp);
803  assert(p2? true: false);
804  assert(!!p2);
805  assert(p2.get() == p.get());
806  assert(p2.use_count() == 2);
807  assert(!p2.unique());
808  assert(p2.use_count() == wp.use_count());
809 
810  assert(p.use_count() == p2.use_count());
811  assert(!(p < p2 || p2 < p)); // shared ownership test
812 
813  shared_ptr<X> p3(wp);
814  assert(p3? true: false);
815  assert(!!p3);
816  assert(p3.get() == p.get());
817  assert(p3.use_count() == 3);
818  assert(!p3.unique());
819  assert(p3.use_count() == wp.use_count());
820 
821  assert(p.use_count() == p3.use_count());
822  }
823 
824  p.reset();
825  assert(wp.use_count() == 0);
826 
827  try
828  {
829  shared_ptr<Y> p2(wp);
830  throw "shared_ptr<Y> p2(wp) failed to throw";
831  }
832  catch(bad_weak_ptr)
833  {
834  }
835 
836  try
837  {
838  shared_ptr<X> p3(wp);
839  throw "shared_ptr<X> p3(wp) failed to throw";
840  }
841  catch(bad_weak_ptr)
842  {
843  }
844  }
845 }
846 
847 void
849 {
850  {
851  std::auto_ptr<int> p;
852  shared_ptr<int> pi(p);
853  assert(pi? false: true);
854  assert(!pi);
855  assert(pi.get() == 0);
856  assert(pi.use_count() == 1);
857  assert(pi.unique());
858  assert(p.get() == 0);
859  }
860 
861  {
862  std::auto_ptr<int> p;
863  shared_ptr<int const> pi(p);
864  assert(pi? false: true);
865  assert(!pi);
866  assert(pi.get() == 0);
867  assert(pi.use_count() == 1);
868  assert(pi.unique());
869  assert(p.get() == 0);
870  }
871 
872  {
873  std::auto_ptr<int> p;
874  shared_ptr<void> pv(p);
875  assert(pv? false: true);
876  assert(!pv);
877  assert(pv.get() == 0);
878  assert(pv.use_count() == 1);
879  assert(pv.unique());
880  assert(p.get() == 0);
881  }
882 
883  {
884  std::auto_ptr<int> p;
886  assert(pv? false: true);
887  assert(!pv);
888  assert(pv.get() == 0);
889  assert(pv.use_count() == 1);
890  assert(pv.unique());
891  assert(p.get() == 0);
892  }
893 
894  {
895  std::auto_ptr<X> p;
896  shared_ptr<X> px(p);
897  assert(px? false: true);
898  assert(!px);
899  assert(px.get() == 0);
900  assert(px.use_count() == 1);
901  assert(px.unique());
902  assert(p.get() == 0);
903  }
904 
905  {
906  std::auto_ptr<X> p;
907  shared_ptr<X const> px(p);
908  assert(px? false: true);
909  assert(!px);
910  assert(px.get() == 0);
911  assert(px.use_count() == 1);
912  assert(px.unique());
913  assert(p.get() == 0);
914  }
915 
916  {
917  std::auto_ptr<Y> p;
918  shared_ptr<X> px(p);
919  assert(px? false: true);
920  assert(!px);
921  assert(px.get() == 0);
922  assert(px.use_count() == 1);
923  assert(px.unique());
924  assert(p.get() == 0);
925  }
926 
927  {
928  std::auto_ptr<Y> p;
929  shared_ptr<X const> px(p);
930  assert(px? false: true);
931  assert(!px);
932  assert(px.get() == 0);
933  assert(px.use_count() == 1);
934  assert(px.unique());
935  assert(p.get() == 0);
936  }
937 
938  {
939  std::auto_ptr<Y> p;
940  shared_ptr<void> pv(p);
941  assert(pv? false: true);
942  assert(!pv);
943  assert(pv.get() == 0);
944  assert(pv.use_count() == 1);
945  assert(pv.unique());
946  assert(p.get() == 0);
947  }
948 
949  {
950  std::auto_ptr<Y> p;
952  assert(pv? false: true);
953  assert(!pv);
954  assert(pv.get() == 0);
955  assert(pv.use_count() == 1);
956  assert(pv.unique());
957  assert(p.get() == 0);
958  }
959 
960  {
961  std::auto_ptr<int> p(new int(7));
962  int * q = p.get();
963  shared_ptr<int> pi(p);
964  assert(pi? true: false);
965  assert(!!pi);
966  assert(pi.get() == q);
967  assert(pi.use_count() == 1);
968  assert(pi.unique());
969  assert(*pi == 7);
970 
971  assert(p.get() == 0);
972  }
973 
974  {
975  std::auto_ptr<int> p(new int(7));
976  int * q = p.get();
977  shared_ptr<int const> pi(p);
978  assert(pi? true: false);
979  assert(!!pi);
980  assert(pi.get() == q);
981  assert(pi.use_count() == 1);
982  assert(pi.unique());
983  assert(*pi == 7);
984 
985  assert(p.get() == 0);
986  }
987 
988  {
989  std::auto_ptr<int> p(new int(7));
990  int * q = p.get();
991  shared_ptr<void> pv(p);
992  assert(pv? true: false);
993  assert(!!pv);
994  assert(pv.get() == q);
995  assert(pv.use_count() == 1);
996  assert(pv.unique());
997 
998  assert(p.get() == 0);
999  }
1000 
1001  {
1002  std::auto_ptr<int> p(new int(7));
1003  int * q = p.get();
1004  shared_ptr<void const> pv(p);
1005  assert(pv? true: false);
1006  assert(!!pv);
1007  assert(pv.get() == q);
1008  assert(pv.use_count() == 1);
1009  assert(pv.unique());
1010 
1011  assert(p.get() == 0);
1012  }
1013 
1014  assert(X::instances == 0);
1015 
1016  {
1017  std::auto_ptr<X> p(new X);
1018  X * q = p.get();
1019  shared_ptr<X> px(p);
1020  assert(px? true: false);
1021  assert(!!px);
1022  assert(px.get() == q);
1023  assert(px.use_count() == 1);
1024  assert(px.unique());
1025  assert(X::instances == 1);
1026 
1027  assert(p.get() == 0);
1028  }
1029 
1030  assert(X::instances == 0);
1031 
1032  {
1033  std::auto_ptr<X> p(new X);
1034  X * q = p.get();
1035  shared_ptr<X const> px(p);
1036  assert(px? true: false);
1037  assert(!!px);
1038  assert(px.get() == q);
1039  assert(px.use_count() == 1);
1040  assert(px.unique());
1041  assert(X::instances == 1);
1042 
1043  assert(p.get() == 0);
1044  }
1045 
1046  assert(X::instances == 0);
1047 
1048  {
1049  std::auto_ptr<X> p(new X);
1050  X * q = p.get();
1051  shared_ptr<void> pv(p);
1052  assert(pv? true: false);
1053  assert(!!pv);
1054  assert(pv.get() == q);
1055  assert(pv.use_count() == 1);
1056  assert(pv.unique());
1057  assert(X::instances == 1);
1058 
1059  assert(p.get() == 0);
1060  }
1061 
1062  assert(X::instances == 0);
1063 
1064  {
1065  std::auto_ptr<X> p(new X);
1066  X * q = p.get();
1067  shared_ptr<void const> pv(p);
1068  assert(pv? true: false);
1069  assert(!!pv);
1070  assert(pv.get() == q);
1071  assert(pv.use_count() == 1);
1072  assert(pv.unique());
1073  assert(X::instances == 1);
1074 
1075  assert(p.get() == 0);
1076  }
1077 
1078  assert(X::instances == 0);
1079  assert(Y::instances == 0);
1080 
1081  {
1082  std::auto_ptr<Y> p(new Y);
1083  Y * q = p.get();
1084  shared_ptr<X> px(p);
1085  assert(px? true: false);
1086  assert(!!px);
1087  assert(px.get() == q);
1088  assert(px.use_count() == 1);
1089  assert(px.unique());
1090  assert(X::instances == 1);
1091  assert(Y::instances == 1);
1092 
1093  assert(p.get() == 0);
1094  }
1095 
1096  assert(X::instances == 0);
1097  assert(Y::instances == 0);
1098 
1099  {
1100  std::auto_ptr<Y> p(new Y);
1101  Y * q = p.get();
1102  shared_ptr<X const> px(p);
1103  assert(px? true: false);
1104  assert(!!px);
1105  assert(px.get() == q);
1106  assert(px.use_count() == 1);
1107  assert(px.unique());
1108  assert(X::instances == 1);
1109  assert(Y::instances == 1);
1110 
1111  assert(p.get() == 0);
1112  }
1113 
1114  assert(X::instances == 0);
1115  assert(Y::instances == 0);
1116 }
1117 
1118 void
1120 {
1124  copy_constructor();
1127 }
1128 
1129 } // namespace n_constructors
1130 
1131 namespace n_assignment
1132 {
1133 
1134 class incomplete;
1135 
1136 struct A
1137 {
1138  int dummy;
1139 };
1140 
1141 struct X
1142 {
1143  static long instances;
1144 
1145  X()
1146  {
1147  ++instances;
1148  }
1149 
1150  ~X()
1151  {
1152  --instances;
1153  }
1154 
1155 private:
1156  X(X const &);
1157  X & operator= (X const &);
1158 };
1159 
1160 long X::instances = 0;
1161 
1162 struct Y
1163  : public A
1164  , public virtual X
1165 {
1166  static long instances;
1167 
1168  Y()
1169  {
1170  ++instances;
1171  }
1172 
1173  ~Y()
1174  {
1175  --instances;
1176  }
1177 
1178 private:
1179  Y(Y const &);
1180  Y & operator= (Y const &);
1181 };
1182 
1183 long Y::instances = 0;
1184 
1185 void
1187 {
1188  {
1190 
1191  p1 = p1;
1192 
1193  assert(p1 == p1);
1194  assert(p1? false: true);
1195  assert(!p1);
1196  assert(p1.get() == 0);
1197 
1199 
1200  p1 = p2;
1201 
1202  assert(p1 == p2);
1203  assert(p1? false: true);
1204  assert(!p1);
1205  assert(p1.get() == 0);
1206 
1207  shared_ptr<incomplete> p3(p1);
1208 
1209  p1 = p3;
1210 
1211  assert(p1 == p3);
1212  assert(p1? false: true);
1213  assert(!p1);
1214  assert(p1.get() == 0);
1215  }
1216 
1217  {
1218  shared_ptr<void> p1;
1219 
1220  p1 = p1;
1221 
1222  assert(p1 == p1);
1223  assert(p1? false: true);
1224  assert(!p1);
1225  assert(p1.get() == 0);
1226 
1227  shared_ptr<void> p2;
1228 
1229  p1 = p2;
1230 
1231  assert(p1 == p2);
1232  assert(p1? false: true);
1233  assert(!p1);
1234  assert(p1.get() == 0);
1235 
1236  shared_ptr<void> p3(p1);
1237 
1238  p1 = p3;
1239 
1240  assert(p1 == p3);
1241  assert(p1? false: true);
1242  assert(!p1);
1243  assert(p1.get() == 0);
1244 
1245  shared_ptr<void> p4(new int);
1246  assert(p4.use_count() == 1);
1247 
1248  p1 = p4;
1249 
1250  assert(p1 == p4);
1251  assert(!(p1 < p4 || p4 < p1));
1252  assert(p1.use_count() == 2);
1253  assert(p4.use_count() == 2);
1254 
1255  p1 = p3;
1256 
1257  assert(p1 == p3);
1258  assert(p4.use_count() == 1);
1259  }
1260 
1261  {
1262  shared_ptr<X> p1;
1263 
1264  p1 = p1;
1265 
1266  assert(p1 == p1);
1267  assert(p1? false: true);
1268  assert(!p1);
1269  assert(p1.get() == 0);
1270 
1271  shared_ptr<X> p2;
1272 
1273  p1 = p2;
1274 
1275  assert(p1 == p2);
1276  assert(p1? false: true);
1277  assert(!p1);
1278  assert(p1.get() == 0);
1279 
1280  shared_ptr<X> p3(p1);
1281 
1282  p1 = p3;
1283 
1284  assert(p1 == p3);
1285  assert(p1? false: true);
1286  assert(!p1);
1287  assert(p1.get() == 0);
1288 
1289  assert(X::instances == 0);
1290 
1291  shared_ptr<X> p4(new X);
1292 
1293  assert(X::instances == 1);
1294 
1295  p1 = p4;
1296 
1297  assert(X::instances == 1);
1298 
1299  assert(p1 == p4);
1300  assert(!(p1 < p4 || p4 < p1));
1301 
1302  assert(p1.use_count() == 2);
1303 
1304  p1 = p2;
1305 
1306  assert(p1 == p2);
1307  assert(X::instances == 1);
1308 
1309  p4 = p3;
1310 
1311  assert(p4 == p3);
1312  assert(X::instances == 0);
1313  }
1314 }
1315 
1316 void
1318 {
1319  {
1320  shared_ptr<void> p1;
1321 
1323 
1324  p1 = p2;
1325 
1326  assert(p1 == p2);
1327  assert(p1? false: true);
1328  assert(!p1);
1329  assert(p1.get() == 0);
1330 
1331  shared_ptr<int> p4(new int);
1332  assert(p4.use_count() == 1);
1333 
1334  shared_ptr<void> p5(p4);
1335  assert(p4.use_count() == 2);
1336 
1337  p1 = p4;
1338 
1339  assert(p1 == p4);
1340  assert(!(p1 < p5 || p5 < p1));
1341  assert(p1.use_count() == 3);
1342  assert(p4.use_count() == 3);
1343 
1344  p1 = p2;
1345 
1346  assert(p1 == p2);
1347  assert(p4.use_count() == 2);
1348  }
1349 
1350  {
1351  shared_ptr<X> p1;
1352 
1353  shared_ptr<Y> p2;
1354 
1355  p1 = p2;
1356 
1357  assert(p1 == p2);
1358  assert(p1? false: true);
1359  assert(!p1);
1360  assert(p1.get() == 0);
1361 
1362  assert(X::instances == 0);
1363  assert(Y::instances == 0);
1364 
1365  shared_ptr<Y> p4(new Y);
1366 
1367  assert(X::instances == 1);
1368  assert(Y::instances == 1);
1369  assert(p4.use_count() == 1);
1370 
1371  shared_ptr<X> p5(p4);
1372  assert(p4.use_count() == 2);
1373 
1374  p1 = p4;
1375 
1376  assert(X::instances == 1);
1377  assert(Y::instances == 1);
1378 
1379  assert(p1 == p4);
1380  assert(!(p1 < p5 || p5 < p1));
1381 
1382  assert(p1.use_count() == 3);
1383  assert(p4.use_count() == 3);
1384 
1385  p1 = p2;
1386 
1387  assert(p1 == p2);
1388  assert(X::instances == 1);
1389  assert(Y::instances == 1);
1390  assert(p4.use_count() == 2);
1391 
1392  p4 = p2;
1393  p5 = p2;
1394 
1395  assert(p4 == p2);
1396  assert(X::instances == 0);
1397  assert(Y::instances == 0);
1398  }
1399 }
1400 
1401 void
1403 {
1404  {
1405  shared_ptr<int> p1;
1406 
1407  std::auto_ptr<int> p2;
1408 
1409  p1 = p2;
1410  assert(p1? false: true);
1411  assert(!p1);
1412  assert(p1.get() == 0);
1413  assert(p1.use_count() == 1);
1414 
1415  int * p = new int;
1416  std::auto_ptr<int> p3(p);
1417 
1418  p1 = p3;
1419  assert(p1.get() == p);
1420  assert(p1.use_count() == 1);
1421 
1422  assert(p3.get() == 0);
1423 
1424  p1 = p2;
1425  assert(p1? false: true);
1426  assert(!p1);
1427  assert(p1.get() == 0);
1428  assert(p1.use_count() == 1);
1429  }
1430 
1431  {
1432  shared_ptr<void> p1;
1433 
1434  std::auto_ptr<int> p2;
1435 
1436  p1 = p2;
1437  assert(p1? false: true);
1438  assert(!p1);
1439  assert(p1.get() == 0);
1440  assert(p1.use_count() == 1);
1441 
1442  int * p = new int;
1443  std::auto_ptr<int> p3(p);
1444 
1445  p1 = p3;
1446  assert(p1.get() == p);
1447  assert(p1.use_count() == 1);
1448 
1449  assert(p3.get() == 0);
1450 
1451  p1 = p2;
1452  assert(p1? false: true);
1453  assert(!p1);
1454  assert(p1.get() == 0);
1455  assert(p1.use_count() == 1);
1456  }
1457 
1458 
1459  {
1460  shared_ptr<X> p1;
1461 
1462  std::auto_ptr<Y> p2;
1463 
1464  p1 = p2;
1465  assert(p1? false: true);
1466  assert(!p1);
1467  assert(p1.get() == 0);
1468  assert(p1.use_count() == 1);
1469  assert(X::instances == 0);
1470  assert(Y::instances == 0);
1471 
1472  Y * p = new Y;
1473  std::auto_ptr<Y> p3(p);
1474 
1475  assert(X::instances == 1);
1476  assert(Y::instances == 1);
1477 
1478  p1 = p3;
1479  assert(p1.get() == p);
1480  assert(p1.use_count() == 1);
1481  assert(X::instances == 1);
1482  assert(Y::instances == 1);
1483 
1484  assert(p3.get() == 0);
1485 
1486  p1 = p2;
1487  assert(p1? false: true);
1488  assert(!p1);
1489  assert(p1.get() == 0);
1490  assert(p1.use_count() == 1);
1491  assert(X::instances == 0);
1492  assert(Y::instances == 0);
1493  }
1494 }
1495 
1496 void
1498 {
1499  copy_assignment();
1502 }
1503 
1504 } // namespace n_assignment
1505 
1506 namespace n_reset
1507 {
1508 
1509 class incomplete;
1510 
1512 
1513 void
1515 {
1516 }
1517 
1518 struct X
1519 {
1520  static long instances;
1521 
1522  X()
1523  {
1524  ++instances;
1525  }
1526 
1527  ~X()
1528  {
1529  --instances;
1530  }
1531 
1532 private:
1533  X(X const &);
1534  X & operator= (X const &);
1535 };
1536 
1537 long X::instances = 0;
1538 
1539 void
1541 {
1542  {
1543  shared_ptr<int> pi;
1544  pi.reset();
1545  assert(pi? false: true);
1546  assert(!pi);
1547  assert(pi.get() == 0);
1548  assert(pi.use_count() == 0);
1549  }
1550 
1551  {
1552  shared_ptr<int> pi(static_cast<int*>(0));
1553  pi.reset();
1554  assert(pi? false: true);
1555  assert(!pi);
1556  assert(pi.get() == 0);
1557  assert(pi.use_count() == 0);
1558  }
1559 
1560  {
1561  shared_ptr<int> pi(new int);
1562  pi.reset();
1563  assert(pi? false: true);
1564  assert(!pi);
1565  assert(pi.get() == 0);
1566  assert(pi.use_count() == 0);
1567  }
1568 
1569  {
1571  px.reset();
1572  assert(px? false: true);
1573  assert(!px);
1574  assert(px.get() == 0);
1575  assert(px.use_count() == 0);
1576  }
1577 
1578  {
1580  px.reset();
1581  assert(px? false: true);
1582  assert(!px);
1583  assert(px.get() == 0);
1584  assert(px.use_count() == 0);
1585  }
1586 
1587  {
1588  shared_ptr<X> px;
1589  px.reset();
1590  assert(px? false: true);
1591  assert(!px);
1592  assert(px.get() == 0);
1593  assert(px.use_count() == 0);
1594  }
1595 
1596  {
1597  assert(X::instances == 0);
1598  shared_ptr<X> px(new X);
1599  assert(X::instances == 1);
1600  px.reset();
1601  assert(px? false: true);
1602  assert(!px);
1603  assert(px.get() == 0);
1604  assert(px.use_count() == 0);
1605  assert(X::instances == 0);
1606  }
1607 
1608  {
1609  shared_ptr<void> pv;
1610  pv.reset();
1611  assert(pv? false: true);
1612  assert(!pv);
1613  assert(pv.get() == 0);
1614  assert(pv.use_count() == 0);
1615  }
1616 
1617  {
1618  assert(X::instances == 0);
1619  shared_ptr<void> pv(new X);
1620  assert(X::instances == 1);
1621  pv.reset();
1622  assert(pv? false: true);
1623  assert(!pv);
1624  assert(pv.get() == 0);
1625  assert(pv.use_count() == 0);
1626  assert(X::instances == 0);
1627  }
1628 }
1629 
1630 struct A
1631 {
1632  int dummy;
1633 };
1634 
1635 struct Y
1636  : public A
1637  , public virtual X
1638 {
1639  static long instances;
1640 
1641  Y()
1642  {
1643  ++instances;
1644  }
1645 
1646  ~Y()
1647  {
1648  --instances;
1649  }
1650 
1651 private:
1652  Y(Y const &);
1653  Y & operator= (Y const &);
1654 };
1655 
1656 long Y::instances = 0;
1657 
1658 void
1660 {
1661  {
1662  shared_ptr<int> pi;
1663 
1664  pi.reset(static_cast<int*>(0));
1665  assert(pi? false: true);
1666  assert(!pi);
1667  assert(pi.get() == 0);
1668  assert(pi.use_count() == 1);
1669  assert(pi.unique());
1670 
1671  int * p = new int;
1672  pi.reset(p);
1673  assert(pi? true: false);
1674  assert(!!pi);
1675  assert(pi.get() == p);
1676  assert(pi.use_count() == 1);
1677  assert(pi.unique());
1678 
1679  pi.reset(static_cast<int*>(0));
1680  assert(pi? false: true);
1681  assert(!pi);
1682  assert(pi.get() == 0);
1683  assert(pi.use_count() == 1);
1684  assert(pi.unique());
1685  }
1686 
1687  {
1688  shared_ptr<X> px;
1689 
1690  px.reset(static_cast<X*>(0));
1691  assert(px? false: true);
1692  assert(!px);
1693  assert(px.get() == 0);
1694  assert(px.use_count() == 1);
1695  assert(px.unique());
1696  assert(X::instances == 0);
1697 
1698  X * p = new X;
1699  px.reset(p);
1700  assert(px? true: false);
1701  assert(!!px);
1702  assert(px.get() == p);
1703  assert(px.use_count() == 1);
1704  assert(px.unique());
1705  assert(X::instances == 1);
1706 
1707  px.reset(static_cast<X*>(0));
1708  assert(px? false: true);
1709  assert(!px);
1710  assert(px.get() == 0);
1711  assert(px.use_count() == 1);
1712  assert(px.unique());
1713  assert(X::instances == 0);
1714  assert(Y::instances == 0);
1715 
1716  Y * q = new Y;
1717  px.reset(q);
1718  assert(px? true: false);
1719  assert(!!px);
1720  assert(px.get() == q);
1721  assert(px.use_count() == 1);
1722  assert(px.unique());
1723  assert(X::instances == 1);
1724  assert(Y::instances == 1);
1725 
1726  px.reset(static_cast<Y*>(0));
1727  assert(px? false: true);
1728  assert(!px);
1729  assert(px.get() == 0);
1730  assert(px.use_count() == 1);
1731  assert(px.unique());
1732  assert(X::instances == 0);
1733  assert(Y::instances == 0);
1734  }
1735 
1736  {
1737  shared_ptr<void> pv;
1738 
1739  pv.reset(static_cast<X*>(0));
1740  assert(pv? false: true);
1741  assert(!pv);
1742  assert(pv.get() == 0);
1743  assert(pv.use_count() == 1);
1744  assert(pv.unique());
1745  assert(X::instances == 0);
1746 
1747  X * p = new X;
1748  pv.reset(p);
1749  assert(pv? true: false);
1750  assert(!!pv);
1751  assert(pv.get() == p);
1752  assert(pv.use_count() == 1);
1753  assert(pv.unique());
1754  assert(X::instances == 1);
1755 
1756  pv.reset(static_cast<X*>(0));
1757  assert(pv? false: true);
1758  assert(!pv);
1759  assert(pv.get() == 0);
1760  assert(pv.use_count() == 1);
1761  assert(pv.unique());
1762  assert(X::instances == 0);
1763  assert(Y::instances == 0);
1764 
1765  Y * q = new Y;
1766  pv.reset(q);
1767  assert(pv? true: false);
1768  assert(!!pv);
1769  assert(pv.get() == q);
1770  assert(pv.use_count() == 1);
1771  assert(pv.unique());
1772  assert(X::instances == 1);
1773  assert(Y::instances == 1);
1774 
1775  pv.reset(static_cast<Y*>(0));
1776  assert(pv? false: true);
1777  assert(!pv);
1778  assert(pv.get() == 0);
1779  assert(pv.use_count() == 1);
1780  assert(pv.unique());
1781  assert(X::instances == 0);
1782  assert(Y::instances == 0);
1783  }
1784 }
1785 
1786 void
1787  * deleted = 0;
1788 
1789 void
1790  deleter2(void * p)
1791 {
1792  deleted = p;
1793 }
1794 
1795 void
1797 {
1798  {
1799  shared_ptr<int> pi;
1800 
1801  pi.reset(static_cast<int*>(0), deleter2);
1802  assert(pi? false: true);
1803  assert(!pi);
1804  assert(pi.get() == 0);
1805  assert(pi.use_count() == 1);
1806  assert(pi.unique());
1807 
1808  deleted = &pi;
1809 
1810  int m = 0;
1811  pi.reset(&m, deleter2);
1812  assert(deleted == 0);
1813  assert(pi? true: false);
1814  assert(!!pi);
1815  assert(pi.get() == &m);
1816  assert(pi.use_count() == 1);
1817  assert(pi.unique());
1818 
1819  pi.reset(static_cast<int*>(0), deleter2);
1820  assert(deleted == &m);
1821  assert(pi? false: true);
1822  assert(!pi);
1823  assert(pi.get() == 0);
1824  assert(pi.use_count() == 1);
1825  assert(pi.unique());
1826 
1827  pi.reset();
1828  assert(deleted == 0);
1829  }
1830 
1831  {
1832  shared_ptr<X> px;
1833 
1834  px.reset(static_cast<X*>(0), deleter2);
1835  assert(px? false: true);
1836  assert(!px);
1837  assert(px.get() == 0);
1838  assert(px.use_count() == 1);
1839  assert(px.unique());
1840 
1841  deleted = &px;
1842 
1843  X x;
1844  px.reset(&x, deleter2);
1845  assert(deleted == 0);
1846  assert(px? true: false);
1847  assert(!!px);
1848  assert(px.get() == &x);
1849  assert(px.use_count() == 1);
1850  assert(px.unique());
1851 
1852  px.reset(static_cast<X*>(0), deleter2);
1853  assert(deleted == &x);
1854  assert(px? false: true);
1855  assert(!px);
1856  assert(px.get() == 0);
1857  assert(px.use_count() == 1);
1858  assert(px.unique());
1859 
1860  Y y;
1861  px.reset(&y, deleter2);
1862  assert(deleted == 0);
1863  assert(px? true: false);
1864  assert(!!px);
1865  assert(px.get() == &y);
1866  assert(px.use_count() == 1);
1867  assert(px.unique());
1868 
1869  px.reset(static_cast<Y*>(0), deleter2);
1870  assert(deleted == &y);
1871  assert(px? false: true);
1872  assert(!px);
1873  assert(px.get() == 0);
1874  assert(px.use_count() == 1);
1875  assert(px.unique());
1876 
1877  px.reset();
1878  assert(deleted == 0);
1879  }
1880 
1881  {
1882  shared_ptr<void> pv;
1883 
1884  pv.reset(static_cast<X*>(0), deleter2);
1885  assert(pv? false: true);
1886  assert(!pv);
1887  assert(pv.get() == 0);
1888  assert(pv.use_count() == 1);
1889  assert(pv.unique());
1890 
1891  deleted = &pv;
1892 
1893  X x;
1894  pv.reset(&x, deleter2);
1895  assert(deleted == 0);
1896  assert(pv? true: false);
1897  assert(!!pv);
1898  assert(pv.get() == &x);
1899  assert(pv.use_count() == 1);
1900  assert(pv.unique());
1901 
1902  pv.reset(static_cast<X*>(0), deleter2);
1903  assert(deleted == &x);
1904  assert(pv? false: true);
1905  assert(!pv);
1906  assert(pv.get() == 0);
1907  assert(pv.use_count() == 1);
1908  assert(pv.unique());
1909 
1910  Y y;
1911  pv.reset(&y, deleter2);
1912  assert(deleted == 0);
1913  assert(pv? true: false);
1914  assert(!!pv);
1915  assert(pv.get() == &y);
1916  assert(pv.use_count() == 1);
1917  assert(pv.unique());
1918 
1919  pv.reset(static_cast<Y*>(0), deleter2);
1920  assert(deleted == &y);
1921  assert(pv? false: true);
1922  assert(!pv);
1923  assert(pv.get() == 0);
1924  assert(pv.use_count() == 1);
1925  assert(pv.unique());
1926 
1927  pv.reset();
1928  assert(deleted == 0);
1929  }
1930 
1931  {
1933 
1934  px.reset(p0, deleter2);
1935  assert(px? false: true);
1936  assert(!px);
1937  assert(px.get() == 0);
1938  assert(px.use_count() == 1);
1939  assert(px.unique());
1940 
1941  deleted = &px;
1942  px.reset(p0, deleter2);
1943  assert(deleted == 0);
1944  }
1945 }
1946 
1947 void
1949 {
1950  plain_reset();
1951  pointer_reset();
1952  deleter_reset();
1953 }
1954 
1955 } // namespace n_reset
1956 
1957 namespace n_access
1958 {
1959 
1960 struct X
1961 {
1962 };
1963 
1964 void
1966 {
1967  {
1968  shared_ptr<X> px;
1969  assert(px.get() == 0);
1970  assert(px? false: true);
1971  assert(!px);
1972 
1973  assert(get_pointer(px) == px.get());
1974  }
1975 
1976  {
1977  shared_ptr<X> px(static_cast<X*>(0));
1978  assert(px.get() == 0);
1979  assert(px? false: true);
1980  assert(!px);
1981 
1982  assert(get_pointer(px) == px.get());
1983  }
1984 
1985  #if 0
1986  {
1987  shared_ptr<X> px(static_cast<X*>(0), checked_deleter<X>());
1988  assert(px.get() == 0);
1989  assert(px? false: true);
1990  assert(!px);
1991 
1992  assert(get_pointer(px) == px.get());
1993  }
1994  #endif // 0
1995 
1996  {
1997  X * p = new X;
1998  shared_ptr<X> px(p);
1999  assert(px.get() == p);
2000  assert(px? true: false);
2001  assert(!!px);
2002  assert(&*px == px.get());
2003  assert(px.operator ->() == px.get());
2004 
2005  assert(get_pointer(px) == px.get());
2006  }
2007 
2008  #if 0
2009  {
2010  X * p = new X;
2011  shared_ptr<X> px(p, checked_deleter<X>());
2012  assert(px.get() == p);
2013  assert(px? true: false);
2014  assert(!!px);
2015  assert(&*px == px.get());
2016  assert(px.operator ->() == px.get());
2017 
2018  assert(get_pointer(px) == px.get());
2019  }
2020  #endif // 0
2021 }
2022 
2023 } // namespace n_access
2024 
2025 namespace n_use_count
2026 {
2027 
2028 struct X
2029 {
2030 };
2031 
2032 void
2034 {
2035  {
2036  shared_ptr<X> px(static_cast<X*>(0));
2037  assert(px.use_count() == 1);
2038  assert(px.unique());
2039 
2040  shared_ptr<X> px2(px);
2041  assert(px2.use_count() == 2);
2042  assert(!px2.unique());
2043  assert(px.use_count() == 2);
2044  assert(!px.unique());
2045  }
2046 
2047  {
2048  shared_ptr<X> px(new X);
2049  assert(px.use_count() == 1);
2050  assert(px.unique());
2051 
2052  shared_ptr<X> px2(px);
2053  assert(px2.use_count() == 2);
2054  assert(!px2.unique());
2055  assert(px.use_count() == 2);
2056  assert(!px.unique());
2057  }
2058 
2059  #if 0
2060  {
2061  shared_ptr<X> px(new X, checked_deleter<X>());
2062  assert(px.use_count() == 1);
2063  assert(px.unique());
2064 
2065  shared_ptr<X> px2(px);
2066  assert(px2.use_count() == 2);
2067  assert(!px2.unique());
2068  assert(px.use_count() == 2);
2069  assert(!px.unique());
2070  }
2071  #endif // 0
2072 }
2073 
2074 } // namespace n_use_count
2075 
2076 namespace n_swap
2077 {
2078 
2079 struct X
2080 {
2081 };
2082 
2083 void
2085 {
2086  {
2087  shared_ptr<X> px;
2088  shared_ptr<X> px2;
2089 
2090  px.swap(px2);
2091 
2092  assert(px.get() == 0);
2093  assert(px2.get() == 0);
2094 
2095  using std::swap;
2096  swap(px, px2);
2097 
2098  assert(px.get() == 0);
2099  assert(px2.get() == 0);
2100  }
2101 
2102  {
2103  X * p = new X;
2104  shared_ptr<X> px;
2105  shared_ptr<X> px2(p);
2106  shared_ptr<X> px3(px2);
2107 
2108  px.swap(px2);
2109 
2110  assert(px.get() == p);
2111  assert(px.use_count() == 2);
2112  assert(px2.get() == 0);
2113  assert(px3.get() == p);
2114  assert(px3.use_count() == 2);
2115 
2116  using std::swap;
2117  swap(px, px2);
2118 
2119  assert(px.get() == 0);
2120  assert(px2.get() == p);
2121  assert(px2.use_count() == 2);
2122  assert(px3.get() == p);
2123  assert(px3.use_count() == 2);
2124  }
2125 
2126  {
2127  X * p1 = new X;
2128  X * p2 = new X;
2129  shared_ptr<X> px(p1);
2130  shared_ptr<X> px2(p2);
2131  shared_ptr<X> px3(px2);
2132 
2133  px.swap(px2);
2134 
2135  assert(px.get() == p2);
2136  assert(px.use_count() == 2);
2137  assert(px2.get() == p1);
2138  assert(px2.use_count() == 1);
2139  assert(px3.get() == p2);
2140  assert(px3.use_count() == 2);
2141 
2142  using std::swap;
2143  swap(px, px2);
2144 
2145  assert(px.get() == p1);
2146  assert(px.use_count() == 1);
2147  assert(px2.get() == p2);
2148  assert(px2.use_count() == 2);
2149  assert(px3.get() == p2);
2150  assert(px3.use_count() == 2);
2151  }
2152 }
2153 
2154 } // namespace n_swap
2155 
2156 namespace n_comparison
2157 {
2158 
2159 struct X
2160 {
2161  int dummy;
2162 };
2163 
2164 struct Y
2165 {
2166  int dummy2;
2167 };
2168 
2169 struct Z
2170  : public X
2171  , public virtual Y
2172 {
2173 };
2174 
2175 void
2177 {
2178  {
2179  shared_ptr<X> px;
2180  assert(px == px);
2181  assert(!(px != px));
2182  assert(!(px < px));
2183 
2184  shared_ptr<X> px2;
2185 
2186  assert(px.get() == px2.get());
2187  assert(px == px2);
2188  assert(!(px != px2));
2189  assert(!(px < px2 && px2 < px));
2190  }
2191 
2192  {
2193  shared_ptr<X> px;
2194  shared_ptr<X> px2(px);
2195 
2196  assert(px2 == px2);
2197  assert(!(px2 != px2));
2198  assert(!(px2 < px2));
2199 
2200  assert(px.get() == px2.get());
2201  assert(px == px2);
2202  assert(!(px != px2));
2203  assert(!(px < px2 && px2 < px));
2204  }
2205 
2206  {
2207  shared_ptr<X> px;
2208  shared_ptr<X> px2(new X);
2209 
2210  assert(px2 == px2);
2211  assert(!(px2 != px2));
2212  assert(!(px2 < px2));
2213 
2214  assert(px.get() != px2.get());
2215  assert(px != px2);
2216  assert(!(px == px2));
2217  assert(px < px2 || px2 < px);
2218  assert(!(px < px2 && px2 < px));
2219  }
2220 
2221  {
2222  shared_ptr<X> px(new X);
2223  shared_ptr<X> px2(new X);
2224 
2225  assert(px.get() != px2.get());
2226  assert(px != px2);
2227  assert(!(px == px2));
2228  assert(px < px2 || px2 < px);
2229  assert(!(px < px2 && px2 < px));
2230  }
2231 
2232  {
2233  shared_ptr<X> px(new X);
2234  shared_ptr<X> px2(px);
2235 
2236  assert(px2 == px2);
2237  assert(!(px2 != px2));
2238  assert(!(px2 < px2));
2239 
2240  assert(px.get() == px2.get());
2241  assert(px == px2);
2242  assert(!(px != px2));
2243  assert(!(px < px2 || px2 < px));
2244  }
2245 
2246  {
2247  shared_ptr<X> px(new X);
2248  shared_ptr<Y> py(new Y);
2249  shared_ptr<Z> pz(new Z);
2250 
2251  assert(px.get() != pz.get());
2252  assert(px != pz);
2253  assert(!(px == pz));
2254 
2255  assert(py.get() != pz.get());
2256  assert(py != pz);
2257  assert(!(py == pz));
2258 
2259  assert(px < py || py < px);
2260  assert(px < pz || pz < px);
2261  assert(py < pz || pz < py);
2262 
2263  assert(!(px < py && py < px));
2264  assert(!(px < pz && pz < px));
2265  assert(!(py < pz && pz < py));
2266 
2267  shared_ptr<void> pvx(px);
2268 
2269  assert(pvx == pvx);
2270  assert(!(pvx != pvx));
2271  assert(!(pvx < pvx));
2272 
2273  shared_ptr<void> pvy(py);
2274  shared_ptr<void> pvz(pz);
2275 
2276  assert(pvx < pvy || pvy < pvx);
2277  assert(pvx < pvz || pvz < pvx);
2278  assert(pvy < pvz || pvz < pvy);
2279 
2280  assert(!(pvx < pvy && pvy < pvx));
2281  assert(!(pvx < pvz && pvz < pvx));
2282  assert(!(pvy < pvz && pvz < pvy));
2283  }
2284 
2285  {
2286  shared_ptr<Z> pz(new Z);
2287  shared_ptr<X> px(pz);
2288 
2289  assert(px == px);
2290  assert(!(px != px));
2291  assert(!(px < px));
2292 
2293  shared_ptr<Y> py(pz);
2294 
2295  assert(px.get() == pz.get());
2296  assert(px == pz);
2297  assert(!(px != pz));
2298 
2299  assert(py.get() == pz.get());
2300  assert(py == pz);
2301  assert(!(py != pz));
2302 
2303  assert(!(px < py || py < px));
2304  assert(!(px < pz || pz < px));
2305  assert(!(py < pz || pz < py));
2306 
2307  shared_ptr<void> pvx(px);
2308  shared_ptr<void> pvy(py);
2309  shared_ptr<void> pvz(pz);
2310 
2311  // pvx and pvy aren't equal...
2312  assert(pvx.get() != pvy.get());
2313  assert(pvx != pvy);
2314  assert(!(pvx == pvy));
2315 
2316  // ... but they share ownership ...
2317  assert(!(pvx < pvy || pvy < pvx));
2318 
2319  // ... with pvz
2320  assert(!(pvx < pvz || pvz < pvx));
2321  assert(!(pvy < pvz || pvz < pvy));
2322  }
2323 }
2324 
2325 } // namespace n_comparison
2326 
2327 namespace n_static_cast
2328 {
2329 
2330 struct X
2331 {
2332 };
2333 
2334 struct Y
2335  : public X
2336 { };
2337 
2338 void
2340 {
2341  {
2342  shared_ptr<void> pv;
2343 
2344  shared_ptr<int> pi = static_pointer_cast<int>(pv);
2345  assert(pi.get() == 0);
2346 
2347  shared_ptr<X> px = static_pointer_cast<X>(pv);
2348  assert(px.get() == 0);
2349  }
2350 
2351  {
2352  shared_ptr<int> pi(new int);
2353  shared_ptr<void> pv(pi);
2354 
2355  shared_ptr<int> pi2 = static_pointer_cast<int>(pv);
2356  assert(pi.get() == pi2.get());
2357  assert(!(pi < pi2 || pi2 < pi));
2358  assert(pi.use_count() == 3);
2359  assert(pv.use_count() == 3);
2360  assert(pi2.use_count() == 3);
2361  }
2362 
2363  {
2364  shared_ptr<X> px(new X);
2365  shared_ptr<void> pv(px);
2366 
2367  shared_ptr<X> px2 = static_pointer_cast<X>(pv);
2368  assert(px.get() == px2.get());
2369  assert(!(px < px2 || px2 < px));
2370  assert(px.use_count() == 3);
2371  assert(pv.use_count() == 3);
2372  assert(px2.use_count() == 3);
2373  }
2374 
2375  {
2376  shared_ptr<X> px(new Y);
2377 
2378  shared_ptr<Y> py = static_pointer_cast<Y>(px);
2379  assert(px.get() == py.get());
2380  assert(px.use_count() == 2);
2381  assert(py.use_count() == 2);
2382 
2383  shared_ptr<X> px2(py);
2384  assert(!(px < px2 || px2 < px));
2385  }
2386 }
2387 
2388 } // namespace n_static_cast
2389 
2390 namespace n_const_cast
2391 {
2392 
2393 struct X;
2394 
2395 void
2397 {
2398  {
2400 
2401  shared_ptr<void> px2 = const_pointer_cast<void>(px);
2402  assert(px2.get() == 0);
2403  }
2404 
2405  {
2407 
2408  shared_ptr<int> px2 = const_pointer_cast<int>(px);
2409  assert(px2.get() == 0);
2410  }
2411 
2412  {
2414 
2415  shared_ptr<X> px2 = const_pointer_cast<X>(px);
2416  assert(px2.get() == 0);
2417  }
2418 
2419  {
2420  shared_ptr<void const volatile> px(new int);
2421 
2422  shared_ptr<void> px2 = const_pointer_cast<void>(px);
2423  assert(px.get() == px2.get());
2424  assert(!(px < px2 || px2 < px));
2425  assert(px.use_count() == 2);
2426  assert(px2.use_count() == 2);
2427  }
2428 
2429  {
2430  shared_ptr<int const volatile> px(new int);
2431 
2432  shared_ptr<int> px2 = const_pointer_cast<int>(px);
2433  assert(px.get() == px2.get());
2434  assert(!(px < px2 || px2 < px));
2435  assert(px.use_count() == 2);
2436  assert(px2.use_count() == 2);
2437  }
2438 }
2439 
2440 } // namespace n_const_cast
2441 
2443 {
2444 
2445 struct V
2446 {
2447  virtual ~V() {}
2448 };
2449 
2450 struct W
2451  : public V
2452 { };
2453 
2454 void
2456 {
2457  {
2458  shared_ptr<V> pv;
2459  shared_ptr<W> pw = dynamic_pointer_cast<W>(pv);
2460  assert(pw.get() == 0);
2461  }
2462 
2463  {
2464  shared_ptr<V> pv(static_cast<V*>(0));
2465 
2466  shared_ptr<W> pw = dynamic_pointer_cast<W>(pv);
2467  assert(pw.get() == 0);
2468 
2469  shared_ptr<V> pv2(pw);
2470  assert(pv < pv2 || pv2 < pv);
2471  }
2472 
2473  {
2474  shared_ptr<V> pv(static_cast<W*>(0));
2475 
2476  shared_ptr<W> pw = dynamic_pointer_cast<W>(pv);
2477  assert(pw.get() == 0);
2478 
2479  shared_ptr<V> pv2(pw);
2480  assert(pv < pv2 || pv2 < pv);
2481  }
2482 
2483  {
2484  shared_ptr<V> pv(new V);
2485 
2486  shared_ptr<W> pw = dynamic_pointer_cast<W>(pv);
2487  assert(pw.get() == 0);
2488 
2489  shared_ptr<V> pv2(pw);
2490  assert(pv < pv2 || pv2 < pv);
2491  }
2492 
2493  {
2494  shared_ptr<V> pv(new W);
2495 
2496  shared_ptr<W> pw = dynamic_pointer_cast<W>(pv);
2497  assert(pw.get() == pv.get());
2498  assert(pv.use_count() == 2);
2499  assert(pw.use_count() == 2);
2500 
2501  shared_ptr<V> pv2(pw);
2502  assert(!(pv < pv2 || pv2 < pv));
2503  }
2504 }
2505 
2506 } // namespace n_dynamic_cast
2507 
2508 namespace n_map
2509 {
2510 
2511 struct X
2512 {
2513 };
2514 
2515 void
2517 {
2518  std::vector< shared_ptr<int> > vi;
2519 
2520  {
2521  shared_ptr<int> pi1(new int);
2522  shared_ptr<int> pi2(new int);
2523  shared_ptr<int> pi3(new int);
2524 
2525  vi.push_back(pi1);
2526  vi.push_back(pi1);
2527  vi.push_back(pi1);
2528  vi.push_back(pi2);
2529  vi.push_back(pi1);
2530  vi.push_back(pi2);
2531  vi.push_back(pi1);
2532  vi.push_back(pi3);
2533  vi.push_back(pi3);
2534  vi.push_back(pi2);
2535  vi.push_back(pi1);
2536  }
2537 
2538  std::vector< shared_ptr<X> > vx;
2539 
2540  {
2541  shared_ptr<X> px1(new X);
2542  shared_ptr<X> px2(new X);
2543  shared_ptr<X> px3(new X);
2544 
2545  vx.push_back(px2);
2546  vx.push_back(px2);
2547  vx.push_back(px1);
2548  vx.push_back(px2);
2549  vx.push_back(px1);
2550  vx.push_back(px1);
2551  vx.push_back(px1);
2552  vx.push_back(px2);
2553  vx.push_back(px1);
2554  vx.push_back(px3);
2555  vx.push_back(px2);
2556  }
2557 
2558  std::map< shared_ptr<void>, long > m;
2559 
2560  {
2561  for(std::vector< shared_ptr<int> >::iterator i = vi.begin(); i != vi.end(); ++i)
2562  {
2563  ++m[*i];
2564  }
2565  }
2566 
2567  {
2568  for(std::vector< shared_ptr<X> >::iterator i = vx.begin(); i != vx.end(); ++i)
2569  {
2570  ++m[*i];
2571  }
2572  }
2573 
2574  {
2575  for(std::map< shared_ptr<void>, long >::iterator i = m.begin(); i != m.end(); ++i)
2576  {
2577  assert(i->first.use_count() == i->second + 1);
2578  }
2579  }
2580 }
2581 
2582 } // namespace n_map
2583 
2584 namespace n_transitive
2585 {
2586 
2587 struct X
2588 {
2589  X(): next() {}
2591 };
2592 
2593 void
2595 {
2596  shared_ptr<X> p(new X);
2597  p->next = shared_ptr<X>(new X);
2598  assert(!p->next->next);
2599  p = p->next;
2600  assert(!p->next);
2601 }
2602 
2603 } // namespace n_transitive
2604 
2605 #if 0
2606 namespace n_report_1
2607 {
2608 
2609 class foo
2610 {
2611 public:
2612 
2613  foo(): m_self(this)
2614  { }
2615 
2616  void suicide()
2617  { m_self.reset(); }
2618 
2619 private:
2620  shared_ptr<foo> m_self;
2621 };
2622 
2623 void
2624  test()
2625 {
2626  foo * foo_ptr = new foo;
2627  foo_ptr->suicide();
2628 }
2629 
2630 } // namespace n_report_1
2631 #endif // 0
2632 
2633 // Test case by Per Kristensen
2634 namespace n_report_2
2635 {
2636 
2637 class foo
2638 {
2639 public:
2640 
2642  {
2643  w = s;
2644  }
2645 
2646 private:
2647 
2648  weak_ptr<foo> w;
2649 };
2650 
2651 class deleter
2652 {
2653 public:
2654 
2655  deleter(): lock(0)
2656  {
2657  }
2658 
2660  {
2661  assert(lock == 0);
2662  }
2663 
2664  void operator() (foo * p)
2665  {
2666  ++lock;
2667  delete p;
2668  --lock;
2669  }
2670 
2671 private:
2672 
2673  int lock;
2674 };
2675 
2676 void
2678 {
2679  shared_ptr<foo> s(new foo, deleter());
2680  s->setWeak(s);
2681  s.reset();
2682 }
2683 
2684 } // namespace n_report_2
2685 
2687 {
2688 
2689 class file;
2690 
2691 shared_ptr<file> fopen(char const * name, char const * mode);
2692 void
2693  fread(shared_ptr<file> f, void * data, long size);
2694 
2696 
2697 void
2699 {
2700  assert(file_instances == 0);
2701 
2702  {
2703  shared_ptr<file> pf = fopen("name", "mode");
2704  assert(file_instances == 1);
2705  fread(pf, 0, 17041);
2706  }
2707 
2708  assert(file_instances == 0);
2709 }
2710 
2711 } // namespace n_spt_incomplete
2712 
2713 namespace n_spt_pimpl
2714 {
2715 
2716 class file
2717 {
2718 private:
2719  class impl;
2720  shared_ptr<impl> pimpl_;
2721 
2722 public:
2723 
2724  file(char const * name, char const * mode);
2725 
2726  // compiler generated members are fine and useful
2727 
2728  void read(void * data, long size);
2729 
2730  long total_size() const;
2731 };
2732 
2734 
2735 void
2737 {
2738  assert(file_instances == 0);
2739 
2740  {
2741  file f("name", "mode");
2742  assert(file_instances == 1);
2743  f.read(0, 152);
2744 
2745  file f2(f);
2746  assert(file_instances == 1);
2747  f2.read(0, 894);
2748 
2749  assert(f.total_size() == 152+894);
2750 
2751  {
2752  file f3("name2", "mode2");
2753  assert(file_instances == 2);
2754  }
2755 
2756  assert(file_instances == 1);
2757  }
2758 
2759  assert(file_instances == 0);
2760 }
2761 
2762 } // namespace n_spt_pimpl
2763 
2765 {
2766 
2767 class X
2768 {
2769 public:
2770 
2771  virtual void f(int) = 0;
2772  virtual int g() = 0;
2773 
2774 protected:
2775 
2776  virtual ~X() {}
2777 };
2778 
2780 
2781 int X_instances = 0;
2782 
2783 void
2785 {
2786  assert(X_instances == 0);
2787 
2788  {
2789  shared_ptr<X> px = createX();
2790 
2791  assert(X_instances == 1);
2792 
2793  px->f(18);
2794  px->f(152);
2795 
2796  assert(px->g() == 170);
2797  }
2798 
2799  assert(X_instances == 0);
2800 }
2801 
2802 } // namespace n_spt_abstract
2803 
2805 {
2806 
2807 int X_instances = 0;
2808 
2809 class X
2810 {
2811 private:
2812  X()
2813  {
2814  ++X_instances;
2815  }
2816 
2817  ~X()
2818  {
2819  --X_instances;
2820  }
2821 
2822  class deleter;
2823  friend class deleter;
2824 
2825  class deleter
2826  {
2827  public:
2828 
2829  void operator()(X * p) { delete p; }
2830  };
2831 
2832 public:
2833 
2835  {
2836  shared_ptr<X> px(new X, X::deleter());
2837  return px;
2838  }
2839 };
2840 
2841 void
2843 {
2844  assert(X_instances == 0);
2845 
2846  {
2847  shared_ptr<X> px = X::create();
2848  assert(X_instances == 1);
2849  }
2850 
2851  assert(X_instances == 0);
2852 }
2853 
2854 } // namespace n_spt_preventing_delete
2855 
2856 namespace n_spt_array
2857 {
2858 
2859 int X_instances = 0;
2860 
2861 struct X
2862 {
2863  X()
2864  {
2865  ++X_instances;
2866  }
2867 
2868  ~X()
2869  {
2870  --X_instances;
2871  }
2872 };
2873 
2874 void
2876 {
2877  assert(X_instances == 0);
2878 
2879  #if 0
2880  {
2881  shared_ptr<X> px(new X[4], checked_array_deleter<X>());
2882  assert(X_instances == 4);
2883  }
2884  #endif // 0
2885 
2886  assert(X_instances == 0);
2887 }
2888 
2889 } // namespace n_spt_array
2890 
2891 namespace n_spt_static
2892 {
2893 
2894 class X
2895 {
2896 public:
2897 
2898  X()
2899  {
2900  }
2901 
2902 private:
2903  void operator delete(void *)
2904  {
2905  throw "n_spt_static::X::operator delete() called.";
2906  }
2907 };
2908 
2910 {
2911  void operator()(void const *) const
2912  {
2913  }
2914 };
2915 
2916 static X x;
2917 
2918 void
2920 {
2921  shared_ptr<X> px(&x, null_deleter());
2922 }
2923 
2924 } // namespace n_spt_static
2925 
2927 {
2928 
2929 int X_instances = 0;
2930 
2931 struct X
2932 {
2933  long count;
2934 
2935  X(): count(0)
2936  {
2937  ++X_instances;
2938  }
2939 
2940  ~X()
2941  {
2942  --X_instances;
2943  }
2944 };
2945 
2946 void
2948 {
2949  ++p->count;
2950 }
2951 
2952 void
2954 {
2955  if(--p->count == 0) delete p;
2956 }
2957 
2958 template< class T >
2960 {
2961  void operator()(T * p)
2962  {
2963  if(p != 0) intrusive_ptr_release(p);
2964  }
2965 };
2966 
2968 {
2969  if(p != 0) intrusive_ptr_add_ref(p);
2971  return px;
2972 }
2973 
2974 void
2976 {
2977  assert(X_instances == 0);
2978 
2979  {
2980  X * p = new X;
2981  assert(X_instances == 1);
2982  assert(p->count == 0);
2984  assert(px.get() == p);
2985  assert(p->count == 1);
2986  shared_ptr<X> px2(px);
2987  assert(px2.get() == p);
2988  assert(p->count == 1);
2989  }
2990 
2991  assert(X_instances == 0);
2992 }
2993 
2994 } // namespace n_spt_intrusive
2995 
2997 {
2998 
2999 template< class T >
3001  : private shared_ptr<T>
3002 {
3003 private:
3004  typedef shared_ptr<T> base_type;
3005 
3006 public:
3007 
3008  explicit another_ptr(T * p = 0): base_type(p)
3009  {
3010  }
3011 
3012  void reset()
3013  {
3014  base_type::reset();
3015  }
3016 
3017  T * get() const
3018  {
3019  return base_type::get();
3020  }
3021 };
3022 
3024 {
3025 public:
3026 
3027  virtual ~event_handler() {}
3028  virtual void begin() = 0;
3029  virtual void handle(int event) = 0;
3030  virtual void end() = 0;
3031 };
3032 
3035 int end_called = 0;
3036 
3038  : public event_handler
3039 {
3040 public:
3041 
3042  virtual void begin()
3043  {
3044  ++begin_called;
3045  }
3046 
3047  virtual void handle(int event)
3048  {
3049  handle_called = event;
3050  }
3051 
3052  virtual void end()
3053  {
3054  ++end_called;
3055  }
3056 };
3057 
3059 {
3061  return p;
3062 }
3063 
3065 
3066 void
3068 {
3069  p->begin();
3070  current_handler = p;
3071 }
3072 
3073 void
3074  handle_event(int event)
3075 {
3076  current_handler->handle(event);
3077 }
3078 
3079 void
3081 {
3082  current_handler->end();
3083  current_handler.reset();
3084 }
3085 
3086 template< class P >
3088 {
3089 private:
3090  P p_;
3091 
3092 public:
3093 
3094  smart_pointer_deleter(P const & p): p_(p)
3095  {
3096  }
3097 
3098  void operator()(void const *)
3099  {
3100  p_.reset();
3101  }
3102 };
3103 
3104 void
3106 {
3108 
3110 
3111  p.reset();
3112 
3113  assert(begin_called == 0);
3114 
3116 
3117  assert(begin_called == 1);
3118 
3119  assert(handle_called == 0);
3120 
3121  handle_event(17041);
3122 
3123  assert(handle_called == 17041);
3124 
3125  assert(end_called == 0);
3126 
3128 
3129  assert(end_called == 1);
3130 }
3131 
3132 } // namespace n_spt_another_sp
3133 
3134 #if 0
3135 namespace n_spt_shared_from_this
3136 {
3137 
3138 class X
3139 {
3140 public:
3141 
3142  virtual void f() = 0;
3143 
3144 protected:
3145 
3146  ~X() {}
3147 };
3148 
3149 class Y
3150 {
3151 public:
3152 
3153  virtual shared_ptr<X> getX() = 0;
3154 
3155 protected:
3156 
3157  ~Y() {}
3158 };
3159 
3160 class impl
3161  : public X, public Y
3162 {
3163 private:
3164  weak_ptr<impl> weak_this;
3165 
3166  impl(impl const &);
3167  impl & operator=(impl const &);
3168 
3169  impl() {}
3170 
3171 public:
3172 
3173  static shared_ptr<impl> create()
3174  {
3175  shared_ptr<impl> pi(new impl);
3176  pi->weak_this = pi;
3177  return pi;
3178  }
3179 
3180  virtual void f() {}
3181 
3182  virtual shared_ptr<X> getX()
3183  {
3184  shared_ptr<X> px = weak_this.lock();
3185  return px;
3186  }
3187 };
3188 
3189 void
3190  test()
3191 {
3192  shared_ptr<Y> py = impl::create();
3193  assert(py.get() != 0);
3194  assert(py.use_count() == 1);
3195 
3196  shared_ptr<X> px = py->getX();
3197  assert(px.get() != 0);
3198  assert(py.use_count() == 2);
3199 
3200  shared_ptr<Y> py2 = dynamic_pointer_cast<Y>(px);
3201  assert(py.get() == py2.get());
3202  assert(!(py < py2 || py2 < py));
3203  assert(py.use_count() == 3);
3204 }
3205 
3206 } // namespace n_spt_shared_from_this
3207 #endif // 0
3208 
3209 namespace n_spt_wrap
3210 {
3211 
3212 void
3214 {
3215 }
3216 
3217 } // namespace n_spt_wrap
3218 
3219 int main()
3220 {
3224  n_reset::test();
3225  n_access::test();
3227  n_swap::test();
3232 
3233  n_map::test();
3234 
3236  #if 0
3237  n_report_1::test();
3238  #endif // 0
3239  n_report_2::test();
3240 
3249  //n_spt_shared_from_this::test();
3250  n_spt_wrap::test();
3251 
3252  return 0;
3253 }
3254 
3255 namespace n_spt_incomplete
3256 {
3257 
3258 class file
3259 {
3260 public:
3261 
3262  file(): fread_called(false)
3263  {
3264  ++file_instances;
3265  }
3266 
3268  {
3269  assert(fread_called);
3270  --file_instances;
3271  }
3272 
3274 };
3275 
3276 shared_ptr<file> fopen(char const *, char const *)
3277 {
3278  shared_ptr<file> pf(new file);
3279  return pf;
3280 }
3281 
3282 void
3283  fread(shared_ptr<file> pf, void *, long)
3284 {
3285  pf->fread_called = true;
3286 }
3287 
3288 } // namespace n_spt_incomplete
3289 
3290 namespace n_spt_pimpl
3291 {
3292 
3294 {
3295 private:
3296  impl(impl const &);
3297  impl & operator=(impl const &);
3298 
3299  long total_size_;
3300 
3301 public:
3302 
3303  impl(char const *, char const *): total_size_(0)
3304  {
3305  ++file_instances;
3306  }
3307 
3309  {
3310  --file_instances;
3311  }
3312 
3313  void read(void *, long size)
3314  {
3315  total_size_ += size;
3316  }
3317 
3318  long total_size() const
3319  {
3320  return total_size_;
3321  }
3322 };
3323 
3324 file::file(char const * name, char const * mode): pimpl_(new impl(name, mode))
3325 {
3326 }
3327 
3328 void
3329  file::read(void * data, long size)
3330 {
3331  pimpl_->read(data, size);
3332 }
3333 
3334 long file::total_size() const
3335 {
3336  return pimpl_->total_size();
3337 }
3338 
3339 } // namespace n_spt_pimpl
3340 
3341 namespace n_spt_abstract
3342 {
3343 
3344 class X_impl
3345  : public X
3346 {
3347 private:
3348  X_impl(X_impl const &);
3349  X_impl & operator=(X_impl const &);
3350 
3351  int n_;
3352 
3353 public:
3354 
3355  X_impl(): n_(0)
3356  {
3357  ++X_instances;
3358  }
3359 
3360  virtual ~X_impl()
3361  {
3362  --X_instances;
3363  }
3364 
3365  virtual void f(int n)
3366  {
3367  n_ += n;
3368  }
3369 
3370  virtual int g()
3371  {
3372  return n_;
3373  }
3374 };
3375 
3377 {
3378  shared_ptr<X> px(new X_impl);
3379  return px;
3380 }
3381 
3382 } // namespace n_spt_abstract
n_spt_preventing_delete::X
Definition: testSharedPtr.cc:2809
n_comparison::Y
Definition: testSharedPtr.cc:2164
n_dynamic_cast::V
Definition: testSharedPtr.cc:2445
f3
int(* f3)(int, bool)
Definition: testCategories.cc:153
CLHEP::shared_ptr
Definition: Matrix/CLHEP/Utility/memory.h:66
n_assignment::A
Definition: testSharedPtr.cc:1136
n_reset::X::~X
~X()
Definition: testSharedPtr.cc:1527
n_spt_another_sp::event_handler::~event_handler
virtual ~event_handler()
Definition: testSharedPtr.cc:3027
n_spt_abstract::X::~X
virtual ~X()
Definition: testSharedPtr.cc:2776
X
Definition: testSharedPtrBasic.cc:28
n_spt_another_sp::smart_pointer_deleter
Definition: testSharedPtr.cc:3087
n_comparison
Definition: testSharedPtr.cc:2156
CLHEP::weak_ptr
Definition: Matrix/CLHEP/Utility/memory.h:67
n_const_cast::test
void test()
Definition: testSharedPtr.cc:2396
n_spt_abstract::X_impl::~X_impl
virtual ~X_impl()
Definition: testSharedPtr.cc:3360
n_spt_another_sp
Definition: testSharedPtr.cc:2996
n_comparison::test
void test()
Definition: testSharedPtr.cc:2176
n_spt_incomplete::fread
void fread(shared_ptr< file > f, void *data, long size)
Definition: testSharedPtr.cc:3283
n_constructors::deleter3::operator()
void operator()(incomplete *p)
Definition: testSharedPtr.cc:387
n_spt_static::null_deleter
Definition: testSharedPtr.cc:2909
n_assignment::Y
Definition: testSharedPtr.cc:1162
n_constructors::deleter3
Definition: testSharedPtr.cc:385
g
int g(shared_ptr< X >)
Definition: testSharedPtrConvertible.cc:46
n_reset::deleter2
void deleter2(void *p)
Definition: testSharedPtr.cc:1790
n_constructors::copy_constructor
void copy_constructor()
Definition: testSharedPtr.cc:500
n_spt_intrusive::test
void test()
Definition: testSharedPtr.cc:2975
n_assignment::X::~X
~X()
Definition: testSharedPtr.cc:1150
n_reset::Y::instances
static long instances
Definition: testSharedPtr.cc:1639
n_report_2::foo
Definition: testSharedPtr.cc:2637
n_reset::Y::~Y
~Y()
Definition: testSharedPtr.cc:1646
n_static_cast
Definition: testSharedPtr.cc:2327
CLHEP::swap
void swap(shared_ptr< P > &, shared_ptr< P > &)
Definition: Matrix/CLHEP/Utility/memory.h:1247
n_spt_incomplete::file::~file
~file()
Definition: testSharedPtr.cc:3267
n_dynamic_cast::V::~V
virtual ~V()
Definition: testSharedPtr.cc:2447
n_transitive::X::next
shared_ptr< X > next
Definition: testSharedPtr.cc:2590
n_swap::X
Definition: testSharedPtr.cc:2079
n_spt_another_sp::another_ptr::reset
void reset()
Definition: testSharedPtr.cc:3012
n_reset::A
Definition: testSharedPtr.cc:1630
n_spt_intrusive::X_instances
int X_instances
Definition: testSharedPtr.cc:2929
n_dynamic_cast::test
void test()
Definition: testSharedPtr.cc:2455
n_use_count::test
void test()
Definition: testSharedPtr.cc:2033
n_constructors::auto_ptr_constructor
void auto_ptr_constructor()
Definition: testSharedPtr.cc:848
n_spt_intrusive::intrusive_ptr_release
void intrusive_ptr_release(X *p)
Definition: testSharedPtr.cc:2953
CLHEP::shared_ptr::unique
bool unique() const
Definition: Matrix/CLHEP/Utility/memory.h:1190
n_spt_array::X::X
X()
Definition: testSharedPtr.cc:2863
n_spt_pimpl::file::impl::~impl
~impl()
Definition: testSharedPtr.cc:3308
n_constructors::Y
Definition: testSharedPtr.cc:111
n_spt_another_sp::event_handler
Definition: testSharedPtr.cc:3023
n_comparison::Z
Definition: testSharedPtr.cc:2169
n_spt_abstract::X_impl::X_impl
X_impl()
Definition: testSharedPtr.cc:3355
n_constructors::Y::instances
static long instances
Definition: testSharedPtr.cc:115
n_constructors::X::X
X()
Definition: testSharedPtr.cc:92
n_assignment::conversion_assignment
void conversion_assignment()
Definition: testSharedPtr.cc:1317
n_assignment::copy_assignment
void copy_assignment()
Definition: testSharedPtr.cc:1186
n_reset::deleted
void * deleted
Definition: testSharedPtr.cc:1787
CLHEP::shared_ptr::reset
void reset()
Definition: Matrix/CLHEP/Utility/memory.h:1120
n_spt_abstract::X_instances
int X_instances
Definition: testSharedPtr.cc:2781
n_spt_static::X::X
X()
Definition: testSharedPtr.cc:2898
n_map::test
void test()
Definition: testSharedPtr.cc:2516
n_reset::A::dummy
int dummy
Definition: testSharedPtr.cc:1632
n_reset::pointer_reset
void pointer_reset()
Definition: testSharedPtr.cc:1659
n_spt_another_sp::test
void test()
Definition: testSharedPtr.cc:3105
n_spt_another_sp::another_ptr
Definition: testSharedPtr.cc:3000
n_spt_static::X
Definition: testSharedPtr.cc:2894
n_static_cast::Y
Definition: testSharedPtr.cc:2334
n_constructors::pointer_constructor
void pointer_constructor()
Definition: testSharedPtr.cc:148
n_spt_intrusive::X::~X
~X()
Definition: testSharedPtr.cc:2940
n_spt_pimpl::test
void test()
Definition: testSharedPtr.cc:2736
n_reset
Definition: testSharedPtr.cc:1506
n_spt_intrusive::X::X
X()
Definition: testSharedPtr.cc:2935
n_report_2::deleter::~deleter
~deleter()
Definition: testSharedPtr.cc:2659
incomplete
Definition: testWeakPtr.cc:1376
n_dynamic_cast::W
Definition: testSharedPtr.cc:2450
n_spt_another_sp::get_event_handler
another_ptr< event_handler > get_event_handler()
Definition: testSharedPtr.cc:3058
n_spt_abstract::X_impl::f
virtual void f(int n)
Definition: testSharedPtr.cc:3365
n_spt_array
Definition: testSharedPtr.cc:2856
n_swap
Definition: testSharedPtr.cc:2076
CLHEP::weak_ptr::lock
shared_ptr< P > lock() const
Definition: Matrix/CLHEP/Utility/memory.h:1401
n_assignment::Y::instances
static long instances
Definition: testSharedPtr.cc:1166
CLHEP::detail::n
n
Definition: Ranlux64Engine.cc:85
n_spt_incomplete
Definition: testSharedPtr.cc:2686
n_element_type::f
void f(int &)
Definition: testSharedPtr.cc:37
n_spt_incomplete::fopen
shared_ptr< file > fopen(char const *name, char const *mode)
Definition: testSharedPtr.cc:3276
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
n_spt_another_sp::handle_called
int handle_called
Definition: testSharedPtr.cc:3034
n_spt_pimpl::file::total_size
long total_size() const
Definition: testSharedPtr.cc:3334
n_reset::Y::Y
Y()
Definition: testSharedPtr.cc:1641
n_constructors::Y::Y
Y()
Definition: testSharedPtr.cc:117
n_spt_static::null_deleter::operator()
void operator()(void const *) const
Definition: testSharedPtr.cc:2911
n_swap::test
void test()
Definition: testSharedPtr.cc:2084
n_reset::deleter_reset
void deleter_reset()
Definition: testSharedPtr.cc:1796
n_map::X
Definition: testSharedPtr.cc:2511
n_comparison::Y::dummy2
int dummy2
Definition: testSharedPtr.cc:2166
n_spt_incomplete::file::fread_called
bool fread_called
Definition: testSharedPtr.cc:3273
n_spt_intrusive::X::count
long count
Definition: testSharedPtr.cc:2933
get
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno whether or not they are still since the user counter was last ZMerrno while ZMerrno ZMerrno get() gives a(const pointer to) the latest recorded exception
n_element_type::test
void test()
Definition: testSharedPtr.cc:41
n_assignment::test
void test()
Definition: testSharedPtr.cc:1497
n_report_2::deleter::deleter
deleter()
Definition: testSharedPtr.cc:2655
n_spt_intrusive
Definition: testSharedPtr.cc:2926
n_access
Definition: testSharedPtr.cc:1957
n_constructors::A
Definition: testSharedPtr.cc:83
CLHEP
Definition: ClhepVersion.h:13
n_spt_pimpl::file::read
void read(void *data, long size)
Definition: testSharedPtr.cc:3329
n_spt_pimpl::file::impl::read
void read(void *, long size)
Definition: testSharedPtr.cc:3313
n_spt_wrap::test
void test()
Definition: testSharedPtr.cc:3213
n_constructors::test
void test()
Definition: testSharedPtr.cc:1119
CLHEP::shared_ptr::element_type
P element_type
Definition: Matrix/CLHEP/Utility/memory.h:823
n_spt_array::X::~X
~X()
Definition: testSharedPtr.cc:2868
n_element_type
Definition: testSharedPtr.cc:33
n_report_2::deleter
Definition: testSharedPtr.cc:2651
n_constructors::X
Definition: testSharedPtr.cc:88
n_spt_abstract::X_impl
Definition: testSharedPtr.cc:3344
n_spt_pimpl::file::impl::total_size
long total_size() const
Definition: testSharedPtr.cc:3318
n_spt_another_sp::another_ptr::get
T * get() const
Definition: testSharedPtr.cc:3017
n_spt_intrusive::X
Definition: testSharedPtr.cc:2931
n_spt_wrap
Definition: testSharedPtr.cc:3209
CLHEP::bad_weak_ptr
Definition: Matrix/CLHEP/Utility/memory.h:76
n_spt_abstract::test
void test()
Definition: testSharedPtr.cc:2784
n_reset::X
Definition: testSharedPtr.cc:1518
n_spt_array::X
Definition: testSharedPtr.cc:2861
n_report_2::foo::setWeak
void setWeak(shared_ptr< foo > s)
Definition: testSharedPtr.cc:2641
n_constructors::X::~X
~X()
Definition: testSharedPtr.cc:97
n_spt_another_sp::event_handler_impl::handle
virtual void handle(int event)
Definition: testSharedPtr.cc:3047
n_spt_array::test
void test()
Definition: testSharedPtr.cc:2875
n_dynamic_cast
Definition: testSharedPtr.cc:2442
n_spt_another_sp::event_handler_impl::end
virtual void end()
Definition: testSharedPtr.cc:3052
n_spt_pimpl::file::impl
Definition: testSharedPtr.cc:3293
n_spt_another_sp::end_called
int end_called
Definition: testSharedPtr.cc:3035
n_reset::X::X
X()
Definition: testSharedPtr.cc:1522
n_access::X
Definition: testSharedPtr.cc:1960
n_assignment
Definition: testSharedPtr.cc:1131
n_spt_another_sp::event_handler_impl::begin
virtual void begin()
Definition: testSharedPtr.cc:3042
n_spt_abstract::createX
shared_ptr< X > createX()
Definition: testSharedPtr.cc:3376
n_spt_static
Definition: testSharedPtr.cc:2891
main
int main()
Definition: testSharedPtr.cc:3219
CLHEP::get_pointer
P * get_pointer(shared_ptr< P > const &)
Definition: Matrix/CLHEP/Utility/memory.h:1275
n_reset::X::instances
static long instances
Definition: testSharedPtr.cc:1520
n_reset::p0
incomplete * p0
Definition: testSharedPtr.cc:1511
Y
Definition: testSharedPtrBasic.cc:34
n_spt_another_sp::event_handler_impl
Definition: testSharedPtr.cc:3037
n_spt_another_sp::smart_pointer_deleter::smart_pointer_deleter
smart_pointer_deleter(P const &p)
Definition: testSharedPtr.cc:3094
n_reset::deleter
void deleter(incomplete *)
Definition: testSharedPtr.cc:1514
n_reset::plain_reset
void plain_reset()
Definition: testSharedPtr.cc:1540
n_comparison::X::dummy
int dummy
Definition: testSharedPtr.cc:2161
n_spt_another_sp::current_handler
shared_ptr< event_handler > current_handler
Definition: testSharedPtr.cc:3064
s
Methods applicble to containers of as in std::list< LorentzVector > s
Definition: keyMergeIssues.doc:328
n_spt_another_sp::another_ptr::another_ptr
another_ptr(T *p=0)
Definition: testSharedPtr.cc:3008
n_spt_abstract::X_impl::g
virtual int g()
Definition: testSharedPtr.cc:3370
n_spt_preventing_delete::test
void test()
Definition: testSharedPtr.cc:2842
n_access::test
void test()
Definition: testSharedPtr.cc:1965
n_spt_abstract
Definition: testSharedPtr.cc:2764
n_spt_intrusive::make_shared_from_intrusive
shared_ptr< X > make_shared_from_intrusive(X *p)
Definition: testSharedPtr.cc:2967
CLHEP::weak_ptr::use_count
long use_count() const
Definition: Matrix/CLHEP/Utility/memory.h:1408
n_const_cast
Definition: testSharedPtr.cc:2390
n_spt_pimpl::file
Definition: testSharedPtr.cc:2716
n_constructors
Definition: testSharedPtr.cc:50
n_spt_preventing_delete::X::create
static shared_ptr< X > create()
Definition: testSharedPtr.cc:2834
i
long i
Definition: JamesRandomSeeding.txt:27
n_constructors::deleter_constructor
void deleter_constructor()
Definition: testSharedPtr.cc:396
n_use_count
Definition: testSharedPtr.cc:2025
Y
there is no the time needed for times is not significantly certainly not enough to warrant the additional complication So we simple provide the transform method taking a rotation which will break no code But for pure rotations around coordinate axes and boosts along we do provide such methods as rotateZ and boostZ Here the efficiency difference is marked CLHEP has these explicitly We also must keep the technically superfluous rotate(delta, axis) and boost(3 doubles or 3-vector) methods. Split of .cc files I decided it might not be worth it Y
Definition: merge-details.doc:99
n_spt_intrusive::intrusive_ptr_add_ref
void intrusive_ptr_add_ref(X *p)
Definition: testSharedPtr.cc:2947
n_spt_preventing_delete
Definition: testSharedPtr.cc:2804
n_comparison::X
Definition: testSharedPtr.cc:2159
n_spt_static::test
void test()
Definition: testSharedPtr.cc:2919
n_assignment::X::X
X()
Definition: testSharedPtr.cc:1145
n_reset::test
void test()
Definition: testSharedPtr.cc:1948
n_reset::Y
Definition: testSharedPtr.cc:1635
n_use_count::X
Definition: testSharedPtr.cc:2028
n_constructors::X::instances
static long instances
Definition: testSharedPtr.cc:90
n_assignment::X::instances
static long instances
Definition: testSharedPtr.cc:1143
n_spt_intrusive::intrusive_deleter::operator()
void operator()(T *p)
Definition: testSharedPtr.cc:2961
n_constructors::weak_ptr_constructor
void weak_ptr_constructor()
Definition: testSharedPtr.cc:756
n_static_cast::test
void test()
Definition: testSharedPtr.cc:2339
n_spt_pimpl
Definition: testSharedPtr.cc:2713
n_spt_incomplete::test
void test()
Definition: testSharedPtr.cc:2698
n_transitive::test
void test()
Definition: testSharedPtr.cc:2594
n_spt_abstract::X
Definition: testSharedPtr.cc:2767
n_assignment::A::dummy
int dummy
Definition: testSharedPtr.cc:1138
n_assignment::auto_ptr_assignment
void auto_ptr_assignment()
Definition: testSharedPtr.cc:1402
n_spt_another_sp::handle_event
void handle_event(int event)
Definition: testSharedPtr.cc:3074
n_spt_incomplete::file
Definition: testSharedPtr.cc:3258
n_spt_another_sp::smart_pointer_deleter::operator()
void operator()(void const *)
Definition: testSharedPtr.cc:3098
f2
int(* f2)(int)
Definition: testCategories.cc:152
n_spt_incomplete::file::file
file()
Definition: testSharedPtr.cc:3262
count
user code seldom needs to call this function directly ZMerrno count() Return the(integer) number of ZMthrow 'n exceptions ever recorded via ZMerrno.write()
n_map
Definition: testSharedPtr.cc:2508
n_spt_intrusive::intrusive_deleter
Definition: testSharedPtr.cc:2959
CLHEP::shared_ptr::swap
void swap(shared_ptr< P > &)
Definition: Matrix/CLHEP/Utility/memory.h:972
x
any side effects of that construction would occur twice The semantics of throw x
Definition: whyZMthrowRethrows.txt:37
n_assignment::X
Definition: testSharedPtr.cc:1141
n_constructors::pc0_test
void pc0_test(T *p)
Definition: testSharedPtr.cc:136
n_assignment::Y::~Y
~Y()
Definition: testSharedPtr.cc:1173
n_assignment::Y::Y
Y()
Definition: testSharedPtr.cc:1168
CLHEP::shared_ptr::get
P * get() const
Definition: Matrix/CLHEP/Utility/memory.h:1183
n_report_2
Definition: testSharedPtr.cc:2634
this
any side effects of that construction would occur twice The semantics of throw on the other are that x is not constructed an extra time The macro used achievs this
Definition: whyZMthrowRethrows.txt:41
n_spt_another_sp::remove_event_handler
void remove_event_handler()
Definition: testSharedPtr.cc:3080
n_constructors::default_constructor
void default_constructor()
Definition: testSharedPtr.cc:56
n_spt_another_sp::begin_called
int begin_called
Definition: testSharedPtr.cc:3033
n_constructors::m
int m
Definition: testSharedPtr.cc:370
n_spt_pimpl::file::impl::impl
impl(char const *, char const *)
Definition: testSharedPtr.cc:3303
name
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno whether or not they are still since the user counter was last ZMerrno name() gives the(string) name of the latest recorded exception
n_transitive::X
Definition: testSharedPtr.cc:2587
n_constructors::Y::~Y
~Y()
Definition: testSharedPtr.cc:122
CLHEP::shared_ptr::use_count
long use_count() const
Definition: Matrix/CLHEP/Utility/memory.h:1197
n_report_2::test
void test()
Definition: testSharedPtr.cc:2677
n_spt_another_sp::install_event_handler
void install_event_handler(shared_ptr< event_handler > p)
Definition: testSharedPtr.cc:3067
n_static_cast::X
Definition: testSharedPtr.cc:2330
n_transitive::X::X
X()
Definition: testSharedPtr.cc:2589
n_spt_pimpl::file_instances
int file_instances
Definition: testSharedPtr.cc:2733
n_transitive
Definition: testSharedPtr.cc:2584
n_constructors::A::dummy
int dummy
Definition: testSharedPtr.cc:85