Files
unordered/test/objects/minimal.hpp

252 lines
7.8 KiB
C++
Raw Normal View History

2006-03-19 22:24:06 +00:00
// 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)
2006-03-19 22:24:06 +00:00
#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
2006-03-19 22:24:06 +00:00
namespace test
{
namespace minimal
{
class copy_constructible;
class default_copy_constructible;
2006-03-19 22:24:06 +00:00
class assignable;
template <class T> class hash;
template <class T> class equal_to;
template <class T> class ptr;
template <class T> class const_ptr;
2006-03-19 22:24:06 +00:00
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&);
};
2006-03-19 22:24:06 +00:00
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>(); }
2006-03-19 22:24:06 +00:00
hash() {}
hash(hash const&) {}
hash& operator=(hash const&) { return *this; }
~hash() {}
std::size_t operator()(T const&) const { return 0; }
2006-03-19 22:24:06 +00:00
};
template <class T>
class equal_to
{
public:
static equal_to create() { return equal_to<T>(); }
2006-03-19 22:24:06 +00:00
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; }
2006-03-19 22:24:06 +00:00
};
template <class T> class ptr;
template <class T> class const_ptr;
2006-03-19 22:24:06 +00:00
template <class T>
class ptr
2006-03-19 22:24:06 +00:00
{
friend class allocator<T>;
friend class const_ptr<T>;
2006-03-19 22:24:06 +00:00
T* ptr_;
2006-03-19 22:24:06 +00:00
2007-05-19 20:04:14 +00:00
ptr(T* x) : ptr_(x) {}
2006-03-19 22:24:06 +00:00
public:
ptr() : ptr_(0) {}
typedef void (ptr::*bool_type)() const;
void this_type_does_not_support_comparisons() const {}
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+(int s) const { return ptr<T>(ptr_ + s); }
T& operator[](int s) const { return ptr_[s]; }
bool operator!() const { return !ptr_; }
operator bool_type() const {
return ptr_ ?
&ptr::this_type_does_not_support_comparisons
: 0;
}
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_; }
2006-03-19 22:24:06 +00:00
};
template <class T>
class const_ptr
2006-03-19 22:24:06 +00:00
{
friend class allocator<T>;
T const* ptr_;
2006-03-19 22:24:06 +00:00
const_ptr(T const* ptr) : ptr_(ptr) {}
2006-03-19 22:24:06 +00:00
public:
const_ptr() : ptr_(0) {}
const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
typedef void (const_ptr::*bool_type)() const;
void this_type_does_not_support_comparisons() const {}
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+(int s) const { return const_ptr(ptr_ + s); }
T const& operator[](int s) const { return ptr_[s]; }
bool operator!() const { return !ptr_; }
operator bool_type() const {
return ptr_ ?
&const_ptr::this_type_does_not_support_comparisons
: 0;
}
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_; }
2006-03-19 22:24:06 +00:00
};
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;
2006-03-19 22:24:06 +00:00
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&) {}
2006-03-19 22:24:06 +00:00
~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))));
}
pointer allocate(size_type n, const_pointer u)
{
return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
void deallocate(pointer p, size_type)
2006-03-19 22:24:06 +00:00
{
::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; }
Merged revisions 41822-41992,41994-42101 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/dev ........ r41822 | danieljames | 2007-12-07 12:51:54 +0000 (Fri, 07 Dec 2007) | 5 lines Change the macros to meet boost guidelines. I should really have done this before the review. At least it'll give them something to say. ........ r41928 | danieljames | 2007-12-09 19:23:27 +0000 (Sun, 09 Dec 2007) | 1 line Add some parameters to standalone documentation build. ........ r41929 | danieljames | 2007-12-09 19:24:07 +0000 (Sun, 09 Dec 2007) | 1 line An extra rehash test for inserting a range. ........ r41930 | danieljames | 2007-12-09 19:24:52 +0000 (Sun, 09 Dec 2007) | 1 line get_for_erase can be static because all the required information is in the iterator. ........ r41931 | danieljames | 2007-12-09 19:31:00 +0000 (Sun, 09 Dec 2007) | 1 line ADL doesn't seem to be working properly on Visual C++ 7.1 when calling swap, so workaround this in the compile tests. ........ r41932 | danieljames | 2007-12-09 19:44:46 +0000 (Sun, 09 Dec 2007) | 1 line Try to make the erase exception requirements a little clearer. ........ r41933 | danieljames | 2007-12-09 19:52:50 +0000 (Sun, 09 Dec 2007) | 1 line Hopefully clearer comparison of accessors for comparison/hash function objects. ........ r41943 | danieljames | 2007-12-10 00:03:53 +0000 (Mon, 10 Dec 2007) | 1 line Fix a typo. ........ r41951 | danieljames | 2007-12-10 11:08:02 +0000 (Mon, 10 Dec 2007) | 1 line Use the locale in the case insensitive comparison, I really should add a test for this. ........ r41994 | danieljames | 2007-12-13 00:26:05 +0000 (Thu, 13 Dec 2007) | 3 lines Hervé Brönnimann's improved explanation of the formula for avoiding invalidating iterators. ........ r41995 | danieljames | 2007-12-13 00:30:46 +0000 (Thu, 13 Dec 2007) | 4 lines Explicity use the classic locale in the case insensitive example. I could make the locale a member, but that would make the example longer. Also, this would be a good place to put a note about the need for constant function objects. ........ r41996 | danieljames | 2007-12-13 00:31:55 +0000 (Thu, 13 Dec 2007) | 1 line Pull the point examples out into test files - fixing a few bugs in the process. ........ r41997 | danieljames | 2007-12-13 00:41:30 +0000 (Thu, 13 Dec 2007) | 3 lines A few reference links for boost::hash, it might be better to link to the first page of the Boost.Hash documentation though. ........ r42092 | danieljames | 2007-12-16 10:07:27 +0000 (Sun, 16 Dec 2007) | 2 lines Fix some typos, and use American spelling. ........ r42093 | danieljames | 2007-12-16 10:11:00 +0000 (Sun, 16 Dec 2007) | 1 line Small documentation tweak. ........ r42096 | danieljames | 2007-12-16 10:17:03 +0000 (Sun, 16 Dec 2007) | 1 line Fix some reference documentation errors. ........ r42097 | danieljames | 2007-12-16 10:28:08 +0000 (Sun, 16 Dec 2007) | 1 line Document the explicit constructors. ........ r42098 | danieljames | 2007-12-16 10:47:13 +0000 (Sun, 16 Dec 2007) | 1 line Try to make the active issues and proposals a little clearer - including more obvious links to the relevant papers. ........ r42099 | danieljames | 2007-12-16 10:52:30 +0000 (Sun, 16 Dec 2007) | 1 line Fix some complexity errors in the comparison table. ........ r42100 | danieljames | 2007-12-16 10:59:45 +0000 (Sun, 16 Dec 2007) | 1 line Use Mapped instead of T in the documentation. ........ r42101 | danieljames | 2007-12-16 11:06:16 +0000 (Sun, 16 Dec 2007) | 1 line Remove hard-coded length of prime numbers. ........ [SVN r42187]
2007-12-19 23:09:09 +00:00
#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
2006-03-19 22:24:06 +00:00
};
template <class T>
inline bool operator==(allocator<T> const&, allocator<T> const&)
2006-03-19 22:24:06 +00:00
{
return true;
}
template <class T>
inline bool operator!=(allocator<T> const&, allocator<T> const&)
2006-03-19 22:24:06 +00:00
{
return false;
}
template <class T>
void swap(allocator<T>&, allocator<T>&)
2006-03-19 22:24:06 +00:00
{
}
}
}
#if defined(BOOST_MSVC)
#pragma warning(pop)
#endif
2006-03-19 22:24:06 +00:00
#endif