default_resource.ipp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_DETAIL_IMPL_DEFAULT_RESOURCE_IPP
  10. #define BOOST_JSON_DETAIL_IMPL_DEFAULT_RESOURCE_IPP
  11. #include <boost/json/detail/default_resource.hpp>
  12. namespace boost {
  13. namespace json {
  14. namespace detail {
  15. #ifndef BOOST_JSON_WEAK_CONSTINIT
  16. # ifndef BOOST_JSON_NO_DESTROY
  17. BOOST_JSON_REQUIRE_CONST_INIT
  18. default_resource::holder
  19. default_resource::instance_;
  20. # else
  21. BOOST_JSON_REQUIRE_CONST_INIT
  22. default_resource
  23. default_resource::instance_;
  24. # endif
  25. #endif
  26. // this is here so that ~memory_resource
  27. // is emitted in the library instead of
  28. // the user's TU.
  29. default_resource::
  30. ~default_resource() = default;
  31. void*
  32. default_resource::
  33. do_allocate(
  34. std::size_t n,
  35. std::size_t)
  36. {
  37. return ::operator new(n);
  38. }
  39. void
  40. default_resource::
  41. do_deallocate(
  42. void* p,
  43. std::size_t,
  44. std::size_t)
  45. {
  46. ::operator delete(p);
  47. }
  48. bool
  49. default_resource::
  50. do_is_equal(
  51. memory_resource const& mr) const noexcept
  52. {
  53. return this == &mr;
  54. }
  55. } // detail
  56. } // namespace json
  57. } // namespace boost
  58. #endif