Documentation of CSL
std_shared_ptr_inheritance.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #pragma once
24 #define INHERIT_SHARED_PTR_CONSTRUCTOR(Class, type)\
25  template<class ...Args> \
26  using _Constructible \
27  = std::shared_ptr<type>::_Constructible<Args...>; \
28  template<class Arg> \
29  using _Assignable \
30  = std::shared_ptr<type>::_Assignable<Arg>; \
31  \
32  constexpr Class(): std::shared_ptr<type>() {}; \
33  \
34  template< class Y , class = _Constructible<Y*> > \
35  explicit Class( Y* ptr ) \
36  :std::shared_ptr<type>(ptr) {} \
37  \
38  template< class Y, class Deleter, \
39  class = _Constructible<Y*, Deleter> > \
40  Class( Y* ptr, Deleter d ) \
41  :std::shared_ptr<type>(ptr, d) {} \
42  \
43  template< class Y, class Deleter, class Alloc, \
44  class = _Constructible<Y*, Deleter, Alloc> > \
45  Class( Y* ptr, Deleter d, Alloc alloc ) \
46  :std::shared_ptr<type>(ptr, d, alloc) {} \
47  \
48  constexpr Class( std::nullptr_t ) \
49  :std::shared_ptr<type>(nullptr) {} \
50  \
51  template< class Deleter > \
52  Class( std::nullptr_t, Deleter d ) \
53  :std::shared_ptr<type>(nullptr, d) {} \
54  \
55  template< class Deleter, class Alloc > \
56  Class( std::nullptr_t, Deleter d, Alloc alloc ) \
57  :std::shared_ptr<type>(nullptr, d, alloc) {} \
58  \
59  template< class Y > \
60  Class( const shared_ptr<Y>& r, type *ptr ) \
61  :std::shared_ptr<type>(r, ptr) {} \
62  \
63  Class( const shared_ptr<type>& r ) \
64  :std::shared_ptr<type>(r) {} \
65  \
66  template< class Y , class = _Constructible<const std::shared_ptr<Y>&> > \
67  Class( const shared_ptr<Y>& r ) \
68  :std::shared_ptr<type>(r) {} \
69  \
70  Class( shared_ptr<type>&& r ) \
71  :std::shared_ptr<type>(r) {} \
72  \
73  template< class Y, class = _Constructible<std::shared_ptr<Y>> > \
74  Class( shared_ptr<Y>&& r ) \
75  :std::shared_ptr<type>(r) {} \
76  \
77  template< class Y, class = _Constructible<const std::weak_ptr<Y>&> > \
78  explicit Class( const std::weak_ptr<Y>& r ) \
79  :std::shared_ptr<type>(r) {} \
80  \
81  template< class Y, class Deleter, \
82  class = _Constructible<std::unique_ptr<Y, Deleter>> > \
83  Class( std::unique_ptr<Y,Deleter>&& r ) \
84  :std::shared_ptr<type>(std::move(r)) {}
85 
86 #define DEFINE_SHARED_PTR_OPERATOR(Class)\
87 inline bool operator==( \
88  Class const &expr, \
89  std::nullptr_t \
90  ) \
91 { \
92  return expr.get() == nullptr; \
93 } \
94 inline bool operator==( \
95  std::nullptr_t, \
96  Class const &expr \
97  ) \
98 { \
99  return expr.get() == nullptr; \
100 } \
101 inline bool operator!=( \
102  Class const &expr, \
103  std::nullptr_t \
104  ) \
105 { \
106  return expr.get() != nullptr; \
107 } \
108 inline bool operator!=( \
109  std::nullptr_t, \
110  Class const &expr \
111  ) \
112 { \
113  return expr.get() != nullptr; \
114 }
115