HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
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 "utility/module.hpp"
9
#include "sip_hash.hpp"
10
#include <bit>
11
12
namespace
hi::inline
v1
{
13
14
template
<fixed_
string
Tag>
15
class
long_tagged_id
{
16
public
:
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
64
private
:
65
uint128_t
_value = 0;
66
};
67
68
}
// namespace hi::inline v1
stdint.hpp
Extra integer definitions.
v1
DOXYGEN BUG.
Definition
algorithm.hpp:13
v1::uint128_t
unsigned __int128 uint128_t
Unsigned 128 bit integer.
Definition
architecture.hpp:184
v1::long_tagged_id
Definition
long_tagged_id.hpp:15
Generated on Mon Apr 22 2024 12:52:30 for HikoGUI by
1.10.0