common.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #ifdef _MSC_VER
  3. #pragma warning (disable:4267)
  4. #pragma warning (disable:4101)
  5. #define _CRT_NONSTDC_NO_DEPRECATE
  6. #define strdup _strdup
  7. #endif
  8. #include <sstream>
  9. #include <regex>
  10. #include <stack>
  11. #include <cmath>
  12. #include <stdexcept>
  13. #include <vector>
  14. #include <string>
  15. #include <cstring>
  16. #include <chrono>
  17. #include <string_view>
  18. #include <queue>
  19. #include <iomanip>
  20. #include <memory>
  21. #include <functional>
  22. #include <iostream>
  23. #include "hash_table8.hpp"
  24. #ifdef POCKETPY_H
  25. #define UNREACHABLE() throw std::runtime_error( "L" + std::to_string(__LINE__) + " UNREACHABLE()! This should be a bug, please report it");
  26. #else
  27. #define UNREACHABLE() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " UNREACHABLE()!");
  28. #endif
  29. #define PK_VERSION "0.8.4"
  30. typedef int64_t i64;
  31. typedef double f64;
  32. #define DUMMY_VAL (char)1
  33. #define DUMMY_VAL_TP char
  34. template<typename T>
  35. void* tid() {
  36. static volatile int8_t _x;
  37. return (void*)(&_x);
  38. }
  39. // This does not ensure to be unique when the pointer of obj->type is deleted & reused.
  40. // But it is good enough for now.
  41. template<typename T>
  42. void* obj_tid(void* alt){
  43. if constexpr(std::is_same_v<T, DUMMY_VAL_TP>) return alt;
  44. return tid<T>();
  45. }