uvw 3.1.0
Loading...
Searching...
No Matches
type_info.hpp
1#ifndef UVW_TYPE_INFO_INCLUDE_HPP
2#define UVW_TYPE_INFO_INCLUDE_HPP
3
4#include <cstdint>
5#include "config.h"
6
7namespace uvw {
8
14namespace internal {
15
16// Fowler-Noll-Vo hash function v. 1a - the good
17[[nodiscard]] static constexpr std::uint32_t fnv1a(const char *curr) noexcept {
18 constexpr std::uint32_t offset = 2166136261;
19 constexpr std::uint32_t prime = 16777619;
20 auto value = offset;
21
22 while(*curr != 0) {
23 value = (value ^ static_cast<std::uint32_t>(*(curr++))) * prime;
24 }
25
26 return value;
27}
28
29[[nodiscard]] static inline std::uint32_t counter() noexcept {
30 static std::uint32_t cnt{};
31 return cnt++;
32}
33
34template<typename Type>
35[[nodiscard]] static std::uint32_t fake() noexcept {
36 static std::uint32_t local = counter();
37 return local;
38}
39
40} // namespace internal
41
52template<typename Type>
53[[nodiscard]] static constexpr std::uint32_t type() noexcept {
54#if defined __clang__ || defined __GNUC__
55 return internal::fnv1a(__PRETTY_FUNCTION__);
56#elif defined _MSC_VER
57 return internal::fnv1a(__FUNCSIG__);
58#else
59 return internal::fake();
60#endif
61}
62
63} // namespace uvw
64
65#endif // UVW_TYPE_INFO_INCLUDE_HPP
uvw default namespace.
Definition: async.h:8
static constexpr std::uint32_t type() noexcept
Returns a numerical identifier for a given type.
Definition: type_info.hpp:53