uvw  2.10.0
type_info.hpp
1 #ifndef UVW_TYPE_INFO_INCLUDE_HPP
2 #define UVW_TYPE_INFO_INCLUDE_HPP
3 
4 
5 #include <cstddef>
6 #include <string_view>
7 
8 
9 namespace uvw {
10 
11 
18 namespace internal {
19 
20 
21 // Fowler–Noll–Vo hash function v. 1a - the good
22 [[nodiscard]] static constexpr std::uint32_t fnv1a(const char *curr) noexcept {
23  constexpr std::uint32_t offset = 2166136261;
24  constexpr std::uint32_t prime = 16777619;
25  auto value = offset;
26 
27  while(*curr != 0) {
28  value = (value ^ static_cast<std::uint32_t>(*(curr++))) * prime;
29  }
30 
31  return value;
32 }
33 
34 
35 [[nodiscard]] static inline std::uint32_t counter() noexcept {
36  static std::uint32_t cnt{};
37  return cnt++;
38 }
39 
40 
41 template<typename Type>
42 [[nodiscard]] static std::uint32_t fake() noexcept {
43  static std::uint32_t local = counter();
44  return local;
45 }
46 
47 
48 }
49 
50 
62 template<typename Type>
63 [[nodiscard]] static constexpr std::uint32_t type() noexcept {
64 #if defined __clang__ || defined __GNUC__
65  return internal::fnv1a(__PRETTY_FUNCTION__);
66 #elif defined _MSC_VER
67  return internal::fnv1a(__FUNCSIG__);
68 #else
69  return internal::fake();
70 #endif
71 }
72 
73 
74 }
75 
76 #endif // UVW_TYPE_INFO_INCLUDE_HPP
uvw default namespace.
Definition: async.h:10
static constexpr std::uint32_t type() noexcept
Returns a numerical identifier for a given type.
Definition: type_info.hpp:63