mirror of
https://github.com/boostorg/unordered.git
synced 2025-11-14 14:30:07 +01:00
* Support emplace for all compilers. * Better configuration of C++0x features for when the appropriate headers aren't available. Merged revisions 52393-52394,52397,52884-52885,53127,53255 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r52393 | danieljames | 2009-04-14 18:23:37 +0100 (Tue, 14 Apr 2009) | 2 lines Implement full extract_key for compilers without SFINAE and variadic templates. ........ r52394 | danieljames | 2009-04-14 18:23:51 +0100 (Tue, 14 Apr 2009) | 1 line Use emplace instead of insert in the backend as it's more appropriate. ........ r52397 | danieljames | 2009-04-14 18:51:34 +0100 (Tue, 14 Apr 2009) | 1 line Add stream output to the count test helper for unordered. ........ r52884 | danieljames | 2009-05-10 22:24:41 +0100 (Sun, 10 May 2009) | 19 lines Cherrypick some unordered container changes from sandbox. Not including anything which depends on the new move library. ------------------------------------------------------------------------ r52746 | danieljames | 2009-05-03 11:12:30 +0100 (Sun, 03 May 2009) | 1 line Merge latest unordered container changes. ------------------------------------------------------------------------ r52747 | danieljames | 2009-05-03 11:15:35 +0100 (Sun, 03 May 2009) | 4 lines Put the C++0x emplace implementations before the non-C++0x versions. I'm going to change the non-C++0x to be macro heavy emulations of the C++0x versions, so this will put the readable version first. ------------------------------------------------------------------------ r52748 | danieljames | 2009-05-03 11:15:44 +0100 (Sun, 03 May 2009) | 1 line Refactor the unordered implementation a tad, to make implementing emplace less painful. ------------------------------------------------------------------------ ........ r52885 | danieljames | 2009-05-10 22:25:09 +0100 (Sun, 10 May 2009) | 1 line Merge emplace support for sandbox - but without move support. ........ r53127 | danieljames | 2009-05-20 07:43:38 +0100 (Wed, 20 May 2009) | 1 line Better configuration for boost.unordered. ........ r53255 | danieljames | 2009-05-25 20:45:06 +0100 (Mon, 25 May 2009) | 1 line Unordered change log. ........ [SVN r53257]
290 lines
9.3 KiB
C++
290 lines
9.3 KiB
C++
|
|
// Copyright 2006-2009 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 copy_constructible_equality_comparable;
|
|
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 copy_constructible_equality_comparable
|
|
{
|
|
public:
|
|
static copy_constructible_equality_comparable create() { return copy_constructible_equality_comparable(); }
|
|
copy_constructible_equality_comparable(copy_constructible_equality_comparable const&) {}
|
|
~copy_constructible_equality_comparable() {}
|
|
private:
|
|
copy_constructible_equality_comparable& operator=(copy_constructible_equality_comparable const&);
|
|
copy_constructible_equality_comparable() {}
|
|
};
|
|
|
|
bool operator==(copy_constructible_equality_comparable, copy_constructible_equality_comparable) {
|
|
return true;
|
|
}
|
|
|
|
bool operator!=(copy_constructible_equality_comparable, copy_constructible_equality_comparable) {
|
|
return false;
|
|
}
|
|
|
|
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); }
|
|
|
|
#if defined(BOOST_UNORDERED_STD_FORWARD)
|
|
template<class... Args> void construct(pointer p, Args&&... args) {
|
|
new((void*)p.ptr_) T(std::forward<Args>(args)...);
|
|
}
|
|
#endif
|
|
|
|
void destroy(pointer p) { ((T*)p.ptr_)->~T(); }
|
|
|
|
size_type max_size() const { return 1000; }
|
|
|
|
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || \
|
|
BOOST_WORKAROUND(BOOST_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_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
|
namespace boost {
|
|
#else
|
|
namespace test {
|
|
namespace minimal {
|
|
#endif
|
|
std::size_t hash_value(test::minimal::copy_constructible_equality_comparable) {
|
|
return 1;
|
|
}
|
|
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
|
}}
|
|
#else
|
|
}
|
|
#endif
|
|
|
|
|
|
#if defined(BOOST_MSVC)
|
|
#pragma warning(pop)
|
|
#endif
|
|
|
|
#endif
|