forked from boostorg/unordered
https://svn.boost.org/svn/boost/branches/unordered/trunk ................ r42887 | danieljames | 2008-01-20 21:32:04 +0000 (Sun, 20 Jan 2008) | 10 lines Merged revisions 42590-42664,42667-42697,42699-42723,42725-42855,42857-42881 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r42881 | danieljames | 2008-01-20 17:37:21 +0000 (Sun, 20 Jan 2008) | 1 line Include <new> to get std::bad_alloc. ........ ................ r42892 | danieljames | 2008-01-21 13:03:16 +0000 (Mon, 21 Jan 2008) | 1 line On some compilers the Rogue Wave/Apache stdcxx library doesn't have the normal std::distance, but instead has a variant that takes the result as the third parameter so it doesn't have to work out the type from the iterator. ................ r42893 | danieljames | 2008-01-21 13:07:58 +0000 (Mon, 21 Jan 2008) | 1 line Fix a typo in the last commit. ................ r42895 | danieljames | 2008-01-21 13:33:29 +0000 (Mon, 21 Jan 2008) | 1 line Remove tabs from the last checkin. ................ r42896 | danieljames | 2008-01-21 15:51:40 +0000 (Mon, 21 Jan 2008) | 1 line Use Boost config to tell when we have a std::distance function. Also, no need for a macro. ................ r42908 | danieljames | 2008-01-21 21:37:04 +0000 (Mon, 21 Jan 2008) | 1 line Use boost::long_long_type and boost::ulong_long_type. ................ r42921 | danieljames | 2008-01-23 11:43:35 +0000 (Wed, 23 Jan 2008) | 1 line Remove some tabs. ................ r42922 | danieljames | 2008-01-23 11:46:28 +0000 (Wed, 23 Jan 2008) | 2 lines Add missing include. Refs #1596 ................ r42923 | danieljames | 2008-01-23 11:52:47 +0000 (Wed, 23 Jan 2008) | 2 lines Always use void const* for the second parameter of allocate. Refs #1596. ................ r42936 | danieljames | 2008-01-23 22:22:16 +0000 (Wed, 23 Jan 2008) | 1 line Use Boost style library name in the documentation. ................ r42937 | danieljames | 2008-01-23 22:22:32 +0000 (Wed, 23 Jan 2008) | 1 line More tabs. ................ r42941 | danieljames | 2008-01-23 23:35:01 +0000 (Wed, 23 Jan 2008) | 1 line Fix all the allocators. ................ [SVN r42943]
246 lines
8.0 KiB
C++
246 lines
8.0 KiB
C++
|
|
// Copyright 2006-2007 Daniel James.
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
// Define some minimal classes which provide the bare minimum concepts to
|
|
// test that the containers don't rely on something that they shouldn't.
|
|
// They are not intended to be good examples of how to implement the concepts.
|
|
|
|
#if !defined(BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER)
|
|
#define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
|
|
|
|
#include <cstddef>
|
|
|
|
#if defined(BOOST_MSVC)
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4100) // unreferenced formal parameter
|
|
#endif
|
|
|
|
namespace test
|
|
{
|
|
namespace minimal
|
|
{
|
|
class copy_constructible;
|
|
class default_copy_constructible;
|
|
class assignable;
|
|
template <class T> class hash;
|
|
template <class T> class equal_to;
|
|
template <class T> class ptr;
|
|
template <class T> class const_ptr;
|
|
template <class T> class allocator;
|
|
|
|
class copy_constructible
|
|
{
|
|
public:
|
|
static copy_constructible create() { return copy_constructible(); }
|
|
copy_constructible(copy_constructible const&) {}
|
|
~copy_constructible() {}
|
|
private:
|
|
copy_constructible& operator=(copy_constructible const&);
|
|
copy_constructible() {}
|
|
};
|
|
|
|
class default_copy_constructible
|
|
{
|
|
public:
|
|
static default_copy_constructible create() { return default_copy_constructible(); }
|
|
default_copy_constructible() {}
|
|
default_copy_constructible(default_copy_constructible const&) {}
|
|
~default_copy_constructible() {}
|
|
private:
|
|
default_copy_constructible& operator=(default_copy_constructible const&);
|
|
};
|
|
|
|
class assignable
|
|
{
|
|
public:
|
|
static assignable create() { return assignable(); }
|
|
assignable(assignable const&) {}
|
|
assignable& operator=(assignable const&) { return *this; }
|
|
~assignable() {}
|
|
private:
|
|
assignable() {}
|
|
};
|
|
|
|
template <class T>
|
|
class hash
|
|
{
|
|
public:
|
|
static hash create() { return hash<T>(); }
|
|
hash() {}
|
|
hash(hash const&) {}
|
|
hash& operator=(hash const&) { return *this; }
|
|
~hash() {}
|
|
|
|
std::size_t operator()(T const&) const { return 0; }
|
|
};
|
|
|
|
template <class T>
|
|
class equal_to
|
|
{
|
|
public:
|
|
static equal_to create() { return equal_to<T>(); }
|
|
equal_to() {}
|
|
equal_to(equal_to const&) {}
|
|
equal_to& operator=(equal_to const&) { return *this; }
|
|
~equal_to() {}
|
|
|
|
bool operator()(T const&, T const&) const { return true; }
|
|
};
|
|
|
|
template <class T> class ptr;
|
|
template <class T> class const_ptr;
|
|
|
|
template <class T>
|
|
class ptr
|
|
{
|
|
friend class allocator<T>;
|
|
friend class const_ptr<T>;
|
|
|
|
T* ptr_;
|
|
|
|
ptr(T* x) : ptr_(x) {}
|
|
public:
|
|
ptr() : ptr_(0) {}
|
|
|
|
T& operator*() const { return *ptr_; }
|
|
T* operator->() const { return ptr_; }
|
|
ptr& operator++() { ++ptr_; return *this; }
|
|
ptr operator++(int) { ptr tmp(*this); ++ptr_; return tmp; }
|
|
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_); }
|
|
T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
|
|
bool operator!() const { return !ptr_; }
|
|
|
|
// I'm not using the safe bool idiom because the containers should be
|
|
// able to cope with bool conversions.
|
|
operator bool() const { return !!ptr_; }
|
|
|
|
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_; }
|
|
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_; }
|
|
|
|
bool operator==(const_ptr<T> const& x) const { return ptr_ == x.ptr_; }
|
|
bool operator!=(const_ptr<T> const& x) const { return ptr_ != x.ptr_; }
|
|
bool operator<(const_ptr<T> const& x) const { return ptr_ < x.ptr_; }
|
|
bool operator>(const_ptr<T> const& x) const { return ptr_ > x.ptr_; }
|
|
bool operator<=(const_ptr<T> const& x) const { return ptr_ <= x.ptr_; }
|
|
bool operator>=(const_ptr<T> const& x) const { return ptr_ >= x.ptr_; }
|
|
};
|
|
|
|
template <class T>
|
|
class const_ptr
|
|
{
|
|
friend class allocator<T>;
|
|
|
|
T const* ptr_;
|
|
|
|
const_ptr(T const* ptr) : ptr_(ptr) {}
|
|
public:
|
|
const_ptr() : ptr_(0) {}
|
|
const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
|
|
|
|
T const& operator*() const { return *ptr_; }
|
|
T const* operator->() const { return ptr_; }
|
|
const_ptr& operator++() { ++ptr_; return *this; }
|
|
const_ptr operator++(int) { const_ptr tmp(*this); ++ptr_; return tmp; }
|
|
const_ptr operator+(std::ptrdiff_t s) const { return const_ptr(ptr_ + s); }
|
|
friend const_ptr operator+(std::ptrdiff_t s, const_ptr p) { return ptr<T>(s + p.ptr_); }
|
|
T const& operator[](int s) const { return ptr_[s]; }
|
|
bool operator!() const { return !ptr_; }
|
|
operator bool() const { return !!ptr_; }
|
|
|
|
bool operator==(ptr<T> const& x) const { return ptr_ == x.ptr_; }
|
|
bool operator!=(ptr<T> const& x) const { return ptr_ != x.ptr_; }
|
|
bool operator<(ptr<T> const& x) const { return ptr_ < x.ptr_; }
|
|
bool operator>(ptr<T> const& x) const { return ptr_ > x.ptr_; }
|
|
bool operator<=(ptr<T> const& x) const { return ptr_ <= x.ptr_; }
|
|
bool operator>=(ptr<T> const& x) const { return ptr_ >= x.ptr_; }
|
|
|
|
bool operator==(const_ptr const& x) const { return ptr_ == x.ptr_; }
|
|
bool operator!=(const_ptr const& x) const { return ptr_ != x.ptr_; }
|
|
bool operator<(const_ptr const& x) const { return ptr_ < x.ptr_; }
|
|
bool operator>(const_ptr const& x) const { return ptr_ > x.ptr_; }
|
|
bool operator<=(const_ptr const& x) const { return ptr_ <= x.ptr_; }
|
|
bool operator>=(const_ptr const& x) const { return ptr_ >= x.ptr_; }
|
|
};
|
|
|
|
template <class T>
|
|
class allocator
|
|
{
|
|
public:
|
|
typedef std::size_t size_type;
|
|
typedef std::ptrdiff_t difference_type;
|
|
typedef ptr<T> pointer;
|
|
typedef const_ptr<T> const_pointer;
|
|
typedef T& reference;
|
|
typedef T const& const_reference;
|
|
typedef T value_type;
|
|
|
|
template <class U> struct rebind { typedef allocator<U> other; };
|
|
|
|
allocator() {}
|
|
template <class Y> allocator(allocator<Y> const&) {}
|
|
allocator(allocator const&) {}
|
|
~allocator() {}
|
|
|
|
pointer address(reference r) { return pointer(&r); }
|
|
const_pointer address(const_reference r) { return const_pointer(&r); }
|
|
|
|
pointer allocate(size_type n) {
|
|
return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
|
|
}
|
|
|
|
template <class Y>
|
|
pointer allocate(size_type n, const_ptr<Y> u)
|
|
{
|
|
return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
|
|
}
|
|
|
|
void deallocate(pointer p, size_type)
|
|
{
|
|
::operator delete((void*) p.ptr_);
|
|
}
|
|
|
|
void construct(pointer p, T const& t) { new((void*)p.ptr_) T(t); }
|
|
void destroy(pointer p) { ((T*)p.ptr_)->~T(); }
|
|
|
|
size_type max_size() const { return 1000; }
|
|
|
|
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || \
|
|
BOOST_WORKAROUND(MSVC, <= 1300)
|
|
public: allocator& operator=(allocator const&) { return *this;}
|
|
#else
|
|
private: allocator& operator=(allocator const&);
|
|
#endif
|
|
};
|
|
|
|
template <class T>
|
|
inline bool operator==(allocator<T> const&, allocator<T> const&)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
template <class T>
|
|
inline bool operator!=(allocator<T> const&, allocator<T> const&)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
template <class T>
|
|
void swap(allocator<T>&, allocator<T>&)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
#if defined(BOOST_MSVC)
|
|
#pragma warning(pop)
|
|
#endif
|
|
|
|
#endif
|