is_deallocate_trivial.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 @ref
  16. boost::container::pmr::memory_resource have no effect. The implementation
  17. will elide such calls when it is safe to do so. By default, the
  18. implementation assumes that all memory resources require a call to
  19. `deallocate` for each memory region obtained by calling `allocate`.
  20. @par Example
  21. This example specializes the metafuction for `my_resource`, to indicate
  22. 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. Instead, they
  39. can call @ref storage_ptr::is_deallocate_trivial to determine if the
  40. pointed-to memory resource has a trivial deallocate function.
  41. @see @ref storage_ptr, @ref boost::container::pmr::memory_resource.
  42. */
  43. template<class T>
  44. struct is_deallocate_trivial
  45. {
  46. /** A bool equal to true if calls to `T::do_deallocate` have no effect.
  47. The primary template sets `value` to false.
  48. */
  49. static constexpr bool value = false;
  50. };
  51. } // namespace json
  52. } // namespace boost
  53. #endif // BOOST_JSON_IS_DEALLOCATE_TRIVIAL_HPP