1 /* Used in Boost.MultiIndex tests. 2 * 3 * Copyright 2003-2020 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) 7 * 8 * See http://www.boost.org/libs/multi_index for library home page. 9 */ 10 11 #ifndef BOOST_MULTI_INDEX_TEST_ROOTED_ALLOCATOR_HPP 12 #define BOOST_MULTI_INDEX_TEST_ROOTED_ALLOCATOR_HPP 13 14 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ 15 #include <boost/type_traits/integral_constant.hpp> 16 #include <memory> 17 18 #if defined(BOOST_MSVC) 19 #pragma warning(push) 20 #pragma warning(disable:4355) /* this used in base member initializer list */ 21 #endif 22 23 template<typename T,bool Propagate,bool AlwaysEqual> 24 class rooted_allocator:public std::allocator<T> 25 { 26 typedef boost::integral_constant<bool,Propagate> propagate_type; 27 typedef boost::integral_constant<bool,AlwaysEqual> always_equal_type; 28 29 public: 30 typedef propagate_type propagate_on_container_copy_assignment; 31 typedef propagate_type propagate_on_container_move_assignment; 32 typedef propagate_type propagate_on_container_swap; 33 typedef always_equal_type is_always_equal; 34 template<typename U> 35 struct rebind{typedef rooted_allocator<U,Propagate,AlwaysEqual> other;}; 36 rooted_allocator()37 rooted_allocator():root(0){} rooted_allocator(int)38 explicit rooted_allocator(int):root(this){} 39 template<typename U> rooted_allocator(const rooted_allocator<U,Propagate,AlwaysEqual> & x)40 rooted_allocator(const rooted_allocator<U,Propagate,AlwaysEqual>& x): 41 root(x.root){} 42 43 template<typename U> operator ==(const rooted_allocator<U,Propagate,AlwaysEqual> & x) const44 bool operator==(const rooted_allocator<U,Propagate,AlwaysEqual>& x)const 45 {return AlwaysEqual?true:root==x.root;} 46 template<typename U> operator !=(const rooted_allocator<U,Propagate,AlwaysEqual> & x) const47 bool operator!=(const rooted_allocator<U,Propagate,AlwaysEqual>& x)const 48 {return !(*this==x);} 49 50 template<typename U> comes_from(const rooted_allocator<U,Propagate,AlwaysEqual> & x) const51 bool comes_from(const rooted_allocator<U,Propagate,AlwaysEqual>& x)const 52 {return root==&x;} 53 54 private: 55 template<typename,bool,bool> friend class rooted_allocator; 56 57 const void* root; 58 }; 59 60 #if defined(BOOST_MSVC) 61 #pragma warning(pop) /* C4355 */ 62 #endif 63 64 #endif 65