HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
long_tagged_id.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "stdint.hpp"
8#include "fixed_string.hpp"
9#include "sip_hash.hpp"
10#include <bit>
11
12namespace hi::inline v1 {
13
14template<fixed_string Tag>
16public:
17 constexpr static auto tag = Tag;
18
19 constexpr long_tagged_id() noexcept = default;
20 constexpr long_tagged_id(long_tagged_id const&) noexcept = default;
21 constexpr long_tagged_id(long_tagged_id&&) noexcept = default;
22 constexpr long_tagged_id& operator=(long_tagged_id const&) noexcept = default;
23 constexpr long_tagged_id& operator=(long_tagged_id&&) noexcept = default;
24
25 constexpr long_tagged_id(nullptr_t) noexcept : _value() {}
26 constexpr long_tagged_id& operator=(nullptr_t) noexcept
27 {
28 _value = {};
29 return *this;
30 }
31
32 template<typename... Args>
33 constexpr explicit long_tagged_id(Args const&...args) noexcept :
34 _value()
35 {
36 auto tmp = (... ^ sip_hash24x2<Args>{}(args));
37 _value = std::bit_cast<uint128_t>(tmp);
38 if (_value == 0) {
39 _value = 1;
40 }
41 }
42
43 template<typename T>
44 constexpr long_tagged_id& operator=(T const& other) noexcept
45 {
46 _value = std::bit_cast<uint128_t>(sip_hash24x2<std::decay_t<T>>{}(other));
47 if (_value == 0) {
48 _value = 1;
49 }
50 }
51
52 [[nodiscard]] constexpr bool empty() const noexcept
53 {
54 return _value == 0;
55 }
56
57 constexpr operator bool() const noexcept
58 {
59 return not empty();
60 }
61
62 [[nodiscard]] constexpr friend bool operator==(long_tagged_id const& lhs, long_tagged_id const& rhs) noexcept = default;
63
64private:
65 uint128_t _value = 0;
66};
67
68} // namespace hi::inline v1
Extra integer definitions.
DOXYGEN BUG.
Definition algorithm.hpp:15
Definition long_tagged_id.hpp:15