pars 0.2.1.99
Loading...
Searching...
No Matches
own.h
Go to the documentation of this file.
1/*
2Copyright (c) 2025 Giuseppe Roberti.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice,
12this list of conditions and the following disclaimer in the documentation and/or
13other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors
16may be used to endorse or promote products derived from this software without
17specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30#pragma once
31
32#include "clev/err.h"
33#include "clev/iface.h"
34
35namespace clev
36{
37
38template<typename wrap_t>
39struct own : iface<wrap_t>
40{
42
43 using parent::parent;
44
45 own(const own& rhs) noexcept
46 requires requires(wrap_t* d, const wrap_t s) {
47 { iface<wrap_t>::copy(d, s) } -> std::convertible_to<clev::expected<void>>;
48 }
49 {
50 iface<wrap_t>::copy(&(own::v), rhs.v).or_exit();
51 }
52
53 own& operator=(const own& rhs) noexcept
54 requires requires(wrap_t* d, const wrap_t s) {
55 { iface<wrap_t>::copy(d, s) } -> std::convertible_to<clev::expected<void>>;
56 }
57 {
58 if (this == &rhs)
59 return *this;
60
61 if (*this)
62 iface<wrap_t>::destroy(own::v).or_exit();
63
64 iface<wrap_t>::copy(&(own::v), rhs.v).or_exit();
65
66 return *this;
67 }
68
69 own(const own& rhs)
70 requires(!requires(wrap_t* d, const wrap_t s) {
71 { iface<wrap_t>::copy(d, s) } -> std ::convertible_to<clev::expected<void>>;
72 })
73 = delete;
74
75 own& operator=(const own&)
76 requires(!requires(wrap_t* d, const wrap_t s) {
77 { iface<wrap_t>::copy(d, s) } -> std ::convertible_to<clev::expected<void>>;
78 })
79 = delete;
80
81 own(own&& rhs) noexcept
82 {
83 if (*this)
84 own::destroy(own::v).or_exit();
85
86 own::v = rhs.v;
87
88 rhs.v = own::empty();
89 }
90
91 own& operator=(own&& rhs) noexcept
92 {
93 if (this != &rhs)
94 {
95 if (*this)
96 own::destroy(own::v).or_exit();
97
98 own::v = rhs.v;
99
100 rhs.v = own::empty();
101 };
102
103 return *this;
104 }
105
107 {
108 if (*this)
109 own::destroy(own::v).or_exit();
110 }
111};
112
113} // namespace clev
114
115static constexpr bool ownxx_own_is_really_needed_v = true;
Definition err.h:40
own & operator=(const own &rhs) noexcept
Definition own.h:53
own & operator=(const own &)=delete
own(const own &rhs)=delete
own(own &&rhs) noexcept
Definition own.h:81
iface< wrap_t > parent
Definition own.h:41
own & operator=(own &&rhs) noexcept
Definition own.h:91
~own()
Definition own.h:106
own(const own &rhs) noexcept
Definition own.h:45