#include #include #include #include #include template class SimpleAllocator { public: typedef Ty value_type; typedef typename std::allocator::pointer pointer; typedef typename std::allocator::size_type size_type; SimpleAllocator(int value) : _value(value) {} template SimpleAllocator(const SimpleAllocator &other) : _value(other._value) {} pointer allocate(size_type n) { return _allocator.allocate(n); } void deallocate(pointer p, size_type n) { _allocator.deallocate(p, n); } private: int _value; std::allocator _allocator; template friend class SimpleAllocator; }; template class ScopedAllocator : public boost::container::scoped_allocator_adaptor > { private: typedef boost::container::scoped_allocator_adaptor > Base; public: ScopedAllocator(int value) : Base(SimpleAllocator(value)) {} }; class Resource { private: // Not copyable Resource(const Resource &); Resource &operator=(const Resource &); public: typedef SimpleAllocator allocator_type; Resource(BOOST_RV_REF(Resource)other) : _value(other._value), _allocator(boost::move(other._allocator)) { other._value = -1; } Resource(BOOST_RV_REF(Resource)other, const allocator_type &allocator) : _value(other._value), _allocator(allocator) { other._value = -1; } Resource(int value, const allocator_type &allocator) : _value(value), _allocator(allocator) {} private: int _value; allocator_type _allocator; }; typedef std::pair MapNode; typedef boost::container::scoped_allocator_adaptor > MapAllocator; typedef boost::container::map, MapAllocator> Map; int main() { Map map1(std::less(), SimpleAllocator(5)); map1.emplace("foo", 42); map1.emplace("bar", 11); //Map map2 = map1; return 0; }