2014-06-21 23:55:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-25 20:46:03 +00:00
|
|
|
#include <type_traits>
|
2014-06-21 23:55:24 +00:00
|
|
|
#include "dxxsconf.h"
|
|
|
|
|
2017-06-25 20:46:03 +00:00
|
|
|
template <typename T>
|
2014-06-21 23:55:24 +00:00
|
|
|
class exact_type
|
|
|
|
{
|
|
|
|
T *p;
|
|
|
|
public:
|
2015-09-15 02:48:04 +00:00
|
|
|
operator bool() const = delete;
|
2014-06-21 23:55:24 +00:00
|
|
|
// Conversion to void* variants is prohibited
|
2015-05-01 02:18:33 +00:00
|
|
|
operator void *() const = delete;
|
|
|
|
operator volatile void *() const = delete;
|
|
|
|
operator const void *() const = delete;
|
|
|
|
operator const volatile void *() const = delete;
|
2016-02-06 22:12:54 +00:00
|
|
|
template <typename U>
|
|
|
|
bool operator<(U &&) const = delete;
|
|
|
|
template <typename U>
|
|
|
|
bool operator<=(U &&) const = delete;
|
|
|
|
template <typename U>
|
|
|
|
bool operator>(U &&) const = delete;
|
|
|
|
template <typename U>
|
|
|
|
bool operator>=(U &&) const = delete;
|
|
|
|
template <typename U>
|
|
|
|
bool operator!=(U &&rhs) const { return !operator==(static_cast<U &&>(rhs)); }
|
2021-08-26 03:13:45 +00:00
|
|
|
constexpr exact_type(T *t) : p(t) {}
|
2014-06-21 23:55:24 +00:00
|
|
|
// Conversion to the exact type is permitted
|
2021-08-26 03:13:45 +00:00
|
|
|
constexpr operator const T *() const { return p; }
|
|
|
|
constexpr operator typename std::remove_const<T>::type *() const { return p; }
|
|
|
|
constexpr bool operator==(const T *rhs) const { return p == rhs; }
|
2022-07-02 18:10:45 +00:00
|
|
|
constexpr bool operator==(const exact_type<T> &rhs) const = default;
|
2014-06-21 23:55:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class prohibit_void_ptr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Return a proxy when the address is taken
|
2021-08-26 03:13:45 +00:00
|
|
|
constexpr exact_type<T> operator&() { return static_cast<T*>(this); }
|
|
|
|
constexpr exact_type<T const> operator&() const { return static_cast<T const*>(this); }
|
2014-06-21 23:55:24 +00:00
|
|
|
};
|