Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #pragma once
  2.  
  3. #include <type_traits>
  4. #include "dxxsconf.h"
  5.  
  6. template <typename T>
  7. class exact_type
  8. {
  9.         T *p;
  10. public:
  11.         operator bool() const = delete;
  12.         // Conversion to void* variants is prohibited
  13.         operator void *() const = delete;
  14.         operator volatile void *() const = delete;
  15.         operator const void *() const = delete;
  16.         operator const volatile void *() const = delete;
  17.         template <typename U>
  18.                 bool operator<(U &&) const = delete;
  19.         template <typename U>
  20.                 bool operator<=(U &&) const = delete;
  21.         template <typename U>
  22.                 bool operator>(U &&) const = delete;
  23.         template <typename U>
  24.                 bool operator>=(U &&) const = delete;
  25.         template <typename U>
  26.                 bool operator!=(U &&rhs) const { return !operator==(static_cast<U &&>(rhs)); }
  27.         exact_type(T *t) : p(t) {}
  28.         // Conversion to the exact type is permitted
  29.         operator const T *() const { return p; }
  30.         operator typename std::remove_const<T>::type *() const { return p; }
  31.         bool operator==(const T *rhs) const { return p == rhs; }
  32. };
  33.  
  34. template <typename T>
  35. class prohibit_void_ptr
  36. {
  37. public:
  38.         // Return a proxy when the address is taken
  39.         exact_type<T> operator&() { return static_cast<T*>(this); }
  40.         exact_type<T const> operator&() const { return static_cast<T const*>(this); }
  41. };
  42.