open-cpp-utils
0.0.1
Loading...
Searching...
No Matches
unique_id.h
1
// =====================================================================================================================
2
// open-cpp-utils, an open-source cpp library with data structures that extend the STL.
3
// Copyright (C) 2024 Medusa Slockbower
4
//
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
// =====================================================================================================================
18
19
#ifndef OPEN_CPP_UTILS_UNIQUE_ID_H
20
#define OPEN_CPP_UTILS_UNIQUE_ID_H
21
22
#include <cstdint>
23
24
namespace
open_cpp_utils
25
{
26
27
// Internal function for incrementing an id associated with a type
28
template
<
typename
Base> uint64_t _increment_id()
29
{
30
static
uint64_t current = 0;
31
return
current++;
32
}
33
47
template
<
typename
Base,
typename
Type> uint64_t unique_id()
48
{
49
static
bool
initialized =
false
;
50
static
uint64_t
id
= 0;
51
52
if
(initialized)
return
id;
53
initialized =
true
;
54
return
id
= _increment_id<Base>();
55
}
56
57
}
58
59
#endif
// OPEN_CPP_UTILS_UNIQUE_ID_H
Generated by
1.11.0