123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #ifndef BOOST_DETAIL_ALLOCATOR_UTILITIES_HPP
- #define BOOST_DETAIL_ALLOCATOR_UTILITIES_HPP
- #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
- #include <boost/detail/workaround.hpp>
- #include <boost/mpl/eval_if.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <cstddef>
- #include <memory>
- #include <new>
- namespace boost{
- namespace detail{
- namespace allocator{
- template<typename Type>
- class partial_std_allocator_wrapper:public std::allocator<Type>
- {
- public:
-
- typedef Type value_type;
- partial_std_allocator_wrapper(){};
- template<typename Other>
- partial_std_allocator_wrapper(const partial_std_allocator_wrapper<Other>&){}
- partial_std_allocator_wrapper(const std::allocator<Type>& x):
- std::allocator<Type>(x)
- {
- };
- #if defined(BOOST_DINKUMWARE_STDLIB)
-
- Type* allocate(std::size_t n,const void* hint=0)
- {
- std::allocator<Type>& a=*this;
- return a.allocate(n,hint);
- }
- #endif
- };
- #if defined(BOOST_NO_STD_ALLOCATOR)&&\
- (defined(BOOST_HAS_PARTIAL_STD_ALLOCATOR)||defined(BOOST_DINKUMWARE_STDLIB))
- template<typename Allocator>
- struct is_partial_std_allocator
- {
- BOOST_STATIC_CONSTANT(bool,
- value=
- (is_same<
- std::allocator<BOOST_DEDUCED_TYPENAME Allocator::value_type>,
- Allocator
- >::value)||
- (is_same<
- partial_std_allocator_wrapper<
- BOOST_DEDUCED_TYPENAME Allocator::value_type>,
- Allocator
- >::value));
- };
- #else
- template<typename Allocator>
- struct is_partial_std_allocator
- {
- BOOST_STATIC_CONSTANT(bool,value=false);
- };
- #endif
- template<typename Allocator,typename Type>
- struct partial_std_allocator_rebind_to
- {
- typedef partial_std_allocator_wrapper<Type> type;
- };
- template<typename Allocator>
- struct rebinder
- {
- template<typename Type>
- struct result
- {
- typedef typename Allocator::BOOST_NESTED_TEMPLATE
- rebind<Type>::other other;
- };
- };
- template<typename Allocator,typename Type>
- struct compliant_allocator_rebind_to
- {
- typedef typename rebinder<Allocator>::
- BOOST_NESTED_TEMPLATE result<Type>::other type;
- };
- template<typename Allocator,typename Type>
- struct rebind_to:
- mpl::eval_if_c<
- is_partial_std_allocator<Allocator>::value,
- partial_std_allocator_rebind_to<Allocator,Type>,
- compliant_allocator_rebind_to<Allocator,Type>
- >
- {
- };
- template<typename Type>
- void construct(void* p,const Type& t)
- {
- new (p) Type(t);
- }
- #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
- #pragma warning(push)
- #pragma warning(disable:4100)
- #endif
- template<typename Type>
- void destroy(const Type* p)
- {
- #if BOOST_WORKAROUND(__SUNPRO_CC,BOOST_TESTED_AT(0x590))
- const_cast<Type*>(p)->~Type();
- #else
- p->~Type();
- #endif
- }
- #if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1500))
- #pragma warning(pop)
- #endif
- }
- }
- }
- #endif
|