pars 0.2.1
Loading...
Searching...
No Matches
value.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/iface.h"
33
34namespace clev
35{
36
37template<typename value_t>
38struct value
39{
40 using value_type = value_t;
41
42 value(value_type v) noexcept
43 : v{v}
44 {
45 }
46
47 value() noexcept
49 {
50 }
51
52 [[nodiscard]] operator value_type() noexcept { return v; }
53
54 [[nodiscard]] operator const value_type() const noexcept { return v; }
55
56 [[nodiscard]] value_type release() noexcept
57 {
58 auto ret = v;
59
61
62 return ret;
63 }
64
65 [[nodiscard]] explicit operator bool() const noexcept
66 {
68 }
69
70protected:
72};
73
74} // namespace clev
75
76#include <concepts>
77
78static_assert(std::copyable<clev::value<int>>);
79
80static_assert(std::copyable<clev::value<int*>>);
Definition err.h:40
value_type v
Definition value.h:71
value_type release() noexcept
Definition value.h:56
value_t value_type
Definition value.h:40
value(value_type v) noexcept
Definition value.h:42
value() noexcept
Definition value.h:47