mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-31 20:04:29 +02:00
Extend fancy pointer types used by test allocators to support a wider array of semantic operations
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
|
#define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
|
||||||
|
|
||||||
#include <boost/core/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/core/pointer_traits.hpp>
|
||||||
#include <boost/move/move.hpp>
|
#include <boost/move/move.hpp>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -311,13 +312,17 @@ namespace test {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
ptr operator+(std::ptrdiff_t s) const { return ptr<T>(ptr_ + s); }
|
ptr operator+(std::ptrdiff_t s) const { return ptr<T>(ptr_ + s); }
|
||||||
friend ptr operator+(std::ptrdiff_t s, ptr p)
|
friend ptr operator+(std::ptrdiff_t s, ptr p) { return ptr<T>(s + p.ptr_); }
|
||||||
{
|
|
||||||
return ptr<T>(s + p.ptr_);
|
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]; }
|
T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
|
||||||
bool operator!() const { return !ptr_; }
|
bool operator!() const { return !ptr_; }
|
||||||
|
|
||||||
|
static ptr pointer_to(T& p) {
|
||||||
|
return ptr(&p);
|
||||||
|
}
|
||||||
|
|
||||||
// I'm not using the safe bool idiom because the containers should be
|
// I'm not using the safe bool idiom because the containers should be
|
||||||
// able to cope with bool conversions.
|
// able to cope with bool conversions.
|
||||||
operator bool() const { return !!ptr_; }
|
operator bool() const { return !!ptr_; }
|
||||||
@@ -637,4 +642,14 @@ namespace test {
|
|||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
template <> struct pointer_traits< ::test::minimal::void_ptr>
|
||||||
|
{
|
||||||
|
template <class U> struct rebind_to
|
||||||
|
{
|
||||||
|
typedef ::test::minimal::ptr<U> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -521,11 +521,22 @@ namespace test {
|
|||||||
++ptr_;
|
++ptr_;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr operator+(std::ptrdiff_t s) const { return ptr<T>(ptr_ + s); }
|
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_); }
|
friend ptr operator+(std::ptrdiff_t s, ptr p) { return ptr<T>(s + p.ptr_); }
|
||||||
|
|
||||||
|
std::ptrdiff_t operator-(ptr p) const { return ptr_ - p.ptr_; }
|
||||||
|
ptr operator-(std::ptrdiff_t s) const { return ptr(ptr_ - s); }
|
||||||
|
|
||||||
|
ptr& operator+=(std::ptrdiff_t s) { ptr_ += s; return *this; }
|
||||||
|
|
||||||
T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
|
T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
|
||||||
bool operator!() const { return !ptr_; }
|
bool operator!() const { return !ptr_; }
|
||||||
|
|
||||||
|
static ptr pointer_to(T& p) {
|
||||||
|
return ptr(&p);
|
||||||
|
}
|
||||||
|
|
||||||
// I'm not using the safe bool idiom because the containers should be
|
// I'm not using the safe bool idiom because the containers should be
|
||||||
// able to cope with bool conversions.
|
// able to cope with bool conversions.
|
||||||
operator bool() const { return !!ptr_; }
|
operator bool() const { return !!ptr_; }
|
||||||
@@ -701,4 +712,14 @@ namespace test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
template <> struct pointer_traits< ::test::void_ptr>
|
||||||
|
{
|
||||||
|
template <class U> struct rebind_to
|
||||||
|
{
|
||||||
|
typedef ::test::ptr<U> type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user