1 #ifndef cetlib_value_ptr_h 2 #define cetlib_value_ptr_h 64 #include <type_traits> 72 template <
class Element,
76 template <
class Element>
80 template <
class Element>
82 template <
class Element>
85 template <
class Element,
87 class Deleter = std::default_delete<Element>>
90 template <
class E,
class C,
class D>
93 template <class
E, class
C, class
D>
95 template <class E, class C, class
D>
98 template <class E, class C, class
D>
99 bool operator==(
value_ptr<E, C,
D> const&,
std::nullptr_t const&);
100 template <class E, class C, class
D>
101 bool operator!=(
value_ptr<E, C,
D> const&,
std::nullptr_t const&);
103 template <class E, class C, class
D>
104 bool operator==(
std::nullptr_t const&,
value_ptr<E, C,
D> const&);
105 template <class E, class C, class
D>
106 bool operator!=(
std::nullptr_t const&,
value_ptr<E, C,
D> const&);
108 template <class E, class C, class
D>
111 template <class E, class C, class
D>
114 template <class E, class C, class
D>
117 template <class E, class C, class
D>
124 struct
cet::_::has_clone {
126 typedef char (&yes_t)[1];
127 typedef char (&no_t)[2];
129 template <
class U, U* (U::*)() const = &U::clone>
135 static no_t
test(...);
138 static bool constexpr
value{
sizeof(test<T>(0)) ==
sizeof(yes_t)};
143 template <
class Element>
149 return new Element{*p};
155 template <
class Element>
168 template <
class Element,
bool>
175 template <
class Element>
184 template <
class Element,
class Cloner,
class Deleter>
198 :
public std::is_convertible<std::add_pointer_t<P>, pointer> {};
213 static_assert(is_compatible_v<E2>,
214 "value_ptr<>'s pointee type is incompatible!");
216 !std::is_polymorphic_v<E2> ||
218 "value_ptr<>'s pointee type would slice when copying!");
226 std::enable_if_t<is_compatible_v<E2>>* =
nullptr)
227 :
p{clone_from(other.
p)}
235 std::enable_if_t<is_compatible_v<E2>>* =
nullptr) noexcept
258 std::enable_if_t<is_compatible_v<E2>,
value_ptr&>
276 std::enable_if_t<is_compatible_v<E2>,
value_ptr&>
293 explicit operator bool()
const noexcept {
return get(); }
322 return p ? Cloner{}(
p) :
nullptr;
333 template <
class E,
class C,
class D>
343 template <
class E,
class C,
class D>
347 return x.
get() == y.
get();
350 template <
class E,
class C,
class D>
357 template <
class E,
class C,
class D>
364 template <
class E,
class C,
class D>
371 template <
class E,
class C,
class D>
378 template <
class E,
class C,
class D>
388 template <
class E,
class C,
class D>
392 using CT = std::common_type_t<typename value_ptr<E, C, D>::pointer,
394 return std::less<CT>{}(x.get(),
y.get());
397 template <
class E,
class C,
class D>
404 template <
class E,
class C,
class D>
411 template <
class E,
class C,
class D>
value_ptr(value_ptr &&other) noexcept
std::add_pointer_t< T > pointer
pointer release() noexcept
constexpr bool operator>=(exempt_ptr< E >, exempt_ptr< E >)
void swap(value_ptr &other) noexcept
value_ptr(value_ptr const &other)
value_ptr & operator=(value_ptr const &other)
std::pair< float, std::string > P
value_ptr & operator=(std::nullptr_t) noexcept
Element * operator()(Element *p) const
constexpr value_ptr(std::nullptr_t) noexcept
value_ptr(E2 *other) noexcept
value_ptr(value_ptr< E2, Cloner, Deleter > &&other, std::enable_if_t< is_compatible_v< E2 >> *=nullptr) noexcept
reference operator*() const
Element * operator()(Element *p) const
value_ptr(value_ptr< E2, Cloner, Deleter > const &other, std::enable_if_t< is_compatible_v< E2 >> *=nullptr)
std::enable_if_t< is_compatible_v< E2 >, value_ptr & > operator=(value_ptr< E2, Cloner, Deleter > const &other)
std::enable_if_t< is_compatible_v< E2 >, value_ptr & > operator=(value_ptr< E2, Cloner, Deleter > &&other) noexcept
QTextStream & reset(QTextStream &s)
value_ptr & operator=(value_ptr &&other) noexcept
void swap(value_ptr< E, C, D > &, value_ptr< E, C, D > &) noexcept
constexpr bool operator==(exempt_ptr< E >, exempt_ptr< E >) noexcept
constexpr bool operator>(exempt_ptr< E >, exempt_ptr< E >)
yes & test(std::ostream &)
void swap(exempt_ptr< E > &, exempt_ptr< E > &) noexcept
pointer operator->() const noexcept
pointer clone_from(P const p) const
constexpr bool operator!=(exempt_ptr< E >, exempt_ptr< E >) noexcept
constexpr value_ptr() noexcept
void reset(pointer t=pointer()) noexcept
std::add_lvalue_reference_t< T > reference
pointer get() const noexcept