dxx-rebirth/common/include/pack.h
Kp 9dc22b1ee6 Expand DXX_CXX11_EXPLICIT_DELETE
Various functions use the non-macro form, so support for =delete is
already mandatory.  Remove the remnants of support for compilers which
lack =delete and replace it with a hard stop when the compiler rejects
declaring explicitly deleted functions.
2015-05-01 02:18:33 +00:00

48 lines
1.4 KiB
C++

#pragma once
#include "dxxsconf.h"
#include "compiler-type_traits.h"
template <typename T>
class exact_type
{
T *p;
public:
operator bool() = delete;
// Conversion to void* variants is prohibited
operator void *() const = delete;
operator volatile void *() const = delete;
operator const void *() const = delete;
operator const volatile void *() const = delete;
bool operator<(exact_type<T>) const = delete;
bool operator<=(exact_type<T>) const = delete;
bool operator>(exact_type<T>) const = delete;
bool operator>=(exact_type<T>) const = delete;
exact_type(T *t) : p(t) {}
// Conversion to the exact type is permitted
operator T *() const { return p; }
bool operator==(exact_type<T> rhs) const { return p == rhs.p; }
bool operator!=(exact_type<T> rhs) const { return p != rhs.p; }
};
template <typename T>
class prohibit_void_ptr
{
public:
// Return a proxy when the address is taken
exact_type<T> operator&() { return static_cast<T*>(this); }
exact_type<T const> operator&() const { return static_cast<T const*>(this); }
};
struct allow_void_ptr {};
template <typename T>
struct has_prohibit_void_ptr : tt::is_base_of<prohibit_void_ptr<T>, T> {};
template <typename T>
struct has_prohibit_void_ptr<T[]> {};
template <typename T, typename D>
struct inherit_void_ptr_handler : public
tt::conditional<has_prohibit_void_ptr<T>::value, prohibit_void_ptr<D>, allow_void_ptr> {};