lzham_helpers.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // File: lzham_helpers.h
  2. // See Copyright Notice and license at the end of include/lzham.h
  3. #pragma once
  4. #define LZHAM_NO_COPY_OR_ASSIGNMENT_OP(c) c(const c&); c& operator= (const c&);
  5. namespace lzham
  6. {
  7. namespace helpers
  8. {
  9. template<typename T> struct rel_ops
  10. {
  11. friend inline bool operator!=(const T& x, const T& y) { return (!(x == y)); }
  12. friend inline bool operator> (const T& x, const T& y) { return (y < x); }
  13. friend inline bool operator<=(const T& x, const T& y) { return (!(y < x)); }
  14. friend inline bool operator>=(const T& x, const T& y) { return (!(x < y)); }
  15. };
  16. template <typename T>
  17. inline T* construct(T* p)
  18. {
  19. return new (static_cast<void*>(p)) T;
  20. }
  21. template <typename T, typename U>
  22. inline T* construct(T* p, const U& init)
  23. {
  24. return new (static_cast<void*>(p)) T(init);
  25. }
  26. template <typename T>
  27. inline void construct_array(T* p, uint n);
  28. template <typename T, typename U>
  29. inline void construct_array(T* p, uint n, const U& init)
  30. {
  31. T* q = p + n;
  32. for ( ; p != q; ++p)
  33. new (static_cast<void*>(p)) T(init);
  34. }
  35. template <typename T>
  36. inline void destruct(T* p)
  37. {
  38. LZHAM_NOTE_UNUSED(p);
  39. p->~T();
  40. }
  41. template <typename T>
  42. inline void destruct_array(T* p, uint n);
  43. } // namespace helpers
  44. } // namespace lzham