File indexing completed on 2025-01-18 09:42:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MULTI_INDEX_DETAIL_AUTO_SPACE_HPP
0010 #define BOOST_MULTI_INDEX_DETAIL_AUTO_SPACE_HPP
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <algorithm>
0018 #include <boost/core/noncopyable.hpp>
0019 #include <boost/multi_index/detail/adl_swap.hpp>
0020 #include <boost/multi_index/detail/allocator_traits.hpp>
0021 #include <boost/type_traits/integral_constant.hpp>
0022 #include <memory>
0023
0024 namespace boost{
0025
0026 namespace multi_index{
0027
0028 namespace detail{
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 template<typename T,typename Allocator=std::allocator<T> >
0047 struct auto_space:private noncopyable
0048 {
0049 typedef typename rebind_alloc_for<
0050 Allocator,T>
0051 ::type allocator;
0052 typedef allocator_traits<allocator> alloc_traits;
0053 typedef typename alloc_traits::pointer pointer;
0054 typedef typename alloc_traits::size_type size_type;
0055
0056 explicit auto_space(const Allocator& al=Allocator(),size_type n=1):
0057 al_(al),n_(n),data_(n_?alloc_traits::allocate(al_,n_):pointer(0))
0058 {}
0059
0060 ~auto_space(){if(n_)alloc_traits::deallocate(al_,data_,n_);}
0061
0062 Allocator get_allocator()const{return al_;}
0063
0064 pointer data()const{return data_;}
0065
0066 void swap(auto_space& x)
0067 {
0068 swap(
0069 x,
0070 boost::integral_constant<
0071 bool,alloc_traits::propagate_on_container_swap::value>());
0072 }
0073
0074 void swap(auto_space& x,boost::true_type )
0075 {
0076 adl_swap(al_,x.al_);
0077 std::swap(n_,x.n_);
0078 std::swap(data_,x.data_);
0079 }
0080
0081 void swap(auto_space& x,boost::false_type )
0082 {
0083 std::swap(n_,x.n_);
0084 std::swap(data_,x.data_);
0085 }
0086
0087 private:
0088 allocator al_;
0089 size_type n_;
0090 pointer data_;
0091 };
0092
0093 template<typename T,typename Allocator>
0094 void swap(auto_space<T,Allocator>& x,auto_space<T,Allocator>& y)
0095 {
0096 x.swap(y);
0097 }
0098
0099 }
0100
0101 }
0102
0103 }
0104
0105 #endif