#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <algorithm>
-#include <boost/detail/allocator_utilities.hpp>
#include <boost/multi_index/detail/adl_swap.hpp>
+#include <boost/multi_index/detail/allocator_traits.hpp>
#include <boost/noncopyable.hpp>
#include <memory>
template<typename T,typename Allocator=std::allocator<T> >
struct auto_space:private noncopyable
{
- typedef typename boost::detail::allocator::rebind_to<
- Allocator,T
- >::type allocator;
-#ifdef BOOST_NO_CXX11_ALLOCATOR
- typedef typename allocator::pointer pointer;
-#else
- typedef std::allocator_traits<allocator> traits;
- typedef typename traits::pointer pointer;
-#endif
-
- explicit auto_space(const Allocator& al=Allocator(),std::size_t n=1):
- al_(al),n_(n),
-#ifdef BOOST_NO_CXX11_ALLOCATOR
- data_(n_?al_.allocate(n_):pointer(0))
-#else
- data_(n_?traits::allocate(al_,n_):pointer(0))
-#endif
+ typedef typename rebind_alloc_for<
+ Allocator,T>
+ ::type allocator;
+ typedef allocator_traits<allocator> alloc_traits;
+ typedef typename alloc_traits::pointer pointer;
+ typedef typename alloc_traits::size_type size_type;
+
+ explicit auto_space(const Allocator& al=Allocator(),size_type n=1):
+ al_(al),n_(n),data_(n_?alloc_traits::allocate(al_,n_):pointer(0))
{}
- ~auto_space()
- {
- if(n_)
-#ifdef BOOST_NO_CXX11_ALLOCATOR
- al_.deallocate(data_,n_);
-#else
- traits::deallocate(al_,data_,n_);
-#endif
- }
+ ~auto_space(){if(n_)alloc_traits::deallocate(al_,data_,n_);}
Allocator get_allocator()const{return al_;}
}
private:
- allocator al_;
- std::size_t n_;
- pointer data_;
+ allocator al_;
+ size_type n_;
+ pointer data_;
};
template<typename T,typename Allocator>