/* Used in Boost.MultiIndex tests. * * Copyright 2003-2020 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See http://www.boost.org/libs/multi_index for library home page. */ #ifndef BOOST_MULTI_INDEX_TEST_ROOTED_ALLOCATOR_HPP #define BOOST_MULTI_INDEX_TEST_ROOTED_ALLOCATOR_HPP #include /* keep it first to prevent nasty warns in MSVC */ #include #include #if defined(BOOST_MSVC) #pragma warning(push) #pragma warning(disable:4355) /* this used in base member initializer list */ #endif template class rooted_allocator:public std::allocator { typedef boost::integral_constant propagate_type; typedef boost::integral_constant always_equal_type; public: typedef propagate_type propagate_on_container_copy_assignment; typedef propagate_type propagate_on_container_move_assignment; typedef propagate_type propagate_on_container_swap; typedef always_equal_type is_always_equal; template struct rebind{typedef rooted_allocator other;}; rooted_allocator():root(0){} explicit rooted_allocator(int):root(this){} template rooted_allocator(const rooted_allocator& x): root(x.root){} template bool operator==(const rooted_allocator& x)const {return AlwaysEqual?true:root==x.root;} template bool operator!=(const rooted_allocator& x)const {return !(*this==x);} template bool comes_from(const rooted_allocator& x)const {return root==&x;} private: template friend class rooted_allocator; const void* root; }; #if defined(BOOST_MSVC) #pragma warning(pop) /* C4355 */ #endif #endif