Skip to content

Commit 42bee96

Browse files
committed
add OptionalSymbolID
1 parent 3573549 commit 42bee96

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

include/mrdox/Metadata/Symbols.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,54 @@ using SymbolID = std::array<unsigned char, 20>;
3434
*/
3535
constexpr SymbolID const EmptySID = SymbolID();
3636

37+
/** Like optional<SymbolID>
38+
*/
39+
class OptionalSymbolID
40+
{
41+
SymbolID ID_{};
42+
43+
public:
44+
using value_type = SymbolID;
45+
46+
constexpr OptionalSymbolID() = default;
47+
48+
constexpr OptionalSymbolID(std::nullopt_t) noexcept
49+
: OptionalSymbolID()
50+
{
51+
}
52+
53+
constexpr OptionalSymbolID(
54+
OptionalSymbolID const& other) = default;
55+
56+
constexpr OptionalSymbolID& operator=(
57+
OptionalSymbolID const& other) = default;
58+
59+
constexpr OptionalSymbolID(value_type const& v) noexcept
60+
: ID_(v)
61+
{
62+
}
63+
64+
constexpr value_type& operator*() noexcept
65+
{
66+
return ID_;
67+
}
68+
69+
constexpr value_type const& operator*() const noexcept
70+
{
71+
return ID_;
72+
}
73+
74+
constexpr explicit operator bool() const noexcept
75+
{
76+
return has_value();
77+
}
78+
79+
constexpr bool has_value() const noexcept
80+
{
81+
return ID_ != EmptySID;
82+
}
83+
};
84+
3785
/** The ID of the global namespace.
3886
*/
3987
constexpr SymbolID const globalNamespaceID = EmptySID;

0 commit comments

Comments
 (0)