allocator_traits.hpp 2.4 KB

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