Lagrange
ptr.h
1// Source: https://github.com/X-czh/smart_ptr
2// SPDX-License-Identifier: MIT
3//
4// This file has been modified by Adobe.
5//
6// All modifications are Copyright 2022 Adobe.
7
8#pragma once
9
10#include <tuple> // tuple, get(tuple)
11
12namespace lagrange::internal {
13
14// ptr class that wraps the deleter, use tuple for Empty Base Optimization
15
16template <typename T, typename D>
17class ptr
18{
19public:
20 using pointer = T*;
21 using deleter_type = D;
22
23 constexpr ptr() noexcept = default;
24
25 ptr(pointer p)
26 : _impl_t{}
27 {
28 _impl_ptr() = p;
29 }
30
31 template <typename Del>
32 ptr(pointer p, Del&& d)
33 : _impl_t{p, std::forward<Del>(d)}
34 {}
35
36 ~ptr() noexcept = default;
37
38 pointer& _impl_ptr() { return std::get<0>(_impl_t); }
39 pointer _impl_ptr() const { return std::get<0>(_impl_t); }
40 deleter_type& _impl_deleter() { return std::get<1>(_impl_t); }
41 const deleter_type& _impl_deleter() const { return std::get<1>(_impl_t); }
42
43private:
44 std::tuple<pointer, deleter_type> _impl_t;
45};
46
47} // namespace lagrange::internal
Definition: ptr.h:18
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21