Update test fancy pointers to be Nullable, add rebind alias template

This commit is contained in:
Christian Mazakas
2023-08-15 13:02:36 -07:00
parent a0679e5ffe
commit 4d6ebc7eb3
3 changed files with 31 additions and 1 deletions

View File

@ -458,6 +458,7 @@ template <class T> class ptr
public:
ptr() : ptr_(0) {}
ptr(std::nullptr_t) : ptr_(nullptr) {}
explicit ptr(void_ptr const& x) : ptr_((T*)x.ptr_) {}
T& operator*() const { return *ptr_; }

View File

@ -307,6 +307,7 @@ namespace test {
public:
ptr() : ptr_(0) {}
ptr(std::nullptr_t) : ptr_(0) {}
explicit ptr(void_ptr const& x) : ptr_((T*)x.ptr_) {}
T& operator*() const { return *ptr_; }
@ -325,6 +326,18 @@ namespace test {
ptr operator+(std::ptrdiff_t s) const { return ptr<T>(ptr_ + s); }
friend ptr operator+(std::ptrdiff_t s, ptr p) { return ptr<T>(s + p.ptr_); }
ptr& operator+=(std::ptrdiff_t s)
{
ptr_ += s;
return *this;
}
ptr& operator-=(std::ptrdiff_t s)
{
ptr_ -= s;
return *this;
}
std::ptrdiff_t operator-(ptr p) const { return ptr_ - p.ptr_; }
ptr operator-(std::ptrdiff_t s) const { return ptr(ptr_ - s); }
T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
@ -340,6 +353,8 @@ namespace test {
bool operator==(ptr const& x) const { return ptr_ == x.ptr_; }
bool operator!=(ptr const& x) const { return ptr_ != x.ptr_; }
bool operator==(std::nullptr_t) const { return ptr_ == nullptr; }
bool operator!=(std::nullptr_t) const { return ptr_ != nullptr; }
bool operator<(ptr const& x) const { return ptr_ < x.ptr_; }
bool operator>(ptr const& x) const { return ptr_ > x.ptr_; }
bool operator<=(ptr const& x) const { return ptr_ <= x.ptr_; }
@ -660,6 +675,9 @@ namespace boost {
{
typedef ::test::minimal::ptr<U> type;
};
template<class U>
using rebind=typename rebind_to<U>::type;
};
}

View File

@ -16,6 +16,9 @@
#include <boost/limits.hpp>
#include <cstddef>
template <class T> struct allocator1;
template <class T> struct allocator2;
namespace test {
// Note that the default hash function will work for any equal_to (but not
// very well).
@ -506,14 +509,18 @@ namespace test {
template <class T> class ptr
{
friend struct ::allocator1<T>;
friend struct ::allocator2<T>;
friend class allocator2<T>;
friend class const_ptr<T>;
friend struct void_ptr;
public:
T* ptr_;
ptr(T* x) : ptr_(x) {}
public:
ptr() : ptr_(0) {}
ptr(std::nullptr_t) : ptr_(nullptr) {}
explicit ptr(void_ptr const& x) : ptr_((T*)x.ptr_) {}
T& operator*() const { return *ptr_; }
@ -537,6 +544,7 @@ namespace test {
ptr operator-(std::ptrdiff_t s) const { return ptr(ptr_ - s); }
ptr& operator+=(std::ptrdiff_t s) { ptr_ += s; return *this; }
ptr& operator-=(std::ptrdiff_t s) { ptr_ -= s; return *this; }
T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
bool operator!() const { return !ptr_; }
@ -727,6 +735,9 @@ namespace boost {
{
typedef ::test::ptr<U> type;
};
template<class U>
using rebind=typename rebind_to<U>::type;
};
} // namespace boost