recycled.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
  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/url
  8. //
  9. #ifndef BOOST_URL_GRAMMAR_DETAIL_RECYCLED_HPP
  10. #define BOOST_URL_GRAMMAR_DETAIL_RECYCLED_HPP
  11. #include <utility>
  12. namespace boost {
  13. namespace urls {
  14. namespace grammar {
  15. namespace detail {
  16. template<
  17. std::size_t Size,
  18. std::size_t Align>
  19. struct aligned_storage_impl
  20. {
  21. void* addr() noexcept
  22. {
  23. return buf_;
  24. }
  25. void const* addr() const noexcept
  26. {
  27. return buf_;
  28. }
  29. private:
  30. alignas(Align)
  31. unsigned char buf_[Size];
  32. };
  33. constexpr
  34. std::size_t
  35. nearest_pow2(
  36. std::size_t x,
  37. std::size_t f = 0) noexcept
  38. {
  39. return
  40. (f <= (std::size_t(-1)/2))
  41. ? ( x <= f
  42. ? f
  43. : nearest_pow2(x, 2 * f))
  44. : x;
  45. }
  46. //------------------------------------------------
  47. BOOST_URL_DECL
  48. void
  49. recycled_add_impl(
  50. std::size_t) noexcept;
  51. BOOST_URL_DECL
  52. void
  53. recycled_remove_impl(
  54. std::size_t) noexcept;
  55. #ifdef BOOST_URL_REPORT
  56. inline
  57. void
  58. recycled_add(
  59. std::size_t n) noexcept
  60. {
  61. recycled_add_impl(n);
  62. }
  63. inline
  64. void
  65. recycled_remove(
  66. std::size_t n) noexcept
  67. {
  68. recycled_remove_impl(n);
  69. }
  70. #else
  71. inline void recycled_add(
  72. std::size_t) noexcept
  73. {
  74. }
  75. inline void recycled_remove(
  76. std::size_t) noexcept
  77. {
  78. }
  79. #endif
  80. } // detail
  81. } // grammar
  82. } // urls
  83. } // boost
  84. #endif