1 /* 2 * Copyright Andrey Semashev 2018. 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 allocator_traits.hpp 9 * \author Andrey Semashev 10 * \date 03.01.2018 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_ALLOCATOR_TRAITS_HPP_INCLUDED_ 17 #define BOOST_LOG_ALLOCATOR_TRAITS_HPP_INCLUDED_ 18 19 #include <memory> 20 #include <boost/log/detail/config.hpp> 21 #if defined(BOOST_NO_CXX11_ALLOCATOR) 22 #include <boost/container/allocator_traits.hpp> 23 #endif 24 #include <boost/log/detail/header.hpp> 25 26 #ifdef BOOST_HAS_PRAGMA_ONCE 27 #pragma once 28 #endif 29 30 namespace boost { 31 32 BOOST_LOG_OPEN_NAMESPACE 33 34 namespace aux { 35 36 // A portable name for allocator traits 37 #if !defined(BOOST_NO_CXX11_ALLOCATOR) 38 using std::allocator_traits; 39 #else 40 using boost::container::allocator_traits; 41 #endif 42 43 /*! 44 * \brief A standalone trait to rebind an allocator to another type. 45 * 46 * The important difference from <tt>std::allocator_traits<Alloc>::rebind_alloc<U></tt> is that this 47 * trait does not require template aliases and thus is compatible with C++03. There is 48 * <tt>boost::container::allocator_traits<Alloc>::portable_rebind_alloc<U></tt>, but it is not present in <tt>std::allocator_traits</tt>. 49 * It will also attempt to instantiate the allocator type to test if it provides the nested <tt>rebind</tt> template. We don't want 50 * that to happen because it prohibits using <tt>std::allocator<void></tt> in C++17 and later, which deprecated 51 * this allocator specialization. This standalone trait does not use the nested <tt>rebind</tt> template in this case. 52 */ 53 template< typename Allocator, typename U > 54 struct rebind_alloc 55 { 56 #if !defined(BOOST_NO_CXX11_ALLOCATOR) 57 typedef typename std::allocator_traits< Allocator >::BOOST_NESTED_TEMPLATE rebind_alloc< U > type; 58 #else 59 typedef typename boost::container::allocator_traits< Allocator >::BOOST_NESTED_TEMPLATE portable_rebind_alloc< U >::type type; 60 #endif 61 }; 62 63 template< typename U > 64 struct rebind_alloc< std::allocator< void >, U > 65 { 66 typedef std::allocator< U > type; 67 }; 68 69 } // namespace aux 70 71 BOOST_LOG_CLOSE_NAMESPACE // namespace log 72 73 } // namespace boost 74 75 #include <boost/log/detail/footer.hpp> 76 77 #endif // BOOST_LOG_ALLOCATOR_TRAITS_HPP_INCLUDED_ 78