1 /* Used in Boost.MultiIndex tests.
3 * Copyright 2003-2015 Joaquin M Lopez Munoz.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org/libs/multi_index for library home page.
11 #ifndef BOOST_MULTI_INDEX_TEST_NON_STD_ALLOCATOR_HPP
12 #define BOOST_MULTI_INDEX_TEST_NON_STD_ALLOCATOR_HPP
14 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
15 #include <boost/throw_exception.hpp>
23 typedef std::ptrdiff_t difference_type;
27 typedef std::random_access_iterator_tag iterator_category;
30 explicit non_raw_pointer(T* p_):p(p_){}
34 #if !defined(BOOST_NO_EXCEPTIONS)
35 if(!p)boost::throw_exception(std::runtime_error("null indirection"));
41 T* operator->()const{return p;}
42 non_raw_pointer& operator++(){++p;return *this;}
43 non_raw_pointer operator++(int){non_raw_pointer t(*this);++p;return t;}
44 non_raw_pointer& operator--(){--p;return *this;}
45 non_raw_pointer operator--(int){non_raw_pointer t(*this);--p;return t;}
46 non_raw_pointer& operator+=(std::ptrdiff_t n){p+=n;return *this;}
47 non_raw_pointer& operator-=(std::ptrdiff_t n){p-=n;return *this;}
48 T& operator[](std::ptrdiff_t n)const{return p[n];}
50 T* raw_ptr()const{return p;}
57 non_raw_pointer<T> operator+(const non_raw_pointer<T>& x,std::ptrdiff_t n)
58 {return non_raw_pointer<T>(x.raw_ptr()+n);}
61 non_raw_pointer<T> operator+(std::ptrdiff_t n,const non_raw_pointer<T>& x)
62 {return non_raw_pointer<T>(n+x.raw_ptr());}
65 non_raw_pointer<T> operator-(const non_raw_pointer<T>& x,std::ptrdiff_t n)
66 {return non_raw_pointer<T>(x.raw_ptr()-n);}
69 std::ptrdiff_t operator-(
70 const non_raw_pointer<T>& x,const non_raw_pointer<T>& y)
71 {return x.raw_ptr()-y.raw_ptr();}
74 bool operator==(const non_raw_pointer<T>& x,const non_raw_pointer<T>& y)
75 {return x.raw_ptr()==y.raw_ptr();}
78 bool operator!=(const non_raw_pointer<T>& x,const non_raw_pointer<T>& y)
79 {return x.raw_ptr()!=y.raw_ptr();}
82 bool operator<(const non_raw_pointer<T>& x,const non_raw_pointer<T>& y)
83 {return x.raw_ptr()<y.raw_ptr();}
86 bool operator>(const non_raw_pointer<T>& x,const non_raw_pointer<T>& y)
87 {return x.raw_ptr()>y.raw_ptr();}
90 bool operator>=(const non_raw_pointer<T>& x,const non_raw_pointer<T>& y)
91 {return x.raw_ptr()>=y.raw_ptr();}
94 bool operator<=(const non_raw_pointer<T>& x,const non_raw_pointer<T>& y)
95 {return x.raw_ptr()<=y.raw_ptr();}
98 class non_std_allocator
101 typedef std::size_t size_type;
102 typedef std::ptrdiff_t difference_type;
103 typedef non_raw_pointer<T> pointer;
104 typedef non_raw_pointer<const T> const_pointer;
105 typedef T& reference;
106 typedef const T& const_reference;
107 typedef T value_type;
108 template<class U>struct rebind{typedef non_std_allocator<U> other;};
110 non_std_allocator(){}
111 non_std_allocator(const non_std_allocator<T>&){}
112 template<class U>non_std_allocator(const non_std_allocator<U>&,int=0){}
114 pointer allocate(size_type n)
116 return pointer((T*)(new char[n*sizeof(T)]));
119 void deallocate(pointer p,size_type)
124 size_type max_size() const{return (size_type )(-1);}
126 friend bool operator==(const non_std_allocator&,const non_std_allocator&)
131 friend bool operator!=(const non_std_allocator&,const non_std_allocator&)