]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/json/memory_resource.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / json / memory_resource.hpp
1 //
2 // Copyright (c) 2019 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/json
8 //
9
10 #ifndef BOOST_JSON_MEMORY_RESOURCE_HPP
11 #define BOOST_JSON_MEMORY_RESOURCE_HPP
12
13 #include <boost/json/detail/config.hpp>
14
15 #include <boost/container/pmr/memory_resource.hpp>
16 #include <boost/container/pmr/polymorphic_allocator.hpp>
17
18 BOOST_JSON_NS_BEGIN
19
20 #ifdef BOOST_JSON_DOCS
21
22 /** The type of memory resource used by the library.
23
24 Alias for `boost::container::pmr::memory_resource`.
25 */
26 class memory_resource
27 {
28 };
29
30 /** The type of polymorphic allocator used by the library.
31
32 Alias template for `boost::container::pmr::polymorphic_allocator`.
33 */
34 template<class T>
35 class polymorphic_allocator;
36
37 // VFALCO Bug: doc toolchain won't make this a ref
38 //using memory_resource = __see_below__;
39
40 #else
41 using memory_resource = boost::container::pmr::memory_resource;
42
43 template<class T>
44 using polymorphic_allocator =
45 boost::container::pmr::polymorphic_allocator<T>;
46 #endif
47
48 /** Return true if a memory resource's deallocate function has no effect.
49
50 This metafunction may be specialized to indicate to
51 the library that calls to the `deallocate` function of
52 a @ref memory_resource have no effect. The implementation
53 will elide such calls when it is safe to do so. By default,
54 the implementation assumes that all memory resources
55 require a call to `deallocate` for each memory region
56 obtained by calling `allocate`.
57
58 @par Example
59
60 This example specializes the metafuction for `my_resource`,
61 to indicate that calls to deallocate have no effect:
62
63 @code
64
65 // Forward-declaration for a user-defined memory resource
66 struct my_resource;
67
68 // It is necessary to specialize the template from
69 // inside the namespace in which it is declared:
70
71 namespace boost {
72 namespace json {
73
74 template<>
75 struct is_deallocate_trivial< my_resource >
76 {
77 static constexpr bool value = true;
78 };
79
80 } // namespace json
81 } // namespace boost
82
83 @endcode
84
85 It is usually not necessary for users to check this trait.
86 Instead, they can call @ref storage_ptr::is_deallocate_trivial
87 to determine if the pointed-to memory resource has a trivial
88 deallocate function.
89
90 @see
91 @ref memory_resource,
92 @ref storage_ptr
93 */
94 template<class T>
95 struct is_deallocate_trivial
96 {
97 /** A bool equal to true if calls to `T::do_deallocate` have no effect.
98
99 The primary template sets `value` to false.
100 */
101 static constexpr bool value = false;
102 };
103
104 BOOST_JSON_NS_END
105
106 #endif