allocator_traits.hpp 2.6 KB

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