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