1 /* 2 * Copyright Andrey Semashev 2007 - 2015. 3 * Distributed under the Boost Software License, Version 1.0. 4 * (See accompanying file LICENSE_1_0.txt or copy at 5 * http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 /*! 8 * \file stateless_allocator.hpp 9 * \author Andrey Semashev 10 * \date 11.02.2012 11 * 12 * \brief This header is the Boost.Log library implementation, see the library documentation 13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. 14 */ 15 16 #ifndef BOOST_LOG_STATELESS_ALLOCATOR_HPP_INCLUDED_ 17 #define BOOST_LOG_STATELESS_ALLOCATOR_HPP_INCLUDED_ 18 19 #include <boost/log/detail/config.hpp> 20 #include <cstddef> 21 #include <cstdlib> 22 #include <memory> 23 #include <boost/log/detail/header.hpp> 24 25 #ifdef BOOST_HAS_PRAGMA_ONCE 26 #pragma once 27 #endif 28 29 namespace boost { 30 31 BOOST_LOG_OPEN_NAMESPACE 32 33 namespace aux { 34 35 #if defined(_STLPORT_VERSION) 36 37 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) 38 39 template< typename T > 40 using stateless_allocator = std::allocator< T >; 41 42 #else 43 44 template< typename T > 45 struct stateless_allocator : 46 public std::allocator< T > 47 { 48 }; 49 50 #endif 51 52 #else 53 54 template< typename T > 55 struct stateless_allocator 56 { 57 template< typename U > 58 struct rebind 59 { 60 typedef stateless_allocator< U > other; 61 }; 62 63 typedef T value_type; 64 typedef value_type* pointer; 65 typedef value_type const* const_pointer; 66 typedef value_type& reference; 67 typedef value_type const& const_reference; 68 typedef std::size_t size_type; 69 typedef std::ptrdiff_t difference_type; 70 71 static pointer allocate(size_type n, const void* = NULL) 72 { 73 pointer p = static_cast< pointer >(std::malloc(n * sizeof(value_type))); 74 if (p) 75 return p; 76 else 77 throw std::bad_alloc(); 78 } 79 static void deallocate(pointer p, size_type) 80 { 81 std::free(p); 82 } 83 }; 84 85 #endif 86 87 } // namespace aux 88 89 BOOST_LOG_CLOSE_NAMESPACE // namespace log 90 91 } // namespace boost 92 93 #include <boost/log/detail/footer.hpp> 94 95 #endif // BOOST_LOG_STATELESS_ALLOCATOR_HPP_INCLUDED_ 96