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/core/allocator_access.hpp>
23#include <boost/core/allocator_traits.hpp>
24#endif
25#include <boost/log/utility/use_std_allocator.hpp>
26#include <boost/log/detail/header.hpp>
27
28#ifdef BOOST_HAS_PRAGMA_ONCE
29#pragma once
30#endif
31
32namespace boost {
33
34BOOST_LOG_OPEN_NAMESPACE
35
36namespace aux {
37
38// A portable name for allocator traits
39#if !defined(BOOST_NO_CXX11_ALLOCATOR)
40using std::allocator_traits;
41#else
42using boost::allocator_traits;
43#endif
44
45/*!
46 * \brief A standalone trait to rebind an allocator to another type.
47 *
48 * This trait mostly exists to hide differences between <tt>std::allocator_traits</tt> and <tt>boost::allocator_traits</tt>
49 * in terms of allocator rebinding and also provide custom behavior in some cases.
50 */
51template< typename Allocator, typename U >
52struct rebind_alloc
53{
54#if !defined(BOOST_NO_CXX11_ALLOCATOR)
55 typedef typename std::allocator_traits< Allocator >::BOOST_NESTED_TEMPLATE rebind_alloc< U > type;
56#else
57 typedef typename boost::allocator_rebind< Allocator, U >::type type;
58#endif
59};
60
61/*!
62 * This specialization mostly exists to keep <tt>std::allocator&lt;void&gt;</tt> working.
63 * The default template will attempt to instantiate the allocator type to test if it provides the nested <tt>rebind</tt> template.
64 * We don't want that to happen because it prohibits using <tt>std::allocator&lt;void&gt;</tt> in C++17 and later, which deprecated
65 * this allocator specialization. This specialization does not use the nested <tt>rebind</tt> template in this case.
66 */
67template< typename T, typename U >
68struct rebind_alloc< std::allocator< T >, U >
69{
70 typedef std::allocator< U > type;
71};
72
73template< typename U >
74struct rebind_alloc< use_std_allocator, U >
75{
76 typedef std::allocator< U > type;
77};
78
79} // namespace aux
80
81BOOST_LOG_CLOSE_NAMESPACE // namespace log
82
83} // namespace boost
84
85#include <boost/log/detail/footer.hpp>
86
87#endif // BOOST_LOG_ALLOCATOR_TRAITS_HPP_INCLUDED_
88

source code of boost/libs/log/include/boost/log/detail/allocator_traits.hpp