is_deallocate_trivial.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // Copyright (c) 2024 Dmitry Arkhipov (grisumbras@yandex.ru)
  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_IS_DEALLOCATE_TRIVIAL_HPP
  10. #define BOOST_JSON_IS_DEALLOCATE_TRIVIAL_HPP
  11. namespace boost {
  12. namespace json {
  13. /** Return true if a memory resource's deallocate function has no effect.
  14. This metafunction may be specialized to indicate to the library that calls
  15. to the `deallocate` function of a `boost::container::pmr::memory_resource`
  16. have no effect. The implementation will elide such calls when it is safe to
  17. do so. By default, the implementation assumes that all memory resources
  18. require a call to `deallocate` for each memory region obtained by
  19. calling `allocate`.
  20. @par Example
  21. This example specializes the metafuction for `my_resource`,
  22. to indicate that calls to deallocate have no effect:
  23. @code
  24. // Forward-declaration for a user-defined memory resource
  25. struct my_resource;
  26. // It is necessary to specialize the template from
  27. // inside the namespace in which it is declared:
  28. namespace boost {
  29. namespace json {
  30. template<>
  31. struct is_deallocate_trivial< my_resource >
  32. {
  33. static constexpr bool value = true;
  34. };
  35. } // namespace json
  36. } // namespace boost
  37. @endcode
  38. It is usually not necessary for users to check this trait.
  39. Instead, they can call @ref storage_ptr::is_deallocate_trivial
  40. to determine if the pointed-to memory resource has a trivial
  41. deallocate function.
  42. @see
  43. @ref storage_ptr,
  44. @ref boost::container::pmr::memory_resource
  45. */
  46. template<class T>
  47. struct is_deallocate_trivial
  48. {
  49. /** A bool equal to true if calls to `T::do_deallocate` have no effect.
  50. The primary template sets `value` to false.
  51. */
  52. static constexpr bool value = false;
  53. };
  54. } // namespace json
  55. } // namespace boost
  56. #endif // BOOST_JSON_IS_DEALLOCATE_TRIVIAL_HPP