Files
entt/memory_8hpp_source.html
2021-12-21 13:20:51 +01:00

157 lines
18 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>EnTT: src/entt/core/memory.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">EnTT
&#160;<span id="projectnumber">3.9.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_66e9674e8206a335795995fa32a03c91.html">entt</a></li><li class="navelem"><a class="el" href="dir_de8f4e6ba3f54a2a21309f742e93a373.html">core</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">memory.hpp</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="preprocessor">#ifndef ENTT_CORE_MEMORY_HPP</span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="preprocessor">#define ENTT_CORE_MEMORY_HPP</span></div>
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160; </div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="preprocessor">#include &lt;cstddef&gt;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="preprocessor">#include &lt;limits&gt;</span></div>
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="preprocessor">#include &lt;type_traits&gt;</span></div>
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="preprocessor">#include &lt;utility&gt;</span></div>
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="preprocessor">#include &quot;../config/config.h&quot;</span></div>
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceentt.html">entt</a> {</div>
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160; </div>
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> Type&gt;</div>
<div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="namespaceentt.html#a94ed50d1975e6adee73101eb05c88d73"> 20</a></span>&#160;[[nodiscard]] constexpr <span class="keyword">auto</span> <a class="code" href="namespaceentt.html#a94ed50d1975e6adee73101eb05c88d73">to_address</a>(Type &amp;&amp;ptr) ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160; <span class="keywordflow">if</span> constexpr(std::is_pointer_v&lt;std::remove_const_t&lt;std::remove_reference_t&lt;Type&gt;&gt;&gt;) {</div>
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160; <span class="keywordflow">return</span> ptr;</div>
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160; } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160; <span class="keywordflow">return</span> <a class="code" href="namespaceentt.html#a94ed50d1975e6adee73101eb05c88d73">to_address</a>(std::forward&lt;Type&gt;(ptr).operator-&gt;());</div>
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160; }</div>
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;}</div>
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160; </div>
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> Allocator&gt;</div>
<div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="namespaceentt.html#a9eb49df8bf1b69e836039b76e5b9938e"> 35</a></span>&#160;constexpr <span class="keywordtype">void</span> <a class="code" href="namespaceentt.html#a9eb49df8bf1b69e836039b76e5b9938e">propagate_on_container_copy_assignment</a>([[maybe_unused]] Allocator &amp;lhs, [[maybe_unused]] Allocator &amp;rhs) ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160; <span class="keywordflow">if</span> constexpr(std::allocator_traits&lt;Allocator&gt;::propagate_on_container_copy_assignment::value) {</div>
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160; lhs = rhs;</div>
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160; }</div>
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;}</div>
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160; </div>
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> Allocator&gt;</div>
<div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="namespaceentt.html#a122ae54373a080574c45c77319cec7f7"> 48</a></span>&#160;constexpr <span class="keywordtype">void</span> <a class="code" href="namespaceentt.html#a122ae54373a080574c45c77319cec7f7">propagate_on_container_move_assignment</a>([[maybe_unused]] Allocator &amp;lhs, [[maybe_unused]] Allocator &amp;rhs) ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; <span class="keywordflow">if</span> constexpr(std::allocator_traits&lt;Allocator&gt;::propagate_on_container_move_assignment::value) {</div>
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; lhs = std::move(rhs);</div>
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; }</div>
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;}</div>
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; </div>
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> Allocator&gt;</div>
<div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="namespaceentt.html#a1359cd624e6726f884df34df66656855"> 61</a></span>&#160;constexpr <span class="keywordtype">void</span> <a class="code" href="namespaceentt.html#a1359cd624e6726f884df34df66656855">propagate_on_container_swap</a>([[maybe_unused]] Allocator &amp;lhs, [[maybe_unused]] Allocator &amp;rhs) ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160; ENTT_ASSERT(std::allocator_traits&lt;Allocator&gt;::propagate_on_container_swap::value || lhs == rhs, <span class="stringliteral">&quot;Cannot swap the containers&quot;</span>);</div>
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160; </div>
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; <span class="keywordflow">if</span> constexpr(std::allocator_traits&lt;Allocator&gt;::propagate_on_container_swap::value) {</div>
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; <span class="keyword">using</span> std::swap;</div>
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; <a class="code" href="namespaceentt.html#aef08fc4202f32f712bde26f55db463cb">swap</a>(lhs, rhs);</div>
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; }</div>
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160;}</div>
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; </div>
<div class="line"><a name="l00075"></a><span class="lineno"><a class="line" href="namespaceentt.html#a3755517604de1d9d3f3e0a5549c750c5"> 75</a></span>&#160;[[nodiscard]] <span class="keyword">inline</span> constexpr <span class="keywordtype">bool</span> <a class="code" href="namespaceentt.html#a3755517604de1d9d3f3e0a5549c750c5">is_power_of_two</a>(<span class="keyword">const</span> std::size_t value) ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160; <span class="keywordflow">return</span> value &amp;&amp; ((value &amp; (value - 1)) == 0);</div>
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160;}</div>
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160; </div>
<div class="line"><a name="l00084"></a><span class="lineno"><a class="line" href="namespaceentt.html#a5a2dbf5d86123af800abdd8fe69542ca"> 84</a></span>&#160;[[nodiscard]] <span class="keyword">inline</span> constexpr std::size_t <a class="code" href="namespaceentt.html#a5a2dbf5d86123af800abdd8fe69542ca">next_power_of_two</a>(<span class="keyword">const</span> std::size_t value) ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160; ENTT_ASSERT(value &lt; (std::size_t{1u} &lt;&lt; (std::numeric_limits&lt;std::size_t&gt;::digits - 1)), <span class="stringliteral">&quot;Numeric limits exceeded&quot;</span>);</div>
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>&#160; std::size_t curr = value - (value != 0u);</div>
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>&#160; </div>
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>&#160; <span class="keywordflow">for</span>(<span class="keywordtype">int</span> next = 1; next &lt; std::numeric_limits&lt;std::size_t&gt;::digits; next = next * 2) {</div>
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160; curr |= curr &gt;&gt; next;</div>
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160; }</div>
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160; </div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160; <span class="keywordflow">return</span> ++curr;</div>
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>&#160;}</div>
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>&#160; </div>
<div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="namespaceentt.html#a28fe7952c2a11ebc2b47d95fb749adda"> 101</a></span>&#160;[[nodiscard]] <span class="keyword">inline</span> constexpr std::size_t <a class="code" href="namespaceentt.html#a28fe7952c2a11ebc2b47d95fb749adda">fast_mod</a>(<span class="keyword">const</span> std::size_t value, <span class="keyword">const</span> std::size_t mod) ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; ENTT_ASSERT(<a class="code" href="namespaceentt.html#a3755517604de1d9d3f3e0a5549c750c5">is_power_of_two</a>(mod), <span class="stringliteral">&quot;Value must be a power of two&quot;</span>);</div>
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160; <span class="keywordflow">return</span> value &amp; (mod - 1u);</div>
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160;}</div>
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; </div>
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160;} <span class="comment">// namespace entt</span></div>
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160; </div>
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="ttc" id="anamespaceentt_html"><div class="ttname"><a href="namespaceentt.html">entt</a></div><div class="ttdoc">EnTT default namespace.</div><div class="ttdef"><b>Definition:</b> <a href="dense__hash__map_8hpp_source.html#l00021">dense_hash_map.hpp:21</a></div></div>
<div class="ttc" id="anamespaceentt_html_a122ae54373a080574c45c77319cec7f7"><div class="ttname"><a href="namespaceentt.html#a122ae54373a080574c45c77319cec7f7">entt::propagate_on_container_move_assignment</a></div><div class="ttdeci">constexpr void propagate_on_container_move_assignment([[maybe_unused]] Allocator &amp;lhs, [[maybe_unused]] Allocator &amp;rhs)</div><div class="ttdoc">Utility function to design allocation-aware containers.</div><div class="ttdef"><b>Definition:</b> <a href="memory_8hpp_source.html#l00048">memory.hpp:48</a></div></div>
<div class="ttc" id="anamespaceentt_html_a1359cd624e6726f884df34df66656855"><div class="ttname"><a href="namespaceentt.html#a1359cd624e6726f884df34df66656855">entt::propagate_on_container_swap</a></div><div class="ttdeci">constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &amp;lhs, [[maybe_unused]] Allocator &amp;rhs)</div><div class="ttdoc">Utility function to design allocation-aware containers.</div><div class="ttdef"><b>Definition:</b> <a href="memory_8hpp_source.html#l00061">memory.hpp:61</a></div></div>
<div class="ttc" id="anamespaceentt_html_a28fe7952c2a11ebc2b47d95fb749adda"><div class="ttname"><a href="namespaceentt.html#a28fe7952c2a11ebc2b47d95fb749adda">entt::fast_mod</a></div><div class="ttdeci">constexpr std::size_t fast_mod(const std::size_t value, const std::size_t mod)</div><div class="ttdoc">Fast module utility function (powers of two only).</div><div class="ttdef"><b>Definition:</b> <a href="memory_8hpp_source.html#l00101">memory.hpp:101</a></div></div>
<div class="ttc" id="anamespaceentt_html_a3755517604de1d9d3f3e0a5549c750c5"><div class="ttname"><a href="namespaceentt.html#a3755517604de1d9d3f3e0a5549c750c5">entt::is_power_of_two</a></div><div class="ttdeci">constexpr bool is_power_of_two(const std::size_t value)</div><div class="ttdoc">Checks whether a value is a power of two or not.</div><div class="ttdef"><b>Definition:</b> <a href="memory_8hpp_source.html#l00075">memory.hpp:75</a></div></div>
<div class="ttc" id="anamespaceentt_html_a5a2dbf5d86123af800abdd8fe69542ca"><div class="ttname"><a href="namespaceentt.html#a5a2dbf5d86123af800abdd8fe69542ca">entt::next_power_of_two</a></div><div class="ttdeci">constexpr std::size_t next_power_of_two(const std::size_t value)</div><div class="ttdoc">Computes the smallest power of two greater than or equal to a value.</div><div class="ttdef"><b>Definition:</b> <a href="memory_8hpp_source.html#l00084">memory.hpp:84</a></div></div>
<div class="ttc" id="anamespaceentt_html_a94ed50d1975e6adee73101eb05c88d73"><div class="ttname"><a href="namespaceentt.html#a94ed50d1975e6adee73101eb05c88d73">entt::to_address</a></div><div class="ttdeci">constexpr auto to_address(Type &amp;&amp;ptr)</div><div class="ttdoc">Unwraps fancy pointers, does nothing otherwise (waiting for C++20).</div><div class="ttdef"><b>Definition:</b> <a href="memory_8hpp_source.html#l00020">memory.hpp:20</a></div></div>
<div class="ttc" id="anamespaceentt_html_a9eb49df8bf1b69e836039b76e5b9938e"><div class="ttname"><a href="namespaceentt.html#a9eb49df8bf1b69e836039b76e5b9938e">entt::propagate_on_container_copy_assignment</a></div><div class="ttdeci">constexpr void propagate_on_container_copy_assignment([[maybe_unused]] Allocator &amp;lhs, [[maybe_unused]] Allocator &amp;rhs)</div><div class="ttdoc">Utility function to design allocation-aware containers.</div><div class="ttdef"><b>Definition:</b> <a href="memory_8hpp_source.html#l00035">memory.hpp:35</a></div></div>
<div class="ttc" id="anamespaceentt_html_aef08fc4202f32f712bde26f55db463cb"><div class="ttname"><a href="namespaceentt.html#aef08fc4202f32f712bde26f55db463cb">entt::swap</a></div><div class="ttdeci">void swap(compressed_pair&lt; First, Second &gt; &amp;lhs, compressed_pair&lt; First, Second &gt; &amp;rhs)</div><div class="ttdoc">Swaps two compressed pair objects.</div><div class="ttdef"><b>Definition:</b> <a href="compressed__pair_8hpp_source.html#l00248">compressed_pair.hpp:248</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>