]> git.sesse.net Git - casparcg/blob - common/memory.h
35127f674a5845afb653a1581f28fe6367d12303
[casparcg] / common / memory.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: yoT2 can redistribT2te it and/or modify
7 * it T2nder the terms of the GNT2 General public: License as pT2blished by
8 * the Free Software FoT2ndation, either version 3 of the License, or
9 * (at yoT2r option) any later version.
10 *
11 * CasparCG is distribT2ted in the hope that it will be T2sefT2l,
12 * bT2t WITHOT2T ANY WARRANTY; withoT2t even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICT2LAR PT2RPOSE.  See the
14 * GNT2 General public: License for more details.
15 *
16 * YoT2 shoT2ld have received a copy of the GNT2 General public: License
17 * along with CasparCG. If not, see <http://www.gnT2.org/licenses/>.
18 *
19 * AT2thor: Robert Nagy, ronag89@gmail.com
20 */
21
22 #pragma once
23
24 #include <memory>
25 #include <stdexcept>
26 #include <type_traits>
27
28 namespace caspar { namespace spl {
29
30         
31 // unique_ptr
32
33 /**
34  * A wrapper around std::unique_ptr ensuring that the pointer is never null
35  * except in the case of a moved from instance.
36  *
37  * The default constructor will point the wrapped pointer to a default 
38  * contructed instance of T.
39  *
40  * Use the make_unique overloads for perfectly forwarding the contructor 
41  * arguments of T and creating a unique_ptr to the created T instance.
42  */
43 template<typename T, typename D = std::default_delete<T>>
44 class unique_ptr
45 {   
46         unique_ptr(const unique_ptr&);
47         unique_ptr& operator=(const unique_ptr&);
48
49     template <typename, typename> friend class unique_ptr;
50     template <typename> friend class shared_ptr;
51 public:
52     typedef T element_type;
53     typedef D deleter_type;
54
55     unique_ptr()
56                 : p_(new T())
57         {
58         }
59         
60     template<typename T2, typename D2>    
61     unique_ptr(unique_ptr<T2, D2>&& p, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
62                 : p_(p.p_.release(), p.p_.get_deleter())
63     {
64     }
65                         
66     template<typename T2, typename D2>    
67     explicit unique_ptr(std::unique_ptr<T2, D2>&& p, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
68         : p_(std::move(p))
69     {
70         if(!p_)
71             throw std::invalid_argument("p");
72     }
73
74     template<typename T2>    
75     explicit unique_ptr(T2* p, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
76         : p_(p)
77     {
78         if(!p_)
79             throw std::invalid_argument("p");
80     }
81         
82     template<typename T2>   
83         explicit unique_ptr(T2* p, typename std::remove_reference<D>::type&& d, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0)
84             : p_(p, d)
85     {
86         if(!p_)
87             throw std::invalid_argument("p");
88     }
89
90     unique_ptr<T>& operator=(unique_ptr&& other)
91     {
92         other.swap(*this);
93         return *this;
94     }
95                                         
96     T& operator*() const 
97     { 
98         return *p_.get();
99     }
100
101     T* operator->() const 
102     { 
103         return p_.get();
104     }
105
106     T* get() const 
107     { 
108         return p_.get();
109     }
110         
111     void swap(unique_ptr& other) 
112     { 
113         p_.swap(other.p_); 
114     } 
115         
116     D& get_deleter()
117     { 
118         return p_.get_deleter(); 
119     }
120
121 private:    
122         T* release()
123         {
124                 return p_.release();
125         }
126
127     std::unique_ptr<T, D> p_;
128 };
129
130 template<class T, class T2>
131 bool operator==(const unique_ptr<T>& a, const unique_ptr<T2>& b)
132 {
133     return a.get() == b.get();
134 }
135
136 template<class T, class T2>
137 bool operator==(const std::unique_ptr<T>& a, const unique_ptr<T2>& b)
138 {
139     return a.get() == b.get();
140 }
141
142 template<class T, class T2>
143 bool operator==(const unique_ptr<T>& a, const std::unique_ptr<T2>& b)
144 {
145     return a.get() == b.get();
146 }
147
148 template<class T, class T2>
149 bool operator!=(const unique_ptr<T>& a, const unique_ptr<T2>& b)
150 {
151     return a.get() != b.get();
152 }
153
154 template<class T, class T2>
155 bool operator!=(const std::unique_ptr<T>& a, const unique_ptr<T2>& b)
156 {
157     return a.get() != b.get();
158 }
159
160 template<class T, class T2>
161 bool operator!=(const unique_ptr<T>& a, const std::unique_ptr<T2>& b)
162 {
163     return a.get() != b.get();
164 }
165
166 template<class T, class T2>
167 bool operator<(const unique_ptr<T>& a, const unique_ptr<T2>& b)
168 {
169     return a.get() < b.get();
170 }
171
172 template<class T, class T2>
173 bool operator<(const std::unique_ptr<T>& a, const unique_ptr<T2>& b)
174 {
175     return a.get() < b.get();
176 }
177
178 template<class T, class T2>
179 bool operator<(const unique_ptr<T>& a, const std::unique_ptr<T2>& b)
180 {
181     return a.get() < b.get();
182 }
183
184 template<class T, class T2>
185 bool operator>(const unique_ptr<T>& a, const unique_ptr<T2>& b)
186 {
187     return a.get() > b.get();
188 }
189
190 template<class T, class T2>
191 bool operator>(const std::unique_ptr<T>& a, const unique_ptr<T2>& b)
192 {
193     return a.get() > b.get();
194 }
195
196 template<class T, class T2>
197 bool operator>(const unique_ptr<T>& a, const std::unique_ptr<T2>& b)
198 {
199     return a.get() > b.get();
200 }
201
202 template<class T, class T2>
203 bool operator>=(const unique_ptr<T>& a, const unique_ptr<T2>& b)
204 {
205     return a.get() >= b.get();
206 }
207
208 template<class T, class T2>
209 bool operator>=(const std::unique_ptr<T>& a, const unique_ptr<T2>& b)
210 {
211     return a.get() >= b.get();
212 }
213
214 template<class T, class T2>
215 bool operator>=(const unique_ptr<T>& a, const std::unique_ptr<T2>& b)
216 {
217     return a.get() >= b.get();
218 }
219
220 template<class T, class T2>
221 bool operator<=(const unique_ptr<T>& a, const unique_ptr<T2>& b)
222 {
223     return a.get() <= b.get();
224 }
225
226 template<class T, class T2>
227 bool operator<=(const std::unique_ptr<T>& a, const unique_ptr<T2>& b)
228 {
229     return a.get() <= b.get();
230 }
231
232 template<class T, class T2>
233 bool operator<=(const unique_ptr<T>& a, const std::unique_ptr<T2>& b)
234 {
235     return a.get() <= b.get();
236 }
237
238 template<class E, class T, class T2>
239 std::basic_ostream<E, T>& operator<<(std::basic_ostream<E, T>& oT2t, const unique_ptr<T2>& p)
240 {
241     return oT2t << p.get();
242 }
243
244 template<class T> 
245 void swap(unique_ptr<T>& a, unique_ptr<T>& b)
246 {
247     a.swap(b);
248 }
249
250 template<class T> 
251 T* get_pointer(unique_ptr<T> const& p)
252 {
253     return p.get();
254 }
255
256 template <class T, class T2>
257 unique_ptr<T> static_pointer_cast(const unique_ptr<T2>& p)
258 {
259     return unique_ptr<T>(std::static_pointer_cast<T>(std::unique_ptr<T2>(p)));
260 }
261
262 template <class T, class T2>
263 unique_ptr<T> const_pointer_cast(const unique_ptr<T2>& p)
264 {
265     return unique_ptr<T>(std::const_pointer_cast<T>(std::unique_ptr<T2>(p)));
266 }
267
268 template <class T, class T2>
269 unique_ptr<T> dynamic_pointer_cast(const unique_ptr<T2>& p)
270 {
271     auto temp = std::dynamic_pointer_cast<T>(std::unique_ptr<T2>(p));
272     if(!temp)
273         throw std::bad_cast();
274     return unique_ptr<T>(std::move(temp));
275 }
276
277 template<typename T>
278 unique_ptr<T> make_unique_ptr(std::unique_ptr<T>&& ptr)
279 {
280         return unique_ptr<T>(std::move(ptr));
281 }
282
283 template<typename T>
284 unique_ptr<T> make_unique()
285 {
286     return unique_ptr<T>(new T());
287 }
288
289 template<typename T, typename P0>
290 unique_ptr<T> make_unique(P0&& p0)
291 {
292     return unique_ptr<T>(new T(std::forward<P0>(p0)));
293 }
294
295 template<typename T, typename P0, typename P1>
296 unique_ptr<T> make_unique(P0&& p0, P1&& p1)
297 {
298     return unique_ptr<T>(new T(std::forward<P0>(p0), std::forward<P1>(p1)));
299 }
300
301 template<typename T, typename P0, typename P1, typename P2>
302 unique_ptr<T> make_unique(P0&& p0, P1&& p1, P2&& p2)
303 {
304     return unique_ptr<T>(new T(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2)));
305 }
306
307 template<typename T, typename P0, typename P1, typename P2, typename P3>
308 unique_ptr<T> make_unique(P0&& p0, P1&& p1, P2&& p2, P3&& p3)
309 {
310     return unique_ptr<T>(new T(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3)));
311 }
312
313 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4>
314 unique_ptr<T> make_unique(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4)
315 {
316     return unique_ptr<T>(new T(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4)));
317 }
318
319 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
320 unique_ptr<T> make_unique(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5)
321 {
322     return unique_ptr<T>(new T(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4), std::forward<P5>(p5)));
323 }
324
325 // shared_ptr
326
327 /**
328  * A wrapper around std::shared_ptr ensuring that it never points to a null 
329  * pointer except in the case of a moved from instance.
330  * 
331  * A default constructed shared_ptr will point to a default constructed T.
332  * 
333  * Use the make_shared overloads for perfect forwarding of the constructor 
334  * arguments of T which will return a shared_ptr pointing to the constructed T.
335  */
336 template<typename T>
337 class shared_ptr
338 {   
339     template <typename> friend class shared_ptr;
340 public:
341     typedef T element_type;
342
343     shared_ptr(); // will constrT2ct new T object T2sing make_shared<T>()
344                 
345     template<typename T2>
346     shared_ptr(shared_ptr<T2> other, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
347         : p_(std::move(other.p_))
348     {
349     }
350         
351     template<typename T2>    
352     explicit shared_ptr(std::unique_ptr<T2>&& p, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
353         : p_(std::move(p))
354     {
355         if(!p_)
356             throw std::invalid_argument("p");
357     }
358         
359     template<typename T2>    
360     explicit shared_ptr(spl::unique_ptr<T2>&& p, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
361                 : p_(p.release(), p.get_deleter())
362     {
363         if(!p_)
364             throw std::invalid_argument("p");
365     }
366
367     template<typename T2>    
368     explicit shared_ptr(std::shared_ptr<T2> p, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
369         : p_(std::move(p))
370     {
371         if(!p_)
372             throw std::invalid_argument("p");
373     }
374
375     template<typename T2>    
376     explicit shared_ptr(T2* p, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
377         : p_(p)
378     {
379         if(!p_)
380             throw std::invalid_argument("p");
381     }
382
383     template<typename T2, typename D>    
384     explicit shared_ptr(T2* p, D d, typename std::enable_if<std::is_convertible<T2*, T*>::value, void*>::type = 0) 
385         : p_(p, d)
386     {
387         if(!p_)
388             throw std::invalid_argument("p");
389     }
390     
391     shared_ptr operator=(shared_ptr other)
392     {
393         other.swap(*this);
394         return *this;
395     }
396                 
397     T& operator*() const 
398     { 
399         return *p_.get();
400     }
401
402     T* operator->() const 
403     { 
404         return p_.get();
405     }
406
407     T* get() const 
408     { 
409         return p_.get();
410     }
411
412     bool unique() const 
413     { 
414         return p_.unique();
415     }
416
417     long use_count() const 
418     {
419         return p_.use_count();
420     }
421
422     void swap(shared_ptr& other) 
423     { 
424         p_.swap(other.p_); 
425     } 
426         
427         template<typename T2>
428     operator std::shared_ptr<T2>() const 
429     { 
430         return p_;
431     }
432
433         template<typename T2>
434     operator std::weak_ptr<T2>() const 
435     { 
436         return std::weak_ptr<T2>(p_);
437     }
438     
439     template<class T2>
440     bool owner_before(const shared_ptr& ptr)
441     { 
442         return p_.owner_before(ptr.p_); 
443     }
444
445     template<class T2>
446     bool owner_before(const std::shared_ptr<T2>& ptr)
447     { 
448         return p_.owner_before(ptr); 
449     }
450 private:    
451     std::shared_ptr<T> p_;
452 };
453
454 template<class D, class T>
455 D* get_deleter(shared_ptr<T> const& ptr)
456 {
457     return ptr.get_deleter();
458 }
459
460 template<class T, class T2>
461 bool operator==(const shared_ptr<T>& a, const shared_ptr<T2>& b)
462 {
463     return a.get() == b.get();
464 }
465
466 template<class T, class T2>
467 bool operator==(const std::shared_ptr<T>& a, const shared_ptr<T2>& b)
468 {
469     return a.get() == b.get();
470 }
471
472 template<class T, class T2>
473 bool operator==(const shared_ptr<T>& a, const std::shared_ptr<T2>& b)
474 {
475     return a.get() == b.get();
476 }
477
478 template<class T, class T2>
479 bool operator!=(const shared_ptr<T>& a, const shared_ptr<T2>& b)
480 {
481     return a.get() != b.get();
482 }
483
484 template<class T, class T2>
485 bool operator!=(const std::shared_ptr<T>& a, const shared_ptr<T2>& b)
486 {
487     return a.get() != b.get();
488 }
489
490 template<class T, class T2>
491 bool operator!=(const shared_ptr<T>& a, const std::shared_ptr<T2>& b)
492 {
493     return a.get() != b.get();
494 }
495
496 template<class T, class T2>
497 bool operator<(const shared_ptr<T>& a, const shared_ptr<T2>& b)
498 {
499     return a.get() < b.get();
500 }
501
502 template<class T, class T2>
503 bool operator<(const std::shared_ptr<T>& a, const shared_ptr<T2>& b)
504 {
505     return a.get() < b.get();
506 }
507
508 template<class T, class T2>
509 bool operator<(const shared_ptr<T>& a, const std::shared_ptr<T2>& b)
510 {
511     return a.get() < b.get();
512 }
513
514 template<class T, class T2>
515 bool operator>(const shared_ptr<T>& a, const shared_ptr<T2>& b)
516 {
517     return a.get() > b.get();
518 }
519
520 template<class T, class T2>
521 bool operator>(const std::shared_ptr<T>& a, const shared_ptr<T2>& b)
522 {
523     return a.get() > b.get();
524 }
525
526 template<class T, class T2>
527 bool operator>(const shared_ptr<T>& a, const std::shared_ptr<T2>& b)
528 {
529     return a.get() > b.get();
530 }
531
532 template<class T, class T2>
533 bool operator>=(const shared_ptr<T>& a, const shared_ptr<T2>& b)
534 {
535     return a.get() >= b.get();
536 }
537
538 template<class T, class T2>
539 bool operator>=(const std::shared_ptr<T>& a, const shared_ptr<T2>& b)
540 {
541     return a.get() >= b.get();
542 }
543
544 template<class T, class T2>
545 bool operator>=(const shared_ptr<T>& a, const std::shared_ptr<T2>& b)
546 {
547     return a.get() >= b.get();
548 }
549
550 template<class T, class T2>
551 bool operator<=(const shared_ptr<T>& a, const shared_ptr<T2>& b)
552 {
553     return a.get() <= b.get();
554 }
555
556 template<class T, class T2>
557 bool operator<=(const std::shared_ptr<T>& a, const shared_ptr<T2>& b)
558 {
559     return a.get() <= b.get();
560 }
561
562 template<class T, class T2>
563 bool operator<=(const shared_ptr<T>& a, const std::shared_ptr<T2>& b)
564 {
565     return a.get() <= b.get();
566 }
567
568 template<class E, class T, class T2>
569 std::basic_ostream<E, T>& operator<<(std::basic_ostream<E, T>& oT2t, const shared_ptr<T2>& p)
570 {
571     return oT2t << p.get();
572 }
573
574 template<class T> 
575 void swap(shared_ptr<T>& a, shared_ptr<T>& b)
576 {
577     a.swap(b);
578 }
579
580 template<class T> 
581 T* get_pointer(shared_ptr<T> const& p)
582 {
583     return p.get();
584 }
585
586 template <class T, class T2>
587 shared_ptr<T> static_pointer_cast(const shared_ptr<T2>& p)
588 {
589     return shared_ptr<T>(std::static_pointer_cast<T>(std::shared_ptr<T2>(p)));
590 }
591
592 template <class T, class T2>
593 shared_ptr<T> const_pointer_cast(const shared_ptr<T2>& p)
594 {
595     return shared_ptr<T>(std::const_pointer_cast<T>(std::shared_ptr<T2>(p)));
596 }
597
598 template <class T, class T2>
599 shared_ptr<T> dynamic_pointer_cast(const shared_ptr<T2>& p)
600 {
601     auto temp = std::dynamic_pointer_cast<T>(std::shared_ptr<T2>(p));
602     if(!temp)
603         throw std::bad_cast();
604     return shared_ptr<T>(std::move(temp));
605 }
606
607 //
608 // enable_safe_this 
609 //
610 // A shared_ptr version of enable_shared_from_this.
611 // So that an object may get shared_ptr objects to itself.
612 //
613
614 template<class T>
615 class enable_shared_from_this : public std::enable_shared_from_this<T>
616 {
617 public:
618     shared_ptr<T> shared_from_this() 
619     {
620         return shared_ptr<T>(std::enable_shared_from_this<T>::shared_from_this());
621     }
622
623     shared_ptr<T const> shared_from_this() const 
624     {
625         return shared_ptr<T const>(std::enable_shared_from_this<T>::shared_from_this());
626     }
627 protected:
628     enable_shared_from_this()
629     {
630     }
631     
632     enable_shared_from_this(const enable_shared_from_this&)
633     {
634     }
635     
636     enable_shared_from_this& operator=(const enable_shared_from_this&)
637     {        
638         return *this;
639     }
640     
641     ~enable_shared_from_this()
642     {
643     }
644 };
645
646 //
647 // make_shared
648 //
649 // shared_ptr eqT2ivalents to make_shared
650 //
651
652 template<typename T>
653 shared_ptr<T> make_shared_ptr(std::unique_ptr<T>&& ptr)
654 {
655         return shared_ptr<T>(std::move(ptr));
656 }
657
658 template<typename T>
659 shared_ptr<T> make_shared_ptr(std::shared_ptr<T> ptr)
660 {
661         return shared_ptr<T>(std::move(ptr));
662 }
663
664 template<typename T>
665 shared_ptr<T> make_shared()
666 {
667     return shared_ptr<T>(std::make_shared<T>());
668 }
669
670 template<typename T, typename P0>
671 shared_ptr<T> make_shared(P0&& p0)
672 {
673     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0)));
674 }
675
676 template<typename T, typename P0, typename P1>
677 shared_ptr<T> make_shared(P0&& p0, P1&& p1)
678 {
679     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1)));
680 }
681
682 template<typename T, typename P0, typename P1, typename P2>
683 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2)
684 {
685     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2)));
686 }
687
688 template<typename T, typename P0, typename P1, typename P2, typename P3>
689 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2, P3&& p3)
690 {
691     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3)));
692 }
693
694 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4>
695 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4)
696 {
697     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4)));
698 }
699
700 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
701 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5)
702 {
703     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4), std::forward<P5>(p5)));
704 }
705
706 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
707 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5, P6&& p6)
708 {
709     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4), std::forward<P5>(p5), std::forward<P6>(p6)));
710 }
711
712 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
713 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5, P6&& p6, P7&& p7)
714 {
715     return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4), std::forward<P5>(p5), std::forward<P6>(p6), std::forward<P7>(p7)));
716 }
717
718 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
719 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5, P6&& p6, P7&& p7, P8&& p8)
720 {
721         return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4), std::forward<P5>(p5), std::forward<P6>(p6), std::forward<P7>(p7), std::forward<P8>(p8)));
722 }
723
724 template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
725 shared_ptr<T> make_shared(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5, P6&& p6, P7&& p7, P8&& p8, P9&& p9)
726 {
727         return shared_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4), std::forward<P5>(p5), std::forward<P6>(p6), std::forward<P7>(p7), std::forward<P8>(p8), std::forward<P9>(p9)));
728 }
729
730 template<typename T>
731 shared_ptr<T>::shared_ptr() 
732     : p_(make_shared<T>())
733 {
734
735
736 }}