157 lines
18 KiB
HTML
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
|
|
 <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&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&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> <span class="preprocessor">#ifndef ENTT_CORE_MEMORY_HPP</span></div>
|
|
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="preprocessor">#define ENTT_CORE_MEMORY_HPP</span></div>
|
|
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span>  </div>
|
|
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="preprocessor">#include <cstddef></span></div>
|
|
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="preprocessor">#include <limits></span></div>
|
|
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="preprocessor">#include <memory></span></div>
|
|
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="preprocessor">#include <type_traits></span></div>
|
|
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="preprocessor">#include <utility></span></div>
|
|
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="preprocessor">#include "../config/config.h"</span></div>
|
|
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span>  </div>
|
|
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <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>  </div>
|
|
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="keyword">template</span><<span class="keyword">typename</span> Type></div>
|
|
<div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="namespaceentt.html#a94ed50d1975e6adee73101eb05c88d73"> 20</a></span> [[nodiscard]] constexpr <span class="keyword">auto</span> <a class="code" href="namespaceentt.html#a94ed50d1975e6adee73101eb05c88d73">to_address</a>(Type &&ptr) ENTT_NOEXCEPT {</div>
|
|
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span>  <span class="keywordflow">if</span> constexpr(std::is_pointer_v<std::remove_const_t<std::remove_reference_t<Type>>>) {</div>
|
|
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span>  <span class="keywordflow">return</span> ptr;</div>
|
|
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span>  } <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span>  <span class="keywordflow">return</span> <a class="code" href="namespaceentt.html#a94ed50d1975e6adee73101eb05c88d73">to_address</a>(std::forward<Type>(ptr).operator->());</div>
|
|
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span>  }</div>
|
|
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span> }</div>
|
|
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>  </div>
|
|
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="keyword">template</span><<span class="keyword">typename</span> Allocator></div>
|
|
<div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="namespaceentt.html#a9eb49df8bf1b69e836039b76e5b9938e"> 35</a></span> constexpr <span class="keywordtype">void</span> <a class="code" href="namespaceentt.html#a9eb49df8bf1b69e836039b76e5b9938e">propagate_on_container_copy_assignment</a>([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {</div>
|
|
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  <span class="keywordflow">if</span> constexpr(std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value) {</div>
|
|
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  lhs = rhs;</div>
|
|
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  }</div>
|
|
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span> }</div>
|
|
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  </div>
|
|
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="keyword">template</span><<span class="keyword">typename</span> Allocator></div>
|
|
<div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="namespaceentt.html#a122ae54373a080574c45c77319cec7f7"> 48</a></span> constexpr <span class="keywordtype">void</span> <a class="code" href="namespaceentt.html#a122ae54373a080574c45c77319cec7f7">propagate_on_container_move_assignment</a>([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {</div>
|
|
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="keywordflow">if</span> constexpr(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {</div>
|
|
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  lhs = std::move(rhs);</div>
|
|
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  }</div>
|
|
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span> }</div>
|
|
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  </div>
|
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="keyword">template</span><<span class="keyword">typename</span> Allocator></div>
|
|
<div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="namespaceentt.html#a1359cd624e6726f884df34df66656855"> 61</a></span> constexpr <span class="keywordtype">void</span> <a class="code" href="namespaceentt.html#a1359cd624e6726f884df34df66656855">propagate_on_container_swap</a>([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs) ENTT_NOEXCEPT {</div>
|
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  ENTT_ASSERT(std::allocator_traits<Allocator>::propagate_on_container_swap::value || lhs == rhs, <span class="stringliteral">"Cannot swap the containers"</span>);</div>
|
|
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  </div>
|
|
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <span class="keywordflow">if</span> constexpr(std::allocator_traits<Allocator>::propagate_on_container_swap::value) {</div>
|
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keyword">using</span> std::swap;</div>
|
|
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <a class="code" href="namespaceentt.html#aef08fc4202f32f712bde26f55db463cb">swap</a>(lhs, rhs);</div>
|
|
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  }</div>
|
|
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span> }</div>
|
|
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  </div>
|
|
<div class="line"><a name="l00075"></a><span class="lineno"><a class="line" href="namespaceentt.html#a3755517604de1d9d3f3e0a5549c750c5"> 75</a></span> [[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>  <span class="keywordflow">return</span> value && ((value & (value - 1)) == 0);</div>
|
|
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span> }</div>
|
|
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  </div>
|
|
<div class="line"><a name="l00084"></a><span class="lineno"><a class="line" href="namespaceentt.html#a5a2dbf5d86123af800abdd8fe69542ca"> 84</a></span> [[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>  ENTT_ASSERT(value < (std::size_t{1u} << (std::numeric_limits<std::size_t>::digits - 1)), <span class="stringliteral">"Numeric limits exceeded"</span>);</div>
|
|
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  std::size_t curr = value - (value != 0u);</div>
|
|
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  </div>
|
|
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> next = 1; next < std::numeric_limits<std::size_t>::digits; next = next * 2) {</div>
|
|
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  curr |= curr >> next;</div>
|
|
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  }</div>
|
|
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  </div>
|
|
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="keywordflow">return</span> ++curr;</div>
|
|
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span> }</div>
|
|
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  </div>
|
|
<div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="namespaceentt.html#a28fe7952c2a11ebc2b47d95fb749adda"> 101</a></span> [[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>  ENTT_ASSERT(<a class="code" href="namespaceentt.html#a3755517604de1d9d3f3e0a5549c750c5">is_power_of_two</a>(mod), <span class="stringliteral">"Value must be a power of two"</span>);</div>
|
|
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">return</span> value & (mod - 1u);</div>
|
|
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span> }</div>
|
|
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  </div>
|
|
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span> } <span class="comment">// namespace entt</span></div>
|
|
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  </div>
|
|
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span> <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 &lhs, [[maybe_unused]] Allocator &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 &lhs, [[maybe_unused]] Allocator &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 &&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 &lhs, [[maybe_unused]] Allocator &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< First, Second > &lhs, compressed_pair< First, Second > &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 <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>
|