1348 lines
140 KiB
HTML
1348 lines
140 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<title>LCOV - coverage.info - libtorch/include/c10/util/Optional.h</title>
|
|
<link rel="stylesheet" type="text/css" href="../../../../gcov.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
<tr><td class="title">LCOV - code coverage report</td></tr>
|
|
<tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
|
|
<tr>
|
|
<td width="100%">
|
|
<table cellpadding=1 border=0 width="100%">
|
|
<tr>
|
|
<td width="10%" class="headerItem">Current view:</td>
|
|
<td width="10%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">libtorch/include/c10/util</a> - Optional.h<span style="font-size: 80%;"> (source / <a href="Optional.h.func-c.html">functions</a>)</span></td>
|
|
<td width="5%"></td>
|
|
<td width="5%"></td>
|
|
<td width="5%" class="headerCovTableHead">Coverage</td>
|
|
<td width="5%" class="headerCovTableHead" title="Covered + Uncovered code">Total</td>
|
|
<td width="5%" class="headerCovTableHead" title="Exercised code only">Hit</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="headerItem">Test:</td>
|
|
<td class="headerValue">coverage.info</td>
|
|
<td></td>
|
|
<td class="headerItem">Lines:</td>
|
|
<td class="headerCovTableEntryMed">89.0 %</td>
|
|
<td class="headerCovTableEntry">91</td>
|
|
<td class="headerCovTableEntry">81</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="headerItem">Test Date:</td>
|
|
<td class="headerValue">2024-04-30 13:17:26</td>
|
|
<td></td>
|
|
<td class="headerItem">Functions:</td>
|
|
<td class="headerCovTableEntryMed">76.4 %</td>
|
|
<td class="headerCovTableEntry">157</td>
|
|
<td class="headerCovTableEntry">120</td>
|
|
</tr>
|
|
<tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
</table>
|
|
|
|
<table cellpadding=0 cellspacing=0 border=0>
|
|
<tr>
|
|
<td><br></td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<pre class="sourceHeading"> Line data Source code</pre>
|
|
<pre class="source">
|
|
<span id="L1"><span class="lineNum"> 1</span> : // Copyright (C) 2011 - 2012 Andrzej Krzemienski.</span>
|
|
<span id="L2"><span class="lineNum"> 2</span> : //</span>
|
|
<span id="L3"><span class="lineNum"> 3</span> : // Use, modification, and distribution is subject to the Boost Software</span>
|
|
<span id="L4"><span class="lineNum"> 4</span> : // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
|
|
<span id="L5"><span class="lineNum"> 5</span> : // http://www.boost.org/LICENSE_1_0.txt)</span>
|
|
<span id="L6"><span class="lineNum"> 6</span> : //</span>
|
|
<span id="L7"><span class="lineNum"> 7</span> : // The idea and interface is based on Boost.Optional library</span>
|
|
<span id="L8"><span class="lineNum"> 8</span> : // authored by Fernando Luis Cacciola Carballal</span>
|
|
<span id="L9"><span class="lineNum"> 9</span> : //</span>
|
|
<span id="L10"><span class="lineNum"> 10</span> : // From https://github.com/akrzemi1/Optional</span>
|
|
<span id="L11"><span class="lineNum"> 11</span> : //</span>
|
|
<span id="L12"><span class="lineNum"> 12</span> : // C10</span>
|
|
<span id="L13"><span class="lineNum"> 13</span> : // - Move file to `c10` namespace.</span>
|
|
<span id="L14"><span class="lineNum"> 14</span> : // - Remove macro use in line 478 because the nvcc device compiler cannot handle</span>
|
|
<span id="L15"><span class="lineNum"> 15</span> : // it.</span>
|
|
<span id="L16"><span class="lineNum"> 16</span> : // - Revise constructor logic so that it is 1) consistent with c++ 17 standard</span>
|
|
<span id="L17"><span class="lineNum"> 17</span> : // documented here in (8):</span>
|
|
<span id="L18"><span class="lineNum"> 18</span> : // https://en.cppreference.com/w/cpp/utility/optional/optional, and 2) able to</span>
|
|
<span id="L19"><span class="lineNum"> 19</span> : // support initialization of optionals from convertible type U.</span>
|
|
<span id="L20"><span class="lineNum"> 20</span> : // - Remove the constructors for `optional(const T&)` and `optional(T&&)`, as</span>
|
|
<span id="L21"><span class="lineNum"> 21</span> : // they can be handled by the template<U=T> case with the default template</span>
|
|
<span id="L22"><span class="lineNum"> 22</span> : // argument.</span>
|
|
<span id="L23"><span class="lineNum"> 23</span> : // - Move `constexpr struct in_place_t {} in_place{}` to `c10/util/in_place.h`</span>
|
|
<span id="L24"><span class="lineNum"> 24</span> : // so that it can also be used in `c10/util/variant.h`.</span>
|
|
<span id="L25"><span class="lineNum"> 25</span> : // - Remove special cases for pre-c++14 compilers to make code simpler.</span>
|
|
<span id="L26"><span class="lineNum"> 26</span> : </span>
|
|
<span id="L27"><span class="lineNum"> 27</span> : #ifndef C10_UTIL_OPTIONAL_H_</span>
|
|
<span id="L28"><span class="lineNum"> 28</span> : #define C10_UTIL_OPTIONAL_H_</span>
|
|
<span id="L29"><span class="lineNum"> 29</span> : </span>
|
|
<span id="L30"><span class="lineNum"> 30</span> : #include <c10/macros/Macros.h></span>
|
|
<span id="L31"><span class="lineNum"> 31</span> : #include <c10/util/ArrayRef.h></span>
|
|
<span id="L32"><span class="lineNum"> 32</span> : #include <c10/util/in_place.h></span>
|
|
<span id="L33"><span class="lineNum"> 33</span> : </span>
|
|
<span id="L34"><span class="lineNum"> 34</span> : #include <cassert></span>
|
|
<span id="L35"><span class="lineNum"> 35</span> : #include <functional></span>
|
|
<span id="L36"><span class="lineNum"> 36</span> : #include <initializer_list></span>
|
|
<span id="L37"><span class="lineNum"> 37</span> : #include <stdexcept></span>
|
|
<span id="L38"><span class="lineNum"> 38</span> : #include <string></span>
|
|
<span id="L39"><span class="lineNum"> 39</span> : #include <type_traits></span>
|
|
<span id="L40"><span class="lineNum"> 40</span> : #include <utility></span>
|
|
<span id="L41"><span class="lineNum"> 41</span> : </span>
|
|
<span id="L42"><span class="lineNum"> 42</span> : #include <c10/util/C++17.h></span>
|
|
<span id="L43"><span class="lineNum"> 43</span> : #include <c10/util/Metaprogramming.h></span>
|
|
<span id="L44"><span class="lineNum"> 44</span> : </span>
|
|
<span id="L45"><span class="lineNum"> 45</span> : C10_CLANG_DIAGNOSTIC_PUSH()</span>
|
|
<span id="L46"><span class="lineNum"> 46</span> : #if C10_CLANG_HAS_WARNING("-Wstring-conversion")</span>
|
|
<span id="L47"><span class="lineNum"> 47</span> : C10_CLANG_DIAGNOSTIC_IGNORE("-Wstring-conversion")</span>
|
|
<span id="L48"><span class="lineNum"> 48</span> : #endif</span>
|
|
<span id="L49"><span class="lineNum"> 49</span> : #if C10_CLANG_HAS_WARNING("-Wshorten-64-to-32")</span>
|
|
<span id="L50"><span class="lineNum"> 50</span> : C10_CLANG_DIAGNOSTIC_IGNORE("-Wshorten-64-to-32")</span>
|
|
<span id="L51"><span class="lineNum"> 51</span> : #endif</span>
|
|
<span id="L52"><span class="lineNum"> 52</span> : #if C10_CLANG_HAS_WARNING("-Wimplicit-float-conversion")</span>
|
|
<span id="L53"><span class="lineNum"> 53</span> : C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-float-conversion")</span>
|
|
<span id="L54"><span class="lineNum"> 54</span> : #endif</span>
|
|
<span id="L55"><span class="lineNum"> 55</span> : #if C10_CLANG_HAS_WARNING("-Wimplicit-int-conversion")</span>
|
|
<span id="L56"><span class="lineNum"> 56</span> : C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-int-conversion")</span>
|
|
<span id="L57"><span class="lineNum"> 57</span> : #endif</span>
|
|
<span id="L58"><span class="lineNum"> 58</span> : </span>
|
|
<span id="L59"><span class="lineNum"> 59</span> : #if defined(_MSC_VER) && !defined(__clang__)</span>
|
|
<span id="L60"><span class="lineNum"> 60</span> : #pragma warning(push)</span>
|
|
<span id="L61"><span class="lineNum"> 61</span> : #pragma warning(disable : 4624) // destructor was implicitly defined as deleted</span>
|
|
<span id="L62"><span class="lineNum"> 62</span> : #endif</span>
|
|
<span id="L63"><span class="lineNum"> 63</span> : </span>
|
|
<span id="L64"><span class="lineNum"> 64</span> : #define TR2_OPTIONAL_REQUIRES(...) \</span>
|
|
<span id="L65"><span class="lineNum"> 65</span> : typename std::enable_if<__VA_ARGS__::value, bool>::type = false</span>
|
|
<span id="L66"><span class="lineNum"> 66</span> : </span>
|
|
<span id="L67"><span class="lineNum"> 67</span> : namespace c10 {</span>
|
|
<span id="L68"><span class="lineNum"> 68</span> : </span>
|
|
<span id="L69"><span class="lineNum"> 69</span> : // 20.5.4, optional for object types</span>
|
|
<span id="L70"><span class="lineNum"> 70</span> : template <class T></span>
|
|
<span id="L71"><span class="lineNum"> 71</span> : class optional;</span>
|
|
<span id="L72"><span class="lineNum"> 72</span> : </span>
|
|
<span id="L73"><span class="lineNum"> 73</span> : // 20.5.5, optional for lvalue reference types</span>
|
|
<span id="L74"><span class="lineNum"> 74</span> : template <class T></span>
|
|
<span id="L75"><span class="lineNum"> 75</span> : class optional<T&>;</span>
|
|
<span id="L76"><span class="lineNum"> 76</span> : </span>
|
|
<span id="L77"><span class="lineNum"> 77</span> : // workaround: std utility functions aren't constexpr yet</span>
|
|
<span id="L78"><span class="lineNum"> 78</span> : template <class T></span>
|
|
<span id="L79"><span class="lineNum"> 79</span> <span class="tlaGNC tlaBgGNC"> 199233304 : inline constexpr T&& constexpr_forward(</span></span>
|
|
<span id="L80"><span class="lineNum"> 80</span> : typename std::remove_reference<T>::type& t) noexcept {</span>
|
|
<span id="L81"><span class="lineNum"> 81</span> <span class="tlaGNC"> 199233304 : return static_cast<T&&>(t);</span></span>
|
|
<span id="L82"><span class="lineNum"> 82</span> : }</span>
|
|
<span id="L83"><span class="lineNum"> 83</span> : </span>
|
|
<span id="L84"><span class="lineNum"> 84</span> : template <class T></span>
|
|
<span id="L85"><span class="lineNum"> 85</span> : inline constexpr T&& constexpr_forward(</span>
|
|
<span id="L86"><span class="lineNum"> 86</span> : typename std::remove_reference<T>::type&& t) noexcept {</span>
|
|
<span id="L87"><span class="lineNum"> 87</span> : static_assert(!std::is_lvalue_reference<T>::value, "!!");</span>
|
|
<span id="L88"><span class="lineNum"> 88</span> : return static_cast<T&&>(t);</span>
|
|
<span id="L89"><span class="lineNum"> 89</span> : }</span>
|
|
<span id="L90"><span class="lineNum"> 90</span> : </span>
|
|
<span id="L91"><span class="lineNum"> 91</span> : template <class T></span>
|
|
<span id="L92"><span class="lineNum"> 92</span> <span class="tlaGNC"> 196750336 : inline constexpr typename std::remove_reference<T>::type&& constexpr_move(</span></span>
|
|
<span id="L93"><span class="lineNum"> 93</span> : T&& t) noexcept {</span>
|
|
<span id="L94"><span class="lineNum"> 94</span> <span class="tlaGNC"> 196750336 : return static_cast<typename std::remove_reference<T>::type&&>(t);</span></span>
|
|
<span id="L95"><span class="lineNum"> 95</span> : }</span>
|
|
<span id="L96"><span class="lineNum"> 96</span> : </span>
|
|
<span id="L97"><span class="lineNum"> 97</span> : #if defined NDEBUG</span>
|
|
<span id="L98"><span class="lineNum"> 98</span> : #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)</span>
|
|
<span id="L99"><span class="lineNum"> 99</span> : #else</span>
|
|
<span id="L100"><span class="lineNum"> 100</span> : #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) \</span>
|
|
<span id="L101"><span class="lineNum"> 101</span> : ((CHECK) ? (EXPR) : ([] { assert(!#CHECK); }(), (EXPR)))</span>
|
|
<span id="L102"><span class="lineNum"> 102</span> : #endif</span>
|
|
<span id="L103"><span class="lineNum"> 103</span> : </span>
|
|
<span id="L104"><span class="lineNum"> 104</span> : #if defined(__CUDA_ARCH__)</span>
|
|
<span id="L105"><span class="lineNum"> 105</span> : #define TR2_OPTIONAL_HOST_CONSTEXPR</span>
|
|
<span id="L106"><span class="lineNum"> 106</span> : #else</span>
|
|
<span id="L107"><span class="lineNum"> 107</span> : #define TR2_OPTIONAL_HOST_CONSTEXPR constexpr</span>
|
|
<span id="L108"><span class="lineNum"> 108</span> : #endif</span>
|
|
<span id="L109"><span class="lineNum"> 109</span> : </span>
|
|
<span id="L110"><span class="lineNum"> 110</span> : // Sphinx chokes on static_addressof, so exclude it from Doxygen</span>
|
|
<span id="L111"><span class="lineNum"> 111</span> : // generation. See https://github.com/sphinx-doc/sphinx/issues/7944</span>
|
|
<span id="L112"><span class="lineNum"> 112</span> : // \cond</span>
|
|
<span id="L113"><span class="lineNum"> 113</span> : </span>
|
|
<span id="L114"><span class="lineNum"> 114</span> : namespace detail_ {</span>
|
|
<span id="L115"><span class="lineNum"> 115</span> : </span>
|
|
<span id="L116"><span class="lineNum"> 116</span> : // VS doesn't handle constexpr well, so we need to skip these stuff.</span>
|
|
<span id="L117"><span class="lineNum"> 117</span> : #if (defined _MSC_VER)</span>
|
|
<span id="L118"><span class="lineNum"> 118</span> : template <typename T></span>
|
|
<span id="L119"><span class="lineNum"> 119</span> : T* static_addressof(T& ref) {</span>
|
|
<span id="L120"><span class="lineNum"> 120</span> : return std::addressof(ref);</span>
|
|
<span id="L121"><span class="lineNum"> 121</span> : }</span>
|
|
<span id="L122"><span class="lineNum"> 122</span> : #else</span>
|
|
<span id="L123"><span class="lineNum"> 123</span> : // static_addressof: a constexpr version of addressof</span>
|
|
<span id="L124"><span class="lineNum"> 124</span> : template <typename T></span>
|
|
<span id="L125"><span class="lineNum"> 125</span> : struct has_overloaded_addressof {</span>
|
|
<span id="L126"><span class="lineNum"> 126</span> : template <class X></span>
|
|
<span id="L127"><span class="lineNum"> 127</span> : constexpr static bool has_overload(...) {</span>
|
|
<span id="L128"><span class="lineNum"> 128</span> : return false;</span>
|
|
<span id="L129"><span class="lineNum"> 129</span> : }</span>
|
|
<span id="L130"><span class="lineNum"> 130</span> : </span>
|
|
<span id="L131"><span class="lineNum"> 131</span> : template <class X, size_t S = sizeof(std::declval<X&>().operator&())></span>
|
|
<span id="L132"><span class="lineNum"> 132</span> : constexpr static bool has_overload(bool) {</span>
|
|
<span id="L133"><span class="lineNum"> 133</span> : return true;</span>
|
|
<span id="L134"><span class="lineNum"> 134</span> : }</span>
|
|
<span id="L135"><span class="lineNum"> 135</span> : </span>
|
|
<span id="L136"><span class="lineNum"> 136</span> : constexpr static bool value = has_overload<T>(true);</span>
|
|
<span id="L137"><span class="lineNum"> 137</span> : };</span>
|
|
<span id="L138"><span class="lineNum"> 138</span> : </span>
|
|
<span id="L139"><span class="lineNum"> 139</span> : template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)></span>
|
|
<span id="L140"><span class="lineNum"> 140</span> : constexpr T* static_addressof(T& ref) {</span>
|
|
<span id="L141"><span class="lineNum"> 141</span> : return &ref;</span>
|
|
<span id="L142"><span class="lineNum"> 142</span> : }</span>
|
|
<span id="L143"><span class="lineNum"> 143</span> : </span>
|
|
<span id="L144"><span class="lineNum"> 144</span> : template <typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)></span>
|
|
<span id="L145"><span class="lineNum"> 145</span> : T* static_addressof(T& ref) {</span>
|
|
<span id="L146"><span class="lineNum"> 146</span> : return std::addressof(ref);</span>
|
|
<span id="L147"><span class="lineNum"> 147</span> : }</span>
|
|
<span id="L148"><span class="lineNum"> 148</span> : #endif</span>
|
|
<span id="L149"><span class="lineNum"> 149</span> : </span>
|
|
<span id="L150"><span class="lineNum"> 150</span> : // the call to convert<A>(b) has return type A and converts b to type A iff b</span>
|
|
<span id="L151"><span class="lineNum"> 151</span> : // decltype(b) is implicitly convertible to A</span>
|
|
<span id="L152"><span class="lineNum"> 152</span> : template <class U></span>
|
|
<span id="L153"><span class="lineNum"> 153</span> <span class="tlaUNC tlaBgUNC"> 0 : constexpr U convert(U v) {</span></span>
|
|
<span id="L154"><span class="lineNum"> 154</span> <span class="tlaUNC"> 0 : return v;</span></span>
|
|
<span id="L155"><span class="lineNum"> 155</span> : }</span>
|
|
<span id="L156"><span class="lineNum"> 156</span> : </span>
|
|
<span id="L157"><span class="lineNum"> 157</span> : } // namespace detail_</span>
|
|
<span id="L158"><span class="lineNum"> 158</span> : </span>
|
|
<span id="L159"><span class="lineNum"> 159</span> : // \endcond</span>
|
|
<span id="L160"><span class="lineNum"> 160</span> : </span>
|
|
<span id="L161"><span class="lineNum"> 161</span> : constexpr struct trivial_init_t {</span>
|
|
<span id="L162"><span class="lineNum"> 162</span> : } trivial_init{};</span>
|
|
<span id="L163"><span class="lineNum"> 163</span> : </span>
|
|
<span id="L164"><span class="lineNum"> 164</span> : // 20.5.7, Disengaged state indicator</span>
|
|
<span id="L165"><span class="lineNum"> 165</span> : struct nullopt_t {</span>
|
|
<span id="L166"><span class="lineNum"> 166</span> : constexpr explicit nullopt_t(int) {}</span>
|
|
<span id="L167"><span class="lineNum"> 167</span> : };</span>
|
|
<span id="L168"><span class="lineNum"> 168</span> : constexpr nullopt_t nullopt{0};</span>
|
|
<span id="L169"><span class="lineNum"> 169</span> : </span>
|
|
<span id="L170"><span class="lineNum"> 170</span> : // 20.5.8, class bad_optional_access</span>
|
|
<span id="L171"><span class="lineNum"> 171</span> : class bad_optional_access : public std::logic_error {</span>
|
|
<span id="L172"><span class="lineNum"> 172</span> : public:</span>
|
|
<span id="L173"><span class="lineNum"> 173</span> : explicit bad_optional_access(const std::string& what_arg)</span>
|
|
<span id="L174"><span class="lineNum"> 174</span> : : logic_error{what_arg} {}</span>
|
|
<span id="L175"><span class="lineNum"> 175</span> <span class="tlaUNC"> 0 : explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} {}</span></span>
|
|
<span id="L176"><span class="lineNum"> 176</span> : };</span>
|
|
<span id="L177"><span class="lineNum"> 177</span> : </span>
|
|
<span id="L178"><span class="lineNum"> 178</span> : template <class T></span>
|
|
<span id="L179"><span class="lineNum"> 179</span> : union storage_t {</span>
|
|
<span id="L180"><span class="lineNum"> 180</span> : unsigned char dummy_{};</span>
|
|
<span id="L181"><span class="lineNum"> 181</span> : T value_;</span>
|
|
<span id="L182"><span class="lineNum"> 182</span> : </span>
|
|
<span id="L183"><span class="lineNum"> 183</span> : #if __cplusplus >= 202002L</span>
|
|
<span id="L184"><span class="lineNum"> 184</span> : constexpr</span>
|
|
<span id="L185"><span class="lineNum"> 185</span> : #endif</span>
|
|
<span id="L186"><span class="lineNum"> 186</span> <span class="tlaGNC tlaBgGNC"> 216200968 : storage_t(trivial_init_t) noexcept {</span></span>
|
|
<span id="L187"><span class="lineNum"> 187</span> <span class="tlaGNC"> 216200968 : new (&dummy_) unsigned char;</span></span>
|
|
<span id="L188"><span class="lineNum"> 188</span> <span class="tlaGNC"> 216200968 : }</span></span>
|
|
<span id="L189"><span class="lineNum"> 189</span> : </span>
|
|
<span id="L190"><span class="lineNum"> 190</span> : template <class... Args></span>
|
|
<span id="L191"><span class="lineNum"> 191</span> <span class="tlaGNC"> 105308712 : constexpr storage_t(Args&&... args)</span></span>
|
|
<span id="L192"><span class="lineNum"> 192</span> <span class="tlaGNC"> 105308712 : : value_(constexpr_forward<Args>(args)...) {}</span></span>
|
|
<span id="L193"><span class="lineNum"> 193</span> : </span>
|
|
<span id="L194"><span class="lineNum"> 194</span> <span class="tlaGNC"> 321509680 : ~storage_t() {}</span></span>
|
|
<span id="L195"><span class="lineNum"> 195</span> : };</span>
|
|
<span id="L196"><span class="lineNum"> 196</span> : </span>
|
|
<span id="L197"><span class="lineNum"> 197</span> : template <class T></span>
|
|
<span id="L198"><span class="lineNum"> 198</span> : union constexpr_storage_t {</span>
|
|
<span id="L199"><span class="lineNum"> 199</span> : unsigned char dummy_;</span>
|
|
<span id="L200"><span class="lineNum"> 200</span> : T value_;</span>
|
|
<span id="L201"><span class="lineNum"> 201</span> : </span>
|
|
<span id="L202"><span class="lineNum"> 202</span> : #if __cplusplus >= 202002L</span>
|
|
<span id="L203"><span class="lineNum"> 203</span> : // C++20 lifted the requirement to initialize a union member in order to be</span>
|
|
<span id="L204"><span class="lineNum"> 204</span> : // constexpr.</span>
|
|
<span id="L205"><span class="lineNum"> 205</span> : constexpr constexpr_storage_t(trivial_init_t) noexcept {</span>
|
|
<span id="L206"><span class="lineNum"> 206</span> : new (&dummy_) unsigned char;</span>
|
|
<span id="L207"><span class="lineNum"> 207</span> : }</span>
|
|
<span id="L208"><span class="lineNum"> 208</span> : #else</span>
|
|
<span id="L209"><span class="lineNum"> 209</span> <span class="tlaGNC"> 2945770 : constexpr constexpr_storage_t(trivial_init_t) noexcept : dummy_() {}</span></span>
|
|
<span id="L210"><span class="lineNum"> 210</span> : #endif</span>
|
|
<span id="L211"><span class="lineNum"> 211</span> : </span>
|
|
<span id="L212"><span class="lineNum"> 212</span> : template <class... Args></span>
|
|
<span id="L213"><span class="lineNum"> 213</span> <span class="tlaGNC"> 92688986 : constexpr constexpr_storage_t(Args&&... args)</span></span>
|
|
<span id="L214"><span class="lineNum"> 214</span> <span class="tlaGNC"> 92688986 : : value_(constexpr_forward<Args>(args)...) {}</span></span>
|
|
<span id="L215"><span class="lineNum"> 215</span> : </span>
|
|
<span id="L216"><span class="lineNum"> 216</span> : ~constexpr_storage_t() = default;</span>
|
|
<span id="L217"><span class="lineNum"> 217</span> : };</span>
|
|
<span id="L218"><span class="lineNum"> 218</span> : </span>
|
|
<span id="L219"><span class="lineNum"> 219</span> : template <class T></span>
|
|
<span id="L220"><span class="lineNum"> 220</span> : struct optional_base {</span>
|
|
<span id="L221"><span class="lineNum"> 221</span> : bool init_;</span>
|
|
<span id="L222"><span class="lineNum"> 222</span> : storage_t<T> storage_;</span>
|
|
<span id="L223"><span class="lineNum"> 223</span> : </span>
|
|
<span id="L224"><span class="lineNum"> 224</span> <span class="tlaGNC"> 110924592 : constexpr optional_base() noexcept : init_(false), storage_(trivial_init){};</span></span>
|
|
<span id="L225"><span class="lineNum"> 225</span> : </span>
|
|
<span id="L226"><span class="lineNum"> 226</span> : explicit constexpr optional_base(const optional_base<T>& v)</span>
|
|
<span id="L227"><span class="lineNum"> 227</span> : : init_(v.init_), storage_(trivial_init) {</span>
|
|
<span id="L228"><span class="lineNum"> 228</span> : if (init_) {</span>
|
|
<span id="L229"><span class="lineNum"> 229</span> : ::new (dataptr()) T(v.storage_.value_);</span>
|
|
<span id="L230"><span class="lineNum"> 230</span> : }</span>
|
|
<span id="L231"><span class="lineNum"> 231</span> : }</span>
|
|
<span id="L232"><span class="lineNum"> 232</span> : </span>
|
|
<span id="L233"><span class="lineNum"> 233</span> <span class="tlaGNC"> 31316 : explicit constexpr optional_base(const T& v) : init_(true), storage_(v) {}</span></span>
|
|
<span id="L234"><span class="lineNum"> 234</span> : </span>
|
|
<span id="L235"><span class="lineNum"> 235</span> <span class="tlaGNC"> 105276376 : explicit constexpr optional_base(optional_base<T>&& v) noexcept(</span></span>
|
|
<span id="L236"><span class="lineNum"> 236</span> : std::is_nothrow_move_constructible<T>::value)</span>
|
|
<span id="L237"><span class="lineNum"> 237</span> <span class="tlaGNC"> 105276376 : : init_(v.init_), storage_(trivial_init) {</span></span>
|
|
<span id="L238"><span class="lineNum"> 238</span> <span class="tlaGNC"> 105276376 : if (init_) {</span></span>
|
|
<span id="L239"><span class="lineNum"> 239</span> <span class="tlaGNC"> 105276376 : ::new (dataptr()) T(std::move(v.storage_.value_));</span></span>
|
|
<span id="L240"><span class="lineNum"> 240</span> : }</span>
|
|
<span id="L241"><span class="lineNum"> 241</span> <span class="tlaGNC"> 105276376 : }</span></span>
|
|
<span id="L242"><span class="lineNum"> 242</span> : </span>
|
|
<span id="L243"><span class="lineNum"> 243</span> <span class="tlaGNC"> 105277396 : explicit constexpr optional_base(T&& v)</span></span>
|
|
<span id="L244"><span class="lineNum"> 244</span> <span class="tlaGNC"> 105277396 : : init_(true), storage_(constexpr_move(v)) {}</span></span>
|
|
<span id="L245"><span class="lineNum"> 245</span> : </span>
|
|
<span id="L246"><span class="lineNum"> 246</span> : template <class... Args></span>
|
|
<span id="L247"><span class="lineNum"> 247</span> : explicit optional_base(in_place_t, Args&&... args)</span>
|
|
<span id="L248"><span class="lineNum"> 248</span> : : init_(true), storage_(constexpr_forward<Args>(args)...) {}</span>
|
|
<span id="L249"><span class="lineNum"> 249</span> : </span>
|
|
<span id="L250"><span class="lineNum"> 250</span> : template <</span>
|
|
<span id="L251"><span class="lineNum"> 251</span> : class U,</span>
|
|
<span id="L252"><span class="lineNum"> 252</span> : class... Args,</span>
|
|
<span id="L253"><span class="lineNum"> 253</span> : TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)></span>
|
|
<span id="L254"><span class="lineNum"> 254</span> : explicit optional_base(</span>
|
|
<span id="L255"><span class="lineNum"> 255</span> : in_place_t,</span>
|
|
<span id="L256"><span class="lineNum"> 256</span> : std::initializer_list<U> il,</span>
|
|
<span id="L257"><span class="lineNum"> 257</span> : Args&&... args)</span>
|
|
<span id="L258"><span class="lineNum"> 258</span> : : init_(true), storage_(il, std::forward<Args>(args)...) {}</span>
|
|
<span id="L259"><span class="lineNum"> 259</span> : </span>
|
|
<span id="L260"><span class="lineNum"> 260</span> : optional_base& operator=(const optional_base& rhs) {</span>
|
|
<span id="L261"><span class="lineNum"> 261</span> : if (init_ && !rhs.init_) {</span>
|
|
<span id="L262"><span class="lineNum"> 262</span> : clear();</span>
|
|
<span id="L263"><span class="lineNum"> 263</span> : } else if (!init_ && rhs.init_) {</span>
|
|
<span id="L264"><span class="lineNum"> 264</span> : init_ = true;</span>
|
|
<span id="L265"><span class="lineNum"> 265</span> : ::new (dataptr()) T(rhs.storage_.value_);</span>
|
|
<span id="L266"><span class="lineNum"> 266</span> : } else if (init_ && rhs.init_) {</span>
|
|
<span id="L267"><span class="lineNum"> 267</span> : storage_.value_ = rhs.storage_.value_;</span>
|
|
<span id="L268"><span class="lineNum"> 268</span> : }</span>
|
|
<span id="L269"><span class="lineNum"> 269</span> : return *this;</span>
|
|
<span id="L270"><span class="lineNum"> 270</span> : }</span>
|
|
<span id="L271"><span class="lineNum"> 271</span> : </span>
|
|
<span id="L272"><span class="lineNum"> 272</span> : optional_base& operator=(optional_base&& rhs) noexcept(</span>
|
|
<span id="L273"><span class="lineNum"> 273</span> : std::is_nothrow_move_assignable<T>::value&&</span>
|
|
<span id="L274"><span class="lineNum"> 274</span> : std::is_nothrow_move_constructible<T>::value) {</span>
|
|
<span id="L275"><span class="lineNum"> 275</span> : if (init_ && !rhs.init_) {</span>
|
|
<span id="L276"><span class="lineNum"> 276</span> : clear();</span>
|
|
<span id="L277"><span class="lineNum"> 277</span> : } else if (!init_ && rhs.init_) {</span>
|
|
<span id="L278"><span class="lineNum"> 278</span> : init_ = true;</span>
|
|
<span id="L279"><span class="lineNum"> 279</span> : ::new (dataptr()) T(std::move(rhs.storage_.value_));</span>
|
|
<span id="L280"><span class="lineNum"> 280</span> : } else if (init_ && rhs.init_) {</span>
|
|
<span id="L281"><span class="lineNum"> 281</span> : storage_.value_ = std::move(rhs.storage_.value_);</span>
|
|
<span id="L282"><span class="lineNum"> 282</span> : }</span>
|
|
<span id="L283"><span class="lineNum"> 283</span> : return *this;</span>
|
|
<span id="L284"><span class="lineNum"> 284</span> : }</span>
|
|
<span id="L285"><span class="lineNum"> 285</span> : </span>
|
|
<span id="L286"><span class="lineNum"> 286</span> <span class="tlaGNC"> 321509680 : ~optional_base() {</span></span>
|
|
<span id="L287"><span class="lineNum"> 287</span> <span class="tlaGNC"> 321509680 : if (init_)</span></span>
|
|
<span id="L288"><span class="lineNum"> 288</span> <span class="tlaGNC"> 210585088 : storage_.value_.T::~T();</span></span>
|
|
<span id="L289"><span class="lineNum"> 289</span> <span class="tlaGNC"> 321509680 : }</span></span>
|
|
<span id="L290"><span class="lineNum"> 290</span> : </span>
|
|
<span id="L291"><span class="lineNum"> 291</span> <span class="tlaGNC"> 321479384 : constexpr bool initialized() const noexcept {</span></span>
|
|
<span id="L292"><span class="lineNum"> 292</span> <span class="tlaGNC"> 321479384 : return init_;</span></span>
|
|
<span id="L293"><span class="lineNum"> 293</span> : }</span>
|
|
<span id="L294"><span class="lineNum"> 294</span> : </span>
|
|
<span id="L295"><span class="lineNum"> 295</span> : void setInitialized(bool init) noexcept {</span>
|
|
<span id="L296"><span class="lineNum"> 296</span> : init_ = init;</span>
|
|
<span id="L297"><span class="lineNum"> 297</span> : }</span>
|
|
<span id="L298"><span class="lineNum"> 298</span> : </span>
|
|
<span id="L299"><span class="lineNum"> 299</span> : private:</span>
|
|
<span id="L300"><span class="lineNum"> 300</span> <span class="tlaGNC"> 105276376 : typename std::remove_const<T>::type* dataptr() {</span></span>
|
|
<span id="L301"><span class="lineNum"> 301</span> <span class="tlaGNC"> 105276376 : return std::addressof(storage_.value_);</span></span>
|
|
<span id="L302"><span class="lineNum"> 302</span> : }</span>
|
|
<span id="L303"><span class="lineNum"> 303</span> : </span>
|
|
<span id="L304"><span class="lineNum"> 304</span> : constexpr const T* dataptr() const {</span>
|
|
<span id="L305"><span class="lineNum"> 305</span> : return detail_::static_addressof(storage_.value_);</span>
|
|
<span id="L306"><span class="lineNum"> 306</span> : }</span>
|
|
<span id="L307"><span class="lineNum"> 307</span> : </span>
|
|
<span id="L308"><span class="lineNum"> 308</span> : void clear() noexcept {</span>
|
|
<span id="L309"><span class="lineNum"> 309</span> : if (init_) {</span>
|
|
<span id="L310"><span class="lineNum"> 310</span> : dataptr()->~T();</span>
|
|
<span id="L311"><span class="lineNum"> 311</span> : }</span>
|
|
<span id="L312"><span class="lineNum"> 312</span> : init_ = false;</span>
|
|
<span id="L313"><span class="lineNum"> 313</span> : }</span>
|
|
<span id="L314"><span class="lineNum"> 314</span> : };</span>
|
|
<span id="L315"><span class="lineNum"> 315</span> : </span>
|
|
<span id="L316"><span class="lineNum"> 316</span> : template <class T></span>
|
|
<span id="L317"><span class="lineNum"> 317</span> : struct constexpr_optional_base {</span>
|
|
<span id="L318"><span class="lineNum"> 318</span> : bool init_;</span>
|
|
<span id="L319"><span class="lineNum"> 319</span> : constexpr_storage_t<T> storage_;</span>
|
|
<span id="L320"><span class="lineNum"> 320</span> : </span>
|
|
<span id="L321"><span class="lineNum"> 321</span> : constexpr constexpr_optional_base() noexcept</span>
|
|
<span id="L322"><span class="lineNum"> 322</span> : : init_(false), storage_(trivial_init){};</span>
|
|
<span id="L323"><span class="lineNum"> 323</span> : </span>
|
|
<span id="L324"><span class="lineNum"> 324</span> : explicit constexpr constexpr_optional_base(</span>
|
|
<span id="L325"><span class="lineNum"> 325</span> : const constexpr_optional_base<T>& v)</span>
|
|
<span id="L326"><span class="lineNum"> 326</span> : : init_(v.init_), storage_(trivial_init) {</span>
|
|
<span id="L327"><span class="lineNum"> 327</span> : if (init_) {</span>
|
|
<span id="L328"><span class="lineNum"> 328</span> : ::new (dataptr()) T(v.storage_.value_);</span>
|
|
<span id="L329"><span class="lineNum"> 329</span> : }</span>
|
|
<span id="L330"><span class="lineNum"> 330</span> : }</span>
|
|
<span id="L331"><span class="lineNum"> 331</span> : </span>
|
|
<span id="L332"><span class="lineNum"> 332</span> : explicit constexpr constexpr_optional_base(</span>
|
|
<span id="L333"><span class="lineNum"> 333</span> : constexpr_optional_base<T>&&</span>
|
|
<span id="L334"><span class="lineNum"> 334</span> : v) noexcept(std::is_nothrow_move_constructible<T>::value)</span>
|
|
<span id="L335"><span class="lineNum"> 335</span> : : init_(v.init_), storage_(trivial_init) {</span>
|
|
<span id="L336"><span class="lineNum"> 336</span> : if (init_) {</span>
|
|
<span id="L337"><span class="lineNum"> 337</span> : ::new (dataptr()) T(std::move(v.storage_.value_));</span>
|
|
<span id="L338"><span class="lineNum"> 338</span> : }</span>
|
|
<span id="L339"><span class="lineNum"> 339</span> : }</span>
|
|
<span id="L340"><span class="lineNum"> 340</span> : </span>
|
|
<span id="L341"><span class="lineNum"> 341</span> : explicit constexpr constexpr_optional_base(const T& v)</span>
|
|
<span id="L342"><span class="lineNum"> 342</span> : : init_(true), storage_(v) {}</span>
|
|
<span id="L343"><span class="lineNum"> 343</span> : </span>
|
|
<span id="L344"><span class="lineNum"> 344</span> : explicit constexpr constexpr_optional_base(T&& v)</span>
|
|
<span id="L345"><span class="lineNum"> 345</span> : : init_(true), storage_(constexpr_move(v)) {}</span>
|
|
<span id="L346"><span class="lineNum"> 346</span> : </span>
|
|
<span id="L347"><span class="lineNum"> 347</span> : template <class... Args></span>
|
|
<span id="L348"><span class="lineNum"> 348</span> : explicit constexpr constexpr_optional_base(in_place_t, Args&&... args)</span>
|
|
<span id="L349"><span class="lineNum"> 349</span> : : init_(true), storage_(constexpr_forward<Args>(args)...) {}</span>
|
|
<span id="L350"><span class="lineNum"> 350</span> : </span>
|
|
<span id="L351"><span class="lineNum"> 351</span> : template <</span>
|
|
<span id="L352"><span class="lineNum"> 352</span> : class U,</span>
|
|
<span id="L353"><span class="lineNum"> 353</span> : class... Args,</span>
|
|
<span id="L354"><span class="lineNum"> 354</span> : TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)></span>
|
|
<span id="L355"><span class="lineNum"> 355</span> : constexpr explicit constexpr_optional_base(</span>
|
|
<span id="L356"><span class="lineNum"> 356</span> : in_place_t,</span>
|
|
<span id="L357"><span class="lineNum"> 357</span> : std::initializer_list<U> il,</span>
|
|
<span id="L358"><span class="lineNum"> 358</span> : Args&&... args)</span>
|
|
<span id="L359"><span class="lineNum"> 359</span> : : init_(true), storage_(il, std::forward<Args>(args)...) {}</span>
|
|
<span id="L360"><span class="lineNum"> 360</span> : </span>
|
|
<span id="L361"><span class="lineNum"> 361</span> : ~constexpr_optional_base() = default;</span>
|
|
<span id="L362"><span class="lineNum"> 362</span> : </span>
|
|
<span id="L363"><span class="lineNum"> 363</span> : constexpr_optional_base& operator=(const constexpr_optional_base& rhs) {</span>
|
|
<span id="L364"><span class="lineNum"> 364</span> : if (init_ && !rhs.init_) {</span>
|
|
<span id="L365"><span class="lineNum"> 365</span> : clear();</span>
|
|
<span id="L366"><span class="lineNum"> 366</span> : } else if (!init_ && rhs.init_) {</span>
|
|
<span id="L367"><span class="lineNum"> 367</span> : init_ = true;</span>
|
|
<span id="L368"><span class="lineNum"> 368</span> : ::new (dataptr()) T(rhs.storage_.value_);</span>
|
|
<span id="L369"><span class="lineNum"> 369</span> : } else if (init_ && rhs.init_) {</span>
|
|
<span id="L370"><span class="lineNum"> 370</span> : storage_.value_ = rhs.storage_.value_;</span>
|
|
<span id="L371"><span class="lineNum"> 371</span> : }</span>
|
|
<span id="L372"><span class="lineNum"> 372</span> : return *this;</span>
|
|
<span id="L373"><span class="lineNum"> 373</span> : }</span>
|
|
<span id="L374"><span class="lineNum"> 374</span> : </span>
|
|
<span id="L375"><span class="lineNum"> 375</span> : constexpr_optional_base& operator=(constexpr_optional_base&& rhs) noexcept(</span>
|
|
<span id="L376"><span class="lineNum"> 376</span> : std::is_nothrow_move_assignable<T>::value&&</span>
|
|
<span id="L377"><span class="lineNum"> 377</span> : std::is_nothrow_move_constructible<T>::value) {</span>
|
|
<span id="L378"><span class="lineNum"> 378</span> : if (init_ && !rhs.init_) {</span>
|
|
<span id="L379"><span class="lineNum"> 379</span> : clear();</span>
|
|
<span id="L380"><span class="lineNum"> 380</span> : } else if (!init_ && rhs.init_) {</span>
|
|
<span id="L381"><span class="lineNum"> 381</span> : init_ = true;</span>
|
|
<span id="L382"><span class="lineNum"> 382</span> : ::new (dataptr()) T(std::move(rhs.storage_.value_));</span>
|
|
<span id="L383"><span class="lineNum"> 383</span> : } else if (init_ && rhs.init_) {</span>
|
|
<span id="L384"><span class="lineNum"> 384</span> : storage_.value_ = std::move(rhs.storage_.value_);</span>
|
|
<span id="L385"><span class="lineNum"> 385</span> : }</span>
|
|
<span id="L386"><span class="lineNum"> 386</span> : return *this;</span>
|
|
<span id="L387"><span class="lineNum"> 387</span> : }</span>
|
|
<span id="L388"><span class="lineNum"> 388</span> : </span>
|
|
<span id="L389"><span class="lineNum"> 389</span> : constexpr bool initialized() const noexcept {</span>
|
|
<span id="L390"><span class="lineNum"> 390</span> : return init_;</span>
|
|
<span id="L391"><span class="lineNum"> 391</span> : }</span>
|
|
<span id="L392"><span class="lineNum"> 392</span> : void setInitialized(bool init) noexcept {</span>
|
|
<span id="L393"><span class="lineNum"> 393</span> : init_ = init;</span>
|
|
<span id="L394"><span class="lineNum"> 394</span> : }</span>
|
|
<span id="L395"><span class="lineNum"> 395</span> : </span>
|
|
<span id="L396"><span class="lineNum"> 396</span> : private:</span>
|
|
<span id="L397"><span class="lineNum"> 397</span> : typename std::remove_const<T>::type* dataptr() {</span>
|
|
<span id="L398"><span class="lineNum"> 398</span> : return std::addressof(storage_.value_);</span>
|
|
<span id="L399"><span class="lineNum"> 399</span> : }</span>
|
|
<span id="L400"><span class="lineNum"> 400</span> : </span>
|
|
<span id="L401"><span class="lineNum"> 401</span> : constexpr const T* dataptr() const {</span>
|
|
<span id="L402"><span class="lineNum"> 402</span> : return detail_::static_addressof(storage_.value_);</span>
|
|
<span id="L403"><span class="lineNum"> 403</span> : }</span>
|
|
<span id="L404"><span class="lineNum"> 404</span> : </span>
|
|
<span id="L405"><span class="lineNum"> 405</span> : void clear() noexcept {</span>
|
|
<span id="L406"><span class="lineNum"> 406</span> : init_ = false;</span>
|
|
<span id="L407"><span class="lineNum"> 407</span> : }</span>
|
|
<span id="L408"><span class="lineNum"> 408</span> : };</span>
|
|
<span id="L409"><span class="lineNum"> 409</span> : </span>
|
|
<span id="L410"><span class="lineNum"> 410</span> : // HACK: Optimization for trivially copyable types. The mainline</span>
|
|
<span id="L411"><span class="lineNum"> 411</span> : // implementation fails to have trivial copy/move operations in these</span>
|
|
<span id="L412"><span class="lineNum"> 412</span> : // cases, and we care about them, so just implement that directly.</span>
|
|
<span id="L413"><span class="lineNum"> 413</span> : template <class T></span>
|
|
<span id="L414"><span class="lineNum"> 414</span> : struct trivially_copyable_optimization_optional_base {</span>
|
|
<span id="L415"><span class="lineNum"> 415</span> : bool init_;</span>
|
|
<span id="L416"><span class="lineNum"> 416</span> : constexpr_storage_t<T> storage_;</span>
|
|
<span id="L417"><span class="lineNum"> 417</span> : </span>
|
|
<span id="L418"><span class="lineNum"> 418</span> <span class="tlaGNC"> 2945770 : constexpr trivially_copyable_optimization_optional_base() noexcept</span></span>
|
|
<span id="L419"><span class="lineNum"> 419</span> <span class="tlaGNC"> 2945770 : : init_(false), storage_(trivial_init) {}</span></span>
|
|
<span id="L420"><span class="lineNum"> 420</span> : </span>
|
|
<span id="L421"><span class="lineNum"> 421</span> <span class="tlaGNC"> 814728 : explicit constexpr trivially_copyable_optimization_optional_base(const T& v)</span></span>
|
|
<span id="L422"><span class="lineNum"> 422</span> <span class="tlaGNC"> 814728 : : init_(true), storage_(v) {}</span></span>
|
|
<span id="L423"><span class="lineNum"> 423</span> : </span>
|
|
<span id="L424"><span class="lineNum"> 424</span> <span class="tlaGNC"> 91472940 : explicit constexpr trivially_copyable_optimization_optional_base(T&& v)</span></span>
|
|
<span id="L425"><span class="lineNum"> 425</span> <span class="tlaGNC"> 91472940 : : init_(true), storage_(constexpr_move(v)) {}</span></span>
|
|
<span id="L426"><span class="lineNum"> 426</span> : </span>
|
|
<span id="L427"><span class="lineNum"> 427</span> : template <class... Args></span>
|
|
<span id="L428"><span class="lineNum"> 428</span> <span class="tlaGNC"> 401318 : explicit constexpr trivially_copyable_optimization_optional_base(</span></span>
|
|
<span id="L429"><span class="lineNum"> 429</span> : in_place_t,</span>
|
|
<span id="L430"><span class="lineNum"> 430</span> : Args&&... args)</span>
|
|
<span id="L431"><span class="lineNum"> 431</span> <span class="tlaGNC"> 401318 : : init_(true), storage_(constexpr_forward<Args>(args)...) {}</span></span>
|
|
<span id="L432"><span class="lineNum"> 432</span> : </span>
|
|
<span id="L433"><span class="lineNum"> 433</span> : template <</span>
|
|
<span id="L434"><span class="lineNum"> 434</span> : class U,</span>
|
|
<span id="L435"><span class="lineNum"> 435</span> : class... Args,</span>
|
|
<span id="L436"><span class="lineNum"> 436</span> : TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)></span>
|
|
<span id="L437"><span class="lineNum"> 437</span> : constexpr explicit trivially_copyable_optimization_optional_base(</span>
|
|
<span id="L438"><span class="lineNum"> 438</span> : in_place_t,</span>
|
|
<span id="L439"><span class="lineNum"> 439</span> : std::initializer_list<U> il,</span>
|
|
<span id="L440"><span class="lineNum"> 440</span> : Args&&... args)</span>
|
|
<span id="L441"><span class="lineNum"> 441</span> : : init_(true), storage_(il, std::forward<Args>(args)...) {}</span>
|
|
<span id="L442"><span class="lineNum"> 442</span> : </span>
|
|
<span id="L443"><span class="lineNum"> 443</span> : ~trivially_copyable_optimization_optional_base() = default;</span>
|
|
<span id="L444"><span class="lineNum"> 444</span> : </span>
|
|
<span id="L445"><span class="lineNum"> 445</span> <span class="tlaGNC"> 185760028 : constexpr bool initialized() const noexcept {</span></span>
|
|
<span id="L446"><span class="lineNum"> 446</span> <span class="tlaGNC"> 185760028 : return init_;</span></span>
|
|
<span id="L447"><span class="lineNum"> 447</span> : }</span>
|
|
<span id="L448"><span class="lineNum"> 448</span> : void setInitialized(bool init) noexcept {</span>
|
|
<span id="L449"><span class="lineNum"> 449</span> : init_ = init;</span>
|
|
<span id="L450"><span class="lineNum"> 450</span> : }</span>
|
|
<span id="L451"><span class="lineNum"> 451</span> : };</span>
|
|
<span id="L452"><span class="lineNum"> 452</span> : </span>
|
|
<span id="L453"><span class="lineNum"> 453</span> : // HACK: Optimization for ArrayRef<T>. We take advantage of an unused</span>
|
|
<span id="L454"><span class="lineNum"> 454</span> : // bit pattern in ArrayRef (inspired by Arthur O'Dwyer's</span>
|
|
<span id="L455"><span class="lineNum"> 455</span> : // tombstone_traits -- see https://youtu.be/MWBfmmg8-Yo?t=2466) to</span>
|
|
<span id="L456"><span class="lineNum"> 456</span> : // keep the size of c10::optional::ArrayRef<T> down to 16 bytes, which</span>
|
|
<span id="L457"><span class="lineNum"> 457</span> : // allows it to be passed to functions in registers instead of getting</span>
|
|
<span id="L458"><span class="lineNum"> 458</span> : // passed in memory per item 5c of the classification algorithm in</span>
|
|
<span id="L459"><span class="lineNum"> 459</span> : // section 3.2.3 of the System V ABI document</span>
|
|
<span id="L460"><span class="lineNum"> 460</span> : // (https://www.uclibc.org/docs/psABI-x86_64.pdf).</span>
|
|
<span id="L461"><span class="lineNum"> 461</span> : template <class ArrayRefT></span>
|
|
<span id="L462"><span class="lineNum"> 462</span> : class arrayref_optional_base {</span>
|
|
<span id="L463"><span class="lineNum"> 463</span> : public:</span>
|
|
<span id="L464"><span class="lineNum"> 464</span> : union storage {</span>
|
|
<span id="L465"><span class="lineNum"> 465</span> : struct raw {</span>
|
|
<span id="L466"><span class="lineNum"> 466</span> : // ArrayRef has the invariant that if Data is nullptr then</span>
|
|
<span id="L467"><span class="lineNum"> 467</span> : // Length must be zero, so this is an unused bit pattern.</span>
|
|
<span id="L468"><span class="lineNum"> 468</span> : const void* p = nullptr;</span>
|
|
<span id="L469"><span class="lineNum"> 469</span> : size_t sz = 1;</span>
|
|
<span id="L470"><span class="lineNum"> 470</span> : } uninitialized_{};</span>
|
|
<span id="L471"><span class="lineNum"> 471</span> : ArrayRefT value_;</span>
|
|
<span id="L472"><span class="lineNum"> 472</span> : </span>
|
|
<span id="L473"><span class="lineNum"> 473</span> <span class="tlaGNC"> 16480 : constexpr storage() noexcept : uninitialized_() {</span></span>
|
|
<span id="L474"><span class="lineNum"> 474</span> <span class="tlaGNC"> 16480 : setUninitialized();</span></span>
|
|
<span id="L475"><span class="lineNum"> 475</span> <span class="tlaGNC"> 16480 : }</span></span>
|
|
<span id="L476"><span class="lineNum"> 476</span> : </span>
|
|
<span id="L477"><span class="lineNum"> 477</span> <span class="tlaGNC"> 16480 : constexpr void setUninitialized() noexcept {</span></span>
|
|
<span id="L478"><span class="lineNum"> 478</span> <span class="tlaGNC"> 16480 : uninitialized_.p = nullptr;</span></span>
|
|
<span id="L479"><span class="lineNum"> 479</span> <span class="tlaGNC"> 16480 : uninitialized_.sz = 1;</span></span>
|
|
<span id="L480"><span class="lineNum"> 480</span> <span class="tlaGNC"> 16480 : }</span></span>
|
|
<span id="L481"><span class="lineNum"> 481</span> : </span>
|
|
<span id="L482"><span class="lineNum"> 482</span> : explicit constexpr storage(ArrayRefT& v) : value_(v) {}</span>
|
|
<span id="L483"><span class="lineNum"> 483</span> : </span>
|
|
<span id="L484"><span class="lineNum"> 484</span> : template <typename T></span>
|
|
<span id="L485"><span class="lineNum"> 485</span> : explicit constexpr storage(const std::initializer_list<T>& v) : value_(v) {}</span>
|
|
<span id="L486"><span class="lineNum"> 486</span> : </span>
|
|
<span id="L487"><span class="lineNum"> 487</span> : template <class... Args></span>
|
|
<span id="L488"><span class="lineNum"> 488</span> <span class="tlaGNC"> 14194 : explicit constexpr storage(Args&&... args)</span></span>
|
|
<span id="L489"><span class="lineNum"> 489</span> <span class="tlaGNC"> 14194 : : value_(constexpr_forward<Args>(args)...) {}</span></span>
|
|
<span id="L490"><span class="lineNum"> 490</span> : };</span>
|
|
<span id="L491"><span class="lineNum"> 491</span> : </span>
|
|
<span id="L492"><span class="lineNum"> 492</span> : storage storage_;</span>
|
|
<span id="L493"><span class="lineNum"> 493</span> : </span>
|
|
<span id="L494"><span class="lineNum"> 494</span> <span class="tlaGNC"> 16480 : constexpr arrayref_optional_base() noexcept = default;</span></span>
|
|
<span id="L495"><span class="lineNum"> 495</span> : </span>
|
|
<span id="L496"><span class="lineNum"> 496</span> <span class="tlaGNC"> 14194 : explicit constexpr arrayref_optional_base(const ArrayRefT& v) : storage_(v) {}</span></span>
|
|
<span id="L497"><span class="lineNum"> 497</span> : </span>
|
|
<span id="L498"><span class="lineNum"> 498</span> : template <class... Args></span>
|
|
<span id="L499"><span class="lineNum"> 499</span> : explicit constexpr arrayref_optional_base(in_place_t, Args&&... args)</span>
|
|
<span id="L500"><span class="lineNum"> 500</span> : : storage_(constexpr_forward<Args>(args)...) {}</span>
|
|
<span id="L501"><span class="lineNum"> 501</span> : </span>
|
|
<span id="L502"><span class="lineNum"> 502</span> : template <typename T></span>
|
|
<span id="L503"><span class="lineNum"> 503</span> : explicit constexpr arrayref_optional_base(</span>
|
|
<span id="L504"><span class="lineNum"> 504</span> : in_place_t,</span>
|
|
<span id="L505"><span class="lineNum"> 505</span> : const std::initializer_list<T>& v)</span>
|
|
<span id="L506"><span class="lineNum"> 506</span> : : storage_(v) {}</span>
|
|
<span id="L507"><span class="lineNum"> 507</span> : </span>
|
|
<span id="L508"><span class="lineNum"> 508</span> : constexpr bool initialized() const noexcept {</span>
|
|
<span id="L509"><span class="lineNum"> 509</span> : return storage_.uninitialized_.p != nullptr ||</span>
|
|
<span id="L510"><span class="lineNum"> 510</span> : storage_.uninitialized_.sz == 0;</span>
|
|
<span id="L511"><span class="lineNum"> 511</span> : }</span>
|
|
<span id="L512"><span class="lineNum"> 512</span> : </span>
|
|
<span id="L513"><span class="lineNum"> 513</span> : void setInitialized(bool init) noexcept {</span>
|
|
<span id="L514"><span class="lineNum"> 514</span> : if (!init) {</span>
|
|
<span id="L515"><span class="lineNum"> 515</span> : storage_.setUninitialized();</span>
|
|
<span id="L516"><span class="lineNum"> 516</span> : } else {</span>
|
|
<span id="L517"><span class="lineNum"> 517</span> : assert(initialized());</span>
|
|
<span id="L518"><span class="lineNum"> 518</span> : }</span>
|
|
<span id="L519"><span class="lineNum"> 519</span> : }</span>
|
|
<span id="L520"><span class="lineNum"> 520</span> : };</span>
|
|
<span id="L521"><span class="lineNum"> 521</span> : </span>
|
|
<span id="L522"><span class="lineNum"> 522</span> : namespace detail_ {</span>
|
|
<span id="L523"><span class="lineNum"> 523</span> : template <typename T></span>
|
|
<span id="L524"><span class="lineNum"> 524</span> : struct is_arrayref : std::false_type {};</span>
|
|
<span id="L525"><span class="lineNum"> 525</span> : </span>
|
|
<span id="L526"><span class="lineNum"> 526</span> : template <typename T></span>
|
|
<span id="L527"><span class="lineNum"> 527</span> : struct is_arrayref<c10::ArrayRef<T>> : std::true_type {};</span>
|
|
<span id="L528"><span class="lineNum"> 528</span> : } // namespace detail_</span>
|
|
<span id="L529"><span class="lineNum"> 529</span> : </span>
|
|
<span id="L530"><span class="lineNum"> 530</span> : template <class T></span>
|
|
<span id="L531"><span class="lineNum"> 531</span> : using OptionalBase = std::conditional_t<</span>
|
|
<span id="L532"><span class="lineNum"> 532</span> : detail_::is_arrayref<T>::value,</span>
|
|
<span id="L533"><span class="lineNum"> 533</span> : arrayref_optional_base<T>,</span>
|
|
<span id="L534"><span class="lineNum"> 534</span> : std::conditional_t<</span>
|
|
<span id="L535"><span class="lineNum"> 535</span> : std::is_trivially_destructible<T>::value &&</span>
|
|
<span id="L536"><span class="lineNum"> 536</span> : C10_IS_TRIVIALLY_COPYABLE(T) &&</span>
|
|
<span id="L537"><span class="lineNum"> 537</span> : // Avoid using is_trivially_copy_{constructible,assignable}</span>
|
|
<span id="L538"><span class="lineNum"> 538</span> : // because old GCC versions don't support them. Also,</span>
|
|
<span id="L539"><span class="lineNum"> 539</span> : // is_trivially_copyable seems not to do what I expect, so check</span>
|
|
<span id="L540"><span class="lineNum"> 540</span> : // trivially_copyable_optimization_optional_base directly.</span>
|
|
<span id="L541"><span class="lineNum"> 541</span> : std::is_copy_constructible<</span>
|
|
<span id="L542"><span class="lineNum"> 542</span> : trivially_copyable_optimization_optional_base<T>>::value &&</span>
|
|
<span id="L543"><span class="lineNum"> 543</span> : std::is_copy_assignable<</span>
|
|
<span id="L544"><span class="lineNum"> 544</span> : trivially_copyable_optimization_optional_base<T>>::value,</span>
|
|
<span id="L545"><span class="lineNum"> 545</span> : trivially_copyable_optimization_optional_base<T>,</span>
|
|
<span id="L546"><span class="lineNum"> 546</span> : std::conditional_t<</span>
|
|
<span id="L547"><span class="lineNum"> 547</span> : std::is_trivially_destructible<T>::value, // if possible</span>
|
|
<span id="L548"><span class="lineNum"> 548</span> : constexpr_optional_base<std::remove_const_t<T>>, // use base with</span>
|
|
<span id="L549"><span class="lineNum"> 549</span> : // trivial</span>
|
|
<span id="L550"><span class="lineNum"> 550</span> : // destructor</span>
|
|
<span id="L551"><span class="lineNum"> 551</span> : optional_base<std::remove_const_t<T>>>>>;</span>
|
|
<span id="L552"><span class="lineNum"> 552</span> : </span>
|
|
<span id="L553"><span class="lineNum"> 553</span> : template <class T></span>
|
|
<span id="L554"><span class="lineNum"> 554</span> : class optional : private OptionalBase<T> {</span>
|
|
<span id="L555"><span class="lineNum"> 555</span> : template <class U> // re-declaration for nvcc on Windows.</span>
|
|
<span id="L556"><span class="lineNum"> 556</span> : using OptionalBase = std::conditional_t<</span>
|
|
<span id="L557"><span class="lineNum"> 557</span> : detail_::is_arrayref<U>::value,</span>
|
|
<span id="L558"><span class="lineNum"> 558</span> : arrayref_optional_base<U>,</span>
|
|
<span id="L559"><span class="lineNum"> 559</span> : std::conditional_t<</span>
|
|
<span id="L560"><span class="lineNum"> 560</span> : std::is_trivially_destructible<U>::value &&</span>
|
|
<span id="L561"><span class="lineNum"> 561</span> : C10_IS_TRIVIALLY_COPYABLE(U) &&</span>
|
|
<span id="L562"><span class="lineNum"> 562</span> : // Avoid using is_trivially_copy_{constructible,assignable}</span>
|
|
<span id="L563"><span class="lineNum"> 563</span> : // because old GCC versions don't support them. Also,</span>
|
|
<span id="L564"><span class="lineNum"> 564</span> : // is_trivially_copyable seems not to do what I expect, so</span>
|
|
<span id="L565"><span class="lineNum"> 565</span> : // check trivially_copyable_optimization_optional_base</span>
|
|
<span id="L566"><span class="lineNum"> 566</span> : // directly.</span>
|
|
<span id="L567"><span class="lineNum"> 567</span> : std::is_copy_constructible<</span>
|
|
<span id="L568"><span class="lineNum"> 568</span> : trivially_copyable_optimization_optional_base<U>>::value &&</span>
|
|
<span id="L569"><span class="lineNum"> 569</span> : std::is_copy_assignable<</span>
|
|
<span id="L570"><span class="lineNum"> 570</span> : trivially_copyable_optimization_optional_base<U>>::value,</span>
|
|
<span id="L571"><span class="lineNum"> 571</span> : trivially_copyable_optimization_optional_base<U>,</span>
|
|
<span id="L572"><span class="lineNum"> 572</span> : std::conditional_t<</span>
|
|
<span id="L573"><span class="lineNum"> 573</span> : std::is_trivially_destructible<U>::value, // if possible</span>
|
|
<span id="L574"><span class="lineNum"> 574</span> : constexpr_optional_base<std::remove_const_t<U>>, // use base</span>
|
|
<span id="L575"><span class="lineNum"> 575</span> : // with</span>
|
|
<span id="L576"><span class="lineNum"> 576</span> : // trivial</span>
|
|
<span id="L577"><span class="lineNum"> 577</span> : // destructor</span>
|
|
<span id="L578"><span class="lineNum"> 578</span> : optional_base<std::remove_const_t<U>>>>>;</span>
|
|
<span id="L579"><span class="lineNum"> 579</span> : </span>
|
|
<span id="L580"><span class="lineNum"> 580</span> : static_assert(</span>
|
|
<span id="L581"><span class="lineNum"> 581</span> : !std::is_same<typename std::decay<T>::type, nullopt_t>::value,</span>
|
|
<span id="L582"><span class="lineNum"> 582</span> : "bad T");</span>
|
|
<span id="L583"><span class="lineNum"> 583</span> : static_assert(</span>
|
|
<span id="L584"><span class="lineNum"> 584</span> : !std::is_same<typename std::decay<T>::type, in_place_t>::value,</span>
|
|
<span id="L585"><span class="lineNum"> 585</span> : "bad T");</span>
|
|
<span id="L586"><span class="lineNum"> 586</span> : </span>
|
|
<span id="L587"><span class="lineNum"> 587</span> <span class="tlaGNC"> 507239412 : constexpr bool initialized() const noexcept {</span></span>
|
|
<span id="L588"><span class="lineNum"> 588</span> <span class="tlaGNC"> 507239412 : return OptionalBase<T>::initialized();</span></span>
|
|
<span id="L589"><span class="lineNum"> 589</span> : }</span>
|
|
<span id="L590"><span class="lineNum"> 590</span> <span class="tlaGNC"> 418776 : typename std::remove_const<T>::type* dataptr() {</span></span>
|
|
<span id="L591"><span class="lineNum"> 591</span> <span class="tlaGNC"> 418776 : return std::addressof(OptionalBase<T>::storage_.value_);</span></span>
|
|
<span id="L592"><span class="lineNum"> 592</span> : }</span>
|
|
<span id="L593"><span class="lineNum"> 593</span> : constexpr const T* dataptr() const {</span>
|
|
<span id="L594"><span class="lineNum"> 594</span> : return detail_::static_addressof(OptionalBase<T>::storage_.value_);</span>
|
|
<span id="L595"><span class="lineNum"> 595</span> : }</span>
|
|
<span id="L596"><span class="lineNum"> 596</span> : </span>
|
|
<span id="L597"><span class="lineNum"> 597</span> <span class="tlaUNC tlaBgUNC"> 0 : constexpr const T& contained_val() const& {</span></span>
|
|
<span id="L598"><span class="lineNum"> 598</span> <span class="tlaUNC"> 0 : return OptionalBase<T>::storage_.value_;</span></span>
|
|
<span id="L599"><span class="lineNum"> 599</span> : }</span>
|
|
<span id="L600"><span class="lineNum"> 600</span> : constexpr T&& contained_val() && {</span>
|
|
<span id="L601"><span class="lineNum"> 601</span> : return std::move(OptionalBase<T>::storage_.value_);</span>
|
|
<span id="L602"><span class="lineNum"> 602</span> : }</span>
|
|
<span id="L603"><span class="lineNum"> 603</span> <span class="tlaGNC tlaBgGNC"> 197127776 : constexpr T& contained_val() & {</span></span>
|
|
<span id="L604"><span class="lineNum"> 604</span> <span class="tlaGNC"> 197127776 : return OptionalBase<T>::storage_.value_;</span></span>
|
|
<span id="L605"><span class="lineNum"> 605</span> : }</span>
|
|
<span id="L606"><span class="lineNum"> 606</span> : </span>
|
|
<span id="L607"><span class="lineNum"> 607</span> : void clear() noexcept {</span>
|
|
<span id="L608"><span class="lineNum"> 608</span> : if (initialized())</span>
|
|
<span id="L609"><span class="lineNum"> 609</span> : dataptr()->~T();</span>
|
|
<span id="L610"><span class="lineNum"> 610</span> : OptionalBase<T>::setInitialized(false);</span>
|
|
<span id="L611"><span class="lineNum"> 611</span> : }</span>
|
|
<span id="L612"><span class="lineNum"> 612</span> : </span>
|
|
<span id="L613"><span class="lineNum"> 613</span> : template <class... Args></span>
|
|
<span id="L614"><span class="lineNum"> 614</span> : void initialize(Args&&... args) noexcept(</span>
|
|
<span id="L615"><span class="lineNum"> 615</span> : noexcept(T(std::forward<Args>(args)...))) {</span>
|
|
<span id="L616"><span class="lineNum"> 616</span> : assert(!initialized());</span>
|
|
<span id="L617"><span class="lineNum"> 617</span> : ::new (static_cast<void*>(dataptr())) T(std::forward<Args>(args)...);</span>
|
|
<span id="L618"><span class="lineNum"> 618</span> : OptionalBase<T>::setInitialized(true);</span>
|
|
<span id="L619"><span class="lineNum"> 619</span> : }</span>
|
|
<span id="L620"><span class="lineNum"> 620</span> : </span>
|
|
<span id="L621"><span class="lineNum"> 621</span> : template <class U, class... Args></span>
|
|
<span id="L622"><span class="lineNum"> 622</span> : void initialize(std::initializer_list<U> il, Args&&... args) noexcept(</span>
|
|
<span id="L623"><span class="lineNum"> 623</span> : noexcept(T(il, std::forward<Args>(args)...))) {</span>
|
|
<span id="L624"><span class="lineNum"> 624</span> : assert(!initialized());</span>
|
|
<span id="L625"><span class="lineNum"> 625</span> : ::new (static_cast<void*>(dataptr())) T(il, std::forward<Args>(args)...);</span>
|
|
<span id="L626"><span class="lineNum"> 626</span> : OptionalBase<T>::setInitialized(true);</span>
|
|
<span id="L627"><span class="lineNum"> 627</span> : }</span>
|
|
<span id="L628"><span class="lineNum"> 628</span> : </span>
|
|
<span id="L629"><span class="lineNum"> 629</span> : public:</span>
|
|
<span id="L630"><span class="lineNum"> 630</span> : typedef T value_type;</span>
|
|
<span id="L631"><span class="lineNum"> 631</span> : </span>
|
|
<span id="L632"><span class="lineNum"> 632</span> : // 20.5.5.1, constructors</span>
|
|
<span id="L633"><span class="lineNum"> 633</span> <span class="tlaGNC"> 16480 : constexpr optional() noexcept = default;</span></span>
|
|
<span id="L634"><span class="lineNum"> 634</span> <span class="tlaGNC"> 113870362 : constexpr optional(nullopt_t) noexcept : OptionalBase<T>(){};</span></span>
|
|
<span id="L635"><span class="lineNum"> 635</span> : </span>
|
|
<span id="L636"><span class="lineNum"> 636</span> : optional(const optional& rhs) = default;</span>
|
|
<span id="L637"><span class="lineNum"> 637</span> <span class="tlaGNC"> 105276376 : optional(optional&& rhs) = default;</span></span>
|
|
<span id="L638"><span class="lineNum"> 638</span> : </span>
|
|
<span id="L639"><span class="lineNum"> 639</span> : // see https://github.com/akrzemi1/Optional/issues/16</span>
|
|
<span id="L640"><span class="lineNum"> 640</span> : // and https://en.cppreference.com/w/cpp/utility/optional/optional,</span>
|
|
<span id="L641"><span class="lineNum"> 641</span> : // in constructor 8, the std::optional spec can allow initialization</span>
|
|
<span id="L642"><span class="lineNum"> 642</span> : // of optionals from convertible type U</span>
|
|
<span id="L643"><span class="lineNum"> 643</span> : //</span>
|
|
<span id="L644"><span class="lineNum"> 644</span> : // 8 - implicit move construct from value</span>
|
|
<span id="L645"><span class="lineNum"> 645</span> : template <</span>
|
|
<span id="L646"><span class="lineNum"> 646</span> : typename U = T,</span>
|
|
<span id="L647"><span class="lineNum"> 647</span> : TR2_OPTIONAL_REQUIRES(</span>
|
|
<span id="L648"><span class="lineNum"> 648</span> : std::is_constructible<T, U&&>::value &&</span>
|
|
<span id="L649"><span class="lineNum"> 649</span> : !std::is_same<typename std::decay<U>::type, in_place_t>::value &&</span>
|
|
<span id="L650"><span class="lineNum"> 650</span> : !std::is_same<typename std::decay<U>::type, optional<T>>::value &&</span>
|
|
<span id="L651"><span class="lineNum"> 651</span> : std::is_convertible<U&&, T>)></span>
|
|
<span id="L652"><span class="lineNum"> 652</span> <span class="tlaGNC"> 197610574 : constexpr optional(U&& u) : OptionalBase<T>(std::forward<U>(u)) {}</span></span>
|
|
<span id="L653"><span class="lineNum"> 653</span> : </span>
|
|
<span id="L654"><span class="lineNum"> 654</span> : // 8 - explicit move construct from value</span>
|
|
<span id="L655"><span class="lineNum"> 655</span> : template <</span>
|
|
<span id="L656"><span class="lineNum"> 656</span> : typename U = T,</span>
|
|
<span id="L657"><span class="lineNum"> 657</span> : TR2_OPTIONAL_REQUIRES(</span>
|
|
<span id="L658"><span class="lineNum"> 658</span> : std::is_constructible<T, U&&>::value &&</span>
|
|
<span id="L659"><span class="lineNum"> 659</span> : !std::is_same<typename std::decay<U>::type, in_place_t>::value &&</span>
|
|
<span id="L660"><span class="lineNum"> 660</span> : !std::is_same<typename std::decay<U>::type, optional<T>>::value &&</span>
|
|
<span id="L661"><span class="lineNum"> 661</span> : !std::is_convertible<U&&, T>)></span>
|
|
<span id="L662"><span class="lineNum"> 662</span> : explicit constexpr optional(U&& u) : OptionalBase<T>(std::forward<U>(u)) {}</span>
|
|
<span id="L663"><span class="lineNum"> 663</span> : </span>
|
|
<span id="L664"><span class="lineNum"> 664</span> : template <class... Args></span>
|
|
<span id="L665"><span class="lineNum"> 665</span> <span class="tlaGNC"> 401318 : explicit constexpr optional(in_place_t, Args&&... args)</span></span>
|
|
<span id="L666"><span class="lineNum"> 666</span> <span class="tlaGNC"> 401318 : : OptionalBase<T>(in_place_t{}, constexpr_forward<Args>(args)...) {}</span></span>
|
|
<span id="L667"><span class="lineNum"> 667</span> : </span>
|
|
<span id="L668"><span class="lineNum"> 668</span> : template <</span>
|
|
<span id="L669"><span class="lineNum"> 669</span> : class U,</span>
|
|
<span id="L670"><span class="lineNum"> 670</span> : class... Args,</span>
|
|
<span id="L671"><span class="lineNum"> 671</span> : TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)></span>
|
|
<span id="L672"><span class="lineNum"> 672</span> : constexpr explicit optional(</span>
|
|
<span id="L673"><span class="lineNum"> 673</span> : in_place_t,</span>
|
|
<span id="L674"><span class="lineNum"> 674</span> : std::initializer_list<U> il,</span>
|
|
<span id="L675"><span class="lineNum"> 675</span> : Args&&... args)</span>
|
|
<span id="L676"><span class="lineNum"> 676</span> : : OptionalBase<T>(in_place_t{}, il, constexpr_forward<Args>(args)...) {}</span>
|
|
<span id="L677"><span class="lineNum"> 677</span> : </span>
|
|
<span id="L678"><span class="lineNum"> 678</span> : // 20.5.4.2, Destructor</span>
|
|
<span id="L679"><span class="lineNum"> 679</span> <span class="tlaGNC"> 321509680 : ~optional() = default;</span></span>
|
|
<span id="L680"><span class="lineNum"> 680</span> : </span>
|
|
<span id="L681"><span class="lineNum"> 681</span> : // 20.5.4.3, assignment</span>
|
|
<span id="L682"><span class="lineNum"> 682</span> : optional& operator=(nullopt_t) noexcept {</span>
|
|
<span id="L683"><span class="lineNum"> 683</span> : clear();</span>
|
|
<span id="L684"><span class="lineNum"> 684</span> : return *this;</span>
|
|
<span id="L685"><span class="lineNum"> 685</span> : }</span>
|
|
<span id="L686"><span class="lineNum"> 686</span> : </span>
|
|
<span id="L687"><span class="lineNum"> 687</span> : optional& operator=(const optional& rhs) = default;</span>
|
|
<span id="L688"><span class="lineNum"> 688</span> : </span>
|
|
<span id="L689"><span class="lineNum"> 689</span> : optional& operator=(optional&& rhs) = default;</span>
|
|
<span id="L690"><span class="lineNum"> 690</span> : </span>
|
|
<span id="L691"><span class="lineNum"> 691</span> : template <class U = T></span>
|
|
<span id="L692"><span class="lineNum"> 692</span> : auto operator=(U&& v) -> typename std::enable_if<</span>
|
|
<span id="L693"><span class="lineNum"> 693</span> : std::is_constructible<T, U>::value &&</span>
|
|
<span id="L694"><span class="lineNum"> 694</span> : !std::is_same<typename std::decay<U>::type, optional<T>>::value &&</span>
|
|
<span id="L695"><span class="lineNum"> 695</span> : (std::is_scalar<T>::value ||</span>
|
|
<span id="L696"><span class="lineNum"> 696</span> : std::is_same<typename std::decay<U>::type, T>::value) &&</span>
|
|
<span id="L697"><span class="lineNum"> 697</span> : std::is_assignable<T&, U>::value,</span>
|
|
<span id="L698"><span class="lineNum"> 698</span> : optional&>::type {</span>
|
|
<span id="L699"><span class="lineNum"> 699</span> : if (initialized()) {</span>
|
|
<span id="L700"><span class="lineNum"> 700</span> : contained_val() = std::forward<U>(v);</span>
|
|
<span id="L701"><span class="lineNum"> 701</span> : } else {</span>
|
|
<span id="L702"><span class="lineNum"> 702</span> : initialize(std::forward<U>(v));</span>
|
|
<span id="L703"><span class="lineNum"> 703</span> : }</span>
|
|
<span id="L704"><span class="lineNum"> 704</span> : return *this;</span>
|
|
<span id="L705"><span class="lineNum"> 705</span> : }</span>
|
|
<span id="L706"><span class="lineNum"> 706</span> : </span>
|
|
<span id="L707"><span class="lineNum"> 707</span> : template <class... Args></span>
|
|
<span id="L708"><span class="lineNum"> 708</span> : void emplace(Args&&... args) {</span>
|
|
<span id="L709"><span class="lineNum"> 709</span> : clear();</span>
|
|
<span id="L710"><span class="lineNum"> 710</span> : initialize(std::forward<Args>(args)...);</span>
|
|
<span id="L711"><span class="lineNum"> 711</span> : }</span>
|
|
<span id="L712"><span class="lineNum"> 712</span> : </span>
|
|
<span id="L713"><span class="lineNum"> 713</span> : template <class U, class... Args></span>
|
|
<span id="L714"><span class="lineNum"> 714</span> : void emplace(std::initializer_list<U> il, Args&&... args) {</span>
|
|
<span id="L715"><span class="lineNum"> 715</span> : clear();</span>
|
|
<span id="L716"><span class="lineNum"> 716</span> : initialize<U, Args...>(il, std::forward<Args>(args)...);</span>
|
|
<span id="L717"><span class="lineNum"> 717</span> : }</span>
|
|
<span id="L718"><span class="lineNum"> 718</span> : </span>
|
|
<span id="L719"><span class="lineNum"> 719</span> : // 20.5.4.4, Swap</span>
|
|
<span id="L720"><span class="lineNum"> 720</span> : void swap(optional<T>& rhs) noexcept(</span>
|
|
<span id="L721"><span class="lineNum"> 721</span> : std::is_nothrow_move_constructible<T>::value&& noexcept(</span>
|
|
<span id="L722"><span class="lineNum"> 722</span> : std::swap(std::declval<T&>(), std::declval<T&>()))) {</span>
|
|
<span id="L723"><span class="lineNum"> 723</span> : if (initialized() == true && rhs.initialized() == false) {</span>
|
|
<span id="L724"><span class="lineNum"> 724</span> : rhs.initialize(std::move(**this));</span>
|
|
<span id="L725"><span class="lineNum"> 725</span> : clear();</span>
|
|
<span id="L726"><span class="lineNum"> 726</span> : } else if (initialized() == false && rhs.initialized() == true) {</span>
|
|
<span id="L727"><span class="lineNum"> 727</span> : initialize(std::move(*rhs));</span>
|
|
<span id="L728"><span class="lineNum"> 728</span> : rhs.clear();</span>
|
|
<span id="L729"><span class="lineNum"> 729</span> : } else if (initialized() == true && rhs.initialized() == true) {</span>
|
|
<span id="L730"><span class="lineNum"> 730</span> : using std::swap;</span>
|
|
<span id="L731"><span class="lineNum"> 731</span> : swap(**this, *rhs);</span>
|
|
<span id="L732"><span class="lineNum"> 732</span> : }</span>
|
|
<span id="L733"><span class="lineNum"> 733</span> : }</span>
|
|
<span id="L734"><span class="lineNum"> 734</span> : </span>
|
|
<span id="L735"><span class="lineNum"> 735</span> : // 20.5.4.5, Observers</span>
|
|
<span id="L736"><span class="lineNum"> 736</span> : </span>
|
|
<span id="L737"><span class="lineNum"> 737</span> <span class="tlaGNC"> 92670626 : explicit constexpr operator bool() const noexcept {</span></span>
|
|
<span id="L738"><span class="lineNum"> 738</span> <span class="tlaGNC"> 92670626 : return initialized();</span></span>
|
|
<span id="L739"><span class="lineNum"> 739</span> : }</span>
|
|
<span id="L740"><span class="lineNum"> 740</span> <span class="tlaGNC"> 217022234 : constexpr bool has_value() const noexcept {</span></span>
|
|
<span id="L741"><span class="lineNum"> 741</span> <span class="tlaGNC"> 217022234 : return initialized();</span></span>
|
|
<span id="L742"><span class="lineNum"> 742</span> : }</span>
|
|
<span id="L743"><span class="lineNum"> 743</span> : </span>
|
|
<span id="L744"><span class="lineNum"> 744</span> : TR2_OPTIONAL_HOST_CONSTEXPR T const* operator->() const {</span>
|
|
<span id="L745"><span class="lineNum"> 745</span> : return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr());</span>
|
|
<span id="L746"><span class="lineNum"> 746</span> : }</span>
|
|
<span id="L747"><span class="lineNum"> 747</span> : </span>
|
|
<span id="L748"><span class="lineNum"> 748</span> <span class="tlaGNC"> 418776 : TR2_OPTIONAL_HOST_CONSTEXPR T* operator->() {</span></span>
|
|
<span id="L749"><span class="lineNum"> 749</span> <span class="tlaGNC"> 418776 : assert(initialized());</span></span>
|
|
<span id="L750"><span class="lineNum"> 750</span> <span class="tlaGNC"> 418776 : return dataptr();</span></span>
|
|
<span id="L751"><span class="lineNum"> 751</span> : }</span>
|
|
<span id="L752"><span class="lineNum"> 752</span> : </span>
|
|
<span id="L753"><span class="lineNum"> 753</span> <span class="tlaUNC tlaBgUNC"> 0 : TR2_OPTIONAL_HOST_CONSTEXPR T const& operator*() const& {</span></span>
|
|
<span id="L754"><span class="lineNum"> 754</span> <span class="tlaUNC"> 0 : return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());</span></span>
|
|
<span id="L755"><span class="lineNum"> 755</span> : }</span>
|
|
<span id="L756"><span class="lineNum"> 756</span> : </span>
|
|
<span id="L757"><span class="lineNum"> 757</span> <span class="tlaGNC tlaBgGNC"> 197126756 : TR2_OPTIONAL_HOST_CONSTEXPR T& operator*() & {</span></span>
|
|
<span id="L758"><span class="lineNum"> 758</span> <span class="tlaGNC"> 197126756 : assert(initialized());</span></span>
|
|
<span id="L759"><span class="lineNum"> 759</span> <span class="tlaGNC"> 197126756 : return contained_val();</span></span>
|
|
<span id="L760"><span class="lineNum"> 760</span> : }</span>
|
|
<span id="L761"><span class="lineNum"> 761</span> : </span>
|
|
<span id="L762"><span class="lineNum"> 762</span> : TR2_OPTIONAL_HOST_CONSTEXPR T&& operator*() && {</span>
|
|
<span id="L763"><span class="lineNum"> 763</span> : assert(initialized());</span>
|
|
<span id="L764"><span class="lineNum"> 764</span> : return constexpr_move(contained_val());</span>
|
|
<span id="L765"><span class="lineNum"> 765</span> : }</span>
|
|
<span id="L766"><span class="lineNum"> 766</span> : </span>
|
|
<span id="L767"><span class="lineNum"> 767</span> : TR2_OPTIONAL_HOST_CONSTEXPR T const& value() const& {</span>
|
|
<span id="L768"><span class="lineNum"> 768</span> : return initialized()</span>
|
|
<span id="L769"><span class="lineNum"> 769</span> : ? contained_val()</span>
|
|
<span id="L770"><span class="lineNum"> 770</span> : : (throw bad_optional_access("bad optional access"), contained_val());</span>
|
|
<span id="L771"><span class="lineNum"> 771</span> : }</span>
|
|
<span id="L772"><span class="lineNum"> 772</span> : </span>
|
|
<span id="L773"><span class="lineNum"> 773</span> : TR2_OPTIONAL_HOST_CONSTEXPR T& value() & {</span>
|
|
<span id="L774"><span class="lineNum"> 774</span> : return initialized()</span>
|
|
<span id="L775"><span class="lineNum"> 775</span> : ? contained_val()</span>
|
|
<span id="L776"><span class="lineNum"> 776</span> : : (throw bad_optional_access("bad optional access"), contained_val());</span>
|
|
<span id="L777"><span class="lineNum"> 777</span> : }</span>
|
|
<span id="L778"><span class="lineNum"> 778</span> : </span>
|
|
<span id="L779"><span class="lineNum"> 779</span> <span class="tlaGNC"> 1020 : TR2_OPTIONAL_HOST_CONSTEXPR T&& value() && {</span></span>
|
|
<span id="L780"><span class="lineNum"> 780</span> <span class="tlaGNC"> 1020 : if (!initialized())</span></span>
|
|
<span id="L781"><span class="lineNum"> 781</span> <span class="tlaUNC tlaBgUNC"> 0 : throw bad_optional_access("bad optional access");</span></span>
|
|
<span id="L782"><span class="lineNum"> 782</span> <span class="tlaGNC tlaBgGNC"> 1020 : return std::move(contained_val());</span></span>
|
|
<span id="L783"><span class="lineNum"> 783</span> : }</span>
|
|
<span id="L784"><span class="lineNum"> 784</span> : </span>
|
|
<span id="L785"><span class="lineNum"> 785</span> : template <class V></span>
|
|
<span id="L786"><span class="lineNum"> 786</span> : constexpr T value_or(V&& v) const& {</span>
|
|
<span id="L787"><span class="lineNum"> 787</span> : return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));</span>
|
|
<span id="L788"><span class="lineNum"> 788</span> : }</span>
|
|
<span id="L789"><span class="lineNum"> 789</span> : </span>
|
|
<span id="L790"><span class="lineNum"> 790</span> : template <class V></span>
|
|
<span id="L791"><span class="lineNum"> 791</span> : constexpr T value_or(V&& v) && {</span>
|
|
<span id="L792"><span class="lineNum"> 792</span> : return *this</span>
|
|
<span id="L793"><span class="lineNum"> 793</span> : ? constexpr_move(const_cast<optional<T>&>(*this).contained_val())</span>
|
|
<span id="L794"><span class="lineNum"> 794</span> : : detail_::convert<T>(constexpr_forward<V>(v));</span>
|
|
<span id="L795"><span class="lineNum"> 795</span> : }</span>
|
|
<span id="L796"><span class="lineNum"> 796</span> : </span>
|
|
<span id="L797"><span class="lineNum"> 797</span> : // 20.6.3.6, modifiers</span>
|
|
<span id="L798"><span class="lineNum"> 798</span> : void reset() noexcept {</span>
|
|
<span id="L799"><span class="lineNum"> 799</span> : clear();</span>
|
|
<span id="L800"><span class="lineNum"> 800</span> : }</span>
|
|
<span id="L801"><span class="lineNum"> 801</span> : };</span>
|
|
<span id="L802"><span class="lineNum"> 802</span> : </span>
|
|
<span id="L803"><span class="lineNum"> 803</span> : template <class T, class F></span>
|
|
<span id="L804"><span class="lineNum"> 804</span> <span class="tlaUNC tlaBgUNC"> 0 : constexpr T value_or_else(const optional<T>& v, F&& func) {</span></span>
|
|
<span id="L805"><span class="lineNum"> 805</span> : static_assert(</span>
|
|
<span id="L806"><span class="lineNum"> 806</span> : std::is_convertible<</span>
|
|
<span id="L807"><span class="lineNum"> 807</span> : typename guts::infer_function_traits_t<F>::return_type,</span>
|
|
<span id="L808"><span class="lineNum"> 808</span> : T>::value,</span>
|
|
<span id="L809"><span class="lineNum"> 809</span> : "func parameters must be a callable that returns a type convertible to the value stored in the optional");</span>
|
|
<span id="L810"><span class="lineNum"> 810</span> <span class="tlaUNC"> 0 : return v.has_value() ? *v : detail_::convert<T>(std::forward<F>(func)());</span></span>
|
|
<span id="L811"><span class="lineNum"> 811</span> : }</span>
|
|
<span id="L812"><span class="lineNum"> 812</span> : </span>
|
|
<span id="L813"><span class="lineNum"> 813</span> : template <class T, class F></span>
|
|
<span id="L814"><span class="lineNum"> 814</span> : constexpr T value_or_else(optional<T>&& v, F&& func) {</span>
|
|
<span id="L815"><span class="lineNum"> 815</span> : static_assert(</span>
|
|
<span id="L816"><span class="lineNum"> 816</span> : std::is_convertible<</span>
|
|
<span id="L817"><span class="lineNum"> 817</span> : typename guts::infer_function_traits_t<F>::return_type,</span>
|
|
<span id="L818"><span class="lineNum"> 818</span> : T>::value,</span>
|
|
<span id="L819"><span class="lineNum"> 819</span> : "func parameters must be a callable that returns a type convertible to the value stored in the optional");</span>
|
|
<span id="L820"><span class="lineNum"> 820</span> : return v.has_value() ? constexpr_move(std::move(v).contained_val())</span>
|
|
<span id="L821"><span class="lineNum"> 821</span> : : detail_::convert<T>(std::forward<F>(func)());</span>
|
|
<span id="L822"><span class="lineNum"> 822</span> : }</span>
|
|
<span id="L823"><span class="lineNum"> 823</span> : </span>
|
|
<span id="L824"><span class="lineNum"> 824</span> : // XXX: please refrain from using optional<T&>, since it is being against with</span>
|
|
<span id="L825"><span class="lineNum"> 825</span> : // the optional standard in c++ 17, see the debate and the details here:</span>
|
|
<span id="L826"><span class="lineNum"> 826</span> : // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3406#rationale.refs</span>
|
|
<span id="L827"><span class="lineNum"> 827</span> : // if you need it, consider using optional<std::reference_wrapper<T>> or *</span>
|
|
<span id="L828"><span class="lineNum"> 828</span> : // pointer</span>
|
|
<span id="L829"><span class="lineNum"> 829</span> : //</span>
|
|
<span id="L830"><span class="lineNum"> 830</span> : // we leave the implementation here in case we want to reconsider using it in</span>
|
|
<span id="L831"><span class="lineNum"> 831</span> : // the future if it becomes a definitely necessary case.</span>
|
|
<span id="L832"><span class="lineNum"> 832</span> : template <class T></span>
|
|
<span id="L833"><span class="lineNum"> 833</span> : class optional<T&> {</span>
|
|
<span id="L834"><span class="lineNum"> 834</span> : // add this assert to prevent user from using optional reference as indicated</span>
|
|
<span id="L835"><span class="lineNum"> 835</span> : // above</span>
|
|
<span id="L836"><span class="lineNum"> 836</span> : static_assert(</span>
|
|
<span id="L837"><span class="lineNum"> 837</span> : sizeof(T) == 0,</span>
|
|
<span id="L838"><span class="lineNum"> 838</span> : "optional references is ill-formed, \</span>
|
|
<span id="L839"><span class="lineNum"> 839</span> : consider use optional of a std::reference_wrapper of type T to \</span>
|
|
<span id="L840"><span class="lineNum"> 840</span> : hold a reference if you really need to");</span>
|
|
<span id="L841"><span class="lineNum"> 841</span> : </span>
|
|
<span id="L842"><span class="lineNum"> 842</span> : static_assert(!std::is_same<T, nullopt_t>::value, "bad T");</span>
|
|
<span id="L843"><span class="lineNum"> 843</span> : static_assert(!std::is_same<T, in_place_t>::value, "bad T");</span>
|
|
<span id="L844"><span class="lineNum"> 844</span> : T* ref;</span>
|
|
<span id="L845"><span class="lineNum"> 845</span> : </span>
|
|
<span id="L846"><span class="lineNum"> 846</span> : public:</span>
|
|
<span id="L847"><span class="lineNum"> 847</span> : // 20.5.5.1, construction/destruction</span>
|
|
<span id="L848"><span class="lineNum"> 848</span> : constexpr optional() noexcept : ref(nullptr) {}</span>
|
|
<span id="L849"><span class="lineNum"> 849</span> : </span>
|
|
<span id="L850"><span class="lineNum"> 850</span> : constexpr optional(nullopt_t) noexcept : ref(nullptr) {}</span>
|
|
<span id="L851"><span class="lineNum"> 851</span> : </span>
|
|
<span id="L852"><span class="lineNum"> 852</span> : template <typename U = T></span>
|
|
<span id="L853"><span class="lineNum"> 853</span> : constexpr optional(U& u) noexcept : ref(detail_::static_addressof(u)) {}</span>
|
|
<span id="L854"><span class="lineNum"> 854</span> : </span>
|
|
<span id="L855"><span class="lineNum"> 855</span> : template <typename U = T></span>
|
|
<span id="L856"><span class="lineNum"> 856</span> : optional(U&&) = delete;</span>
|
|
<span id="L857"><span class="lineNum"> 857</span> : </span>
|
|
<span id="L858"><span class="lineNum"> 858</span> : constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {}</span>
|
|
<span id="L859"><span class="lineNum"> 859</span> : </span>
|
|
<span id="L860"><span class="lineNum"> 860</span> : explicit constexpr optional(in_place_t, T& v) noexcept</span>
|
|
<span id="L861"><span class="lineNum"> 861</span> : : ref(detail_::static_addressof(v)) {}</span>
|
|
<span id="L862"><span class="lineNum"> 862</span> : </span>
|
|
<span id="L863"><span class="lineNum"> 863</span> : explicit optional(in_place_t, T&&) = delete;</span>
|
|
<span id="L864"><span class="lineNum"> 864</span> : </span>
|
|
<span id="L865"><span class="lineNum"> 865</span> : ~optional() = default;</span>
|
|
<span id="L866"><span class="lineNum"> 866</span> : </span>
|
|
<span id="L867"><span class="lineNum"> 867</span> : // 20.5.5.2, mutation</span>
|
|
<span id="L868"><span class="lineNum"> 868</span> : optional& operator=(nullopt_t) noexcept {</span>
|
|
<span id="L869"><span class="lineNum"> 869</span> : ref = nullptr;</span>
|
|
<span id="L870"><span class="lineNum"> 870</span> : return *this;</span>
|
|
<span id="L871"><span class="lineNum"> 871</span> : }</span>
|
|
<span id="L872"><span class="lineNum"> 872</span> : </span>
|
|
<span id="L873"><span class="lineNum"> 873</span> : // optional& operator=(const optional& rhs) noexcept {</span>
|
|
<span id="L874"><span class="lineNum"> 874</span> : // ref = rhs.ref;</span>
|
|
<span id="L875"><span class="lineNum"> 875</span> : // return *this;</span>
|
|
<span id="L876"><span class="lineNum"> 876</span> : // }</span>
|
|
<span id="L877"><span class="lineNum"> 877</span> : </span>
|
|
<span id="L878"><span class="lineNum"> 878</span> : // optional& operator=(optional&& rhs) noexcept {</span>
|
|
<span id="L879"><span class="lineNum"> 879</span> : // ref = rhs.ref;</span>
|
|
<span id="L880"><span class="lineNum"> 880</span> : // return *this;</span>
|
|
<span id="L881"><span class="lineNum"> 881</span> : // }</span>
|
|
<span id="L882"><span class="lineNum"> 882</span> : </span>
|
|
<span id="L883"><span class="lineNum"> 883</span> : template <typename U></span>
|
|
<span id="L884"><span class="lineNum"> 884</span> : auto operator=(U&& rhs) noexcept -> typename std::enable_if<</span>
|
|
<span id="L885"><span class="lineNum"> 885</span> : std::is_same<typename std::decay<U>::type, optional<T&>>::value,</span>
|
|
<span id="L886"><span class="lineNum"> 886</span> : optional&>::type {</span>
|
|
<span id="L887"><span class="lineNum"> 887</span> : ref = rhs.ref;</span>
|
|
<span id="L888"><span class="lineNum"> 888</span> : return *this;</span>
|
|
<span id="L889"><span class="lineNum"> 889</span> : }</span>
|
|
<span id="L890"><span class="lineNum"> 890</span> : </span>
|
|
<span id="L891"><span class="lineNum"> 891</span> : template <typename U></span>
|
|
<span id="L892"><span class="lineNum"> 892</span> : auto operator=(U&& rhs) noexcept -> typename std::enable_if<</span>
|
|
<span id="L893"><span class="lineNum"> 893</span> : !std::is_same<typename std::decay<U>::type, optional<T&>>::value,</span>
|
|
<span id="L894"><span class="lineNum"> 894</span> : optional&>::type = delete;</span>
|
|
<span id="L895"><span class="lineNum"> 895</span> : </span>
|
|
<span id="L896"><span class="lineNum"> 896</span> : void emplace(T& v) noexcept {</span>
|
|
<span id="L897"><span class="lineNum"> 897</span> : ref = detail_::static_addressof(v);</span>
|
|
<span id="L898"><span class="lineNum"> 898</span> : }</span>
|
|
<span id="L899"><span class="lineNum"> 899</span> : </span>
|
|
<span id="L900"><span class="lineNum"> 900</span> : void emplace(T&&) = delete;</span>
|
|
<span id="L901"><span class="lineNum"> 901</span> : </span>
|
|
<span id="L902"><span class="lineNum"> 902</span> : void swap(optional<T&>& rhs) noexcept {</span>
|
|
<span id="L903"><span class="lineNum"> 903</span> : std::swap(ref, rhs.ref);</span>
|
|
<span id="L904"><span class="lineNum"> 904</span> : }</span>
|
|
<span id="L905"><span class="lineNum"> 905</span> : </span>
|
|
<span id="L906"><span class="lineNum"> 906</span> : // 20.5.5.3, observers</span>
|
|
<span id="L907"><span class="lineNum"> 907</span> : TR2_OPTIONAL_HOST_CONSTEXPR T* operator->() const {</span>
|
|
<span id="L908"><span class="lineNum"> 908</span> : return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref);</span>
|
|
<span id="L909"><span class="lineNum"> 909</span> : }</span>
|
|
<span id="L910"><span class="lineNum"> 910</span> : </span>
|
|
<span id="L911"><span class="lineNum"> 911</span> : TR2_OPTIONAL_HOST_CONSTEXPR T& operator*() const {</span>
|
|
<span id="L912"><span class="lineNum"> 912</span> : return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref);</span>
|
|
<span id="L913"><span class="lineNum"> 913</span> : }</span>
|
|
<span id="L914"><span class="lineNum"> 914</span> : </span>
|
|
<span id="L915"><span class="lineNum"> 915</span> : constexpr T& value() const {</span>
|
|
<span id="L916"><span class="lineNum"> 916</span> : return ref ? *ref</span>
|
|
<span id="L917"><span class="lineNum"> 917</span> : : (throw bad_optional_access("bad optional access"), *ref);</span>
|
|
<span id="L918"><span class="lineNum"> 918</span> : }</span>
|
|
<span id="L919"><span class="lineNum"> 919</span> : </span>
|
|
<span id="L920"><span class="lineNum"> 920</span> : explicit constexpr operator bool() const noexcept {</span>
|
|
<span id="L921"><span class="lineNum"> 921</span> : return ref != nullptr;</span>
|
|
<span id="L922"><span class="lineNum"> 922</span> : }</span>
|
|
<span id="L923"><span class="lineNum"> 923</span> : </span>
|
|
<span id="L924"><span class="lineNum"> 924</span> : constexpr bool has_value() const noexcept {</span>
|
|
<span id="L925"><span class="lineNum"> 925</span> : return ref != nullptr;</span>
|
|
<span id="L926"><span class="lineNum"> 926</span> : }</span>
|
|
<span id="L927"><span class="lineNum"> 927</span> : </span>
|
|
<span id="L928"><span class="lineNum"> 928</span> : template <class V></span>
|
|
<span id="L929"><span class="lineNum"> 929</span> : constexpr typename std::decay<T>::type value_or(V&& v) const {</span>
|
|
<span id="L930"><span class="lineNum"> 930</span> : return *this ? **this</span>
|
|
<span id="L931"><span class="lineNum"> 931</span> : : detail_::convert<typename std::decay<T>::type>(</span>
|
|
<span id="L932"><span class="lineNum"> 932</span> : constexpr_forward<V>(v));</span>
|
|
<span id="L933"><span class="lineNum"> 933</span> : }</span>
|
|
<span id="L934"><span class="lineNum"> 934</span> : </span>
|
|
<span id="L935"><span class="lineNum"> 935</span> : // x.x.x.x, modifiers</span>
|
|
<span id="L936"><span class="lineNum"> 936</span> : void reset() noexcept {</span>
|
|
<span id="L937"><span class="lineNum"> 937</span> : ref = nullptr;</span>
|
|
<span id="L938"><span class="lineNum"> 938</span> : }</span>
|
|
<span id="L939"><span class="lineNum"> 939</span> : };</span>
|
|
<span id="L940"><span class="lineNum"> 940</span> : </span>
|
|
<span id="L941"><span class="lineNum"> 941</span> : template <class T></span>
|
|
<span id="L942"><span class="lineNum"> 942</span> : class optional<T&&> {</span>
|
|
<span id="L943"><span class="lineNum"> 943</span> : static_assert(sizeof(T) == 0, "optional rvalue references disallowed");</span>
|
|
<span id="L944"><span class="lineNum"> 944</span> : };</span>
|
|
<span id="L945"><span class="lineNum"> 945</span> : </span>
|
|
<span id="L946"><span class="lineNum"> 946</span> : // 20.5.8, Relational operators</span>
|
|
<span id="L947"><span class="lineNum"> 947</span> : template <class T></span>
|
|
<span id="L948"><span class="lineNum"> 948</span> : constexpr bool operator==(const optional<T>& x, const optional<T>& y) {</span>
|
|
<span id="L949"><span class="lineNum"> 949</span> : return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y;</span>
|
|
<span id="L950"><span class="lineNum"> 950</span> : }</span>
|
|
<span id="L951"><span class="lineNum"> 951</span> : </span>
|
|
<span id="L952"><span class="lineNum"> 952</span> : template <class T></span>
|
|
<span id="L953"><span class="lineNum"> 953</span> : constexpr bool operator!=(const optional<T>& x, const optional<T>& y) {</span>
|
|
<span id="L954"><span class="lineNum"> 954</span> : return !(x == y);</span>
|
|
<span id="L955"><span class="lineNum"> 955</span> : }</span>
|
|
<span id="L956"><span class="lineNum"> 956</span> : </span>
|
|
<span id="L957"><span class="lineNum"> 957</span> : template <class T></span>
|
|
<span id="L958"><span class="lineNum"> 958</span> : constexpr bool operator<(const optional<T>& x, const optional<T>& y) {</span>
|
|
<span id="L959"><span class="lineNum"> 959</span> : return (!y) ? false : (!x) ? true : *x < *y;</span>
|
|
<span id="L960"><span class="lineNum"> 960</span> : }</span>
|
|
<span id="L961"><span class="lineNum"> 961</span> : </span>
|
|
<span id="L962"><span class="lineNum"> 962</span> : template <class T></span>
|
|
<span id="L963"><span class="lineNum"> 963</span> : constexpr bool operator>(const optional<T>& x, const optional<T>& y) {</span>
|
|
<span id="L964"><span class="lineNum"> 964</span> : return (y < x);</span>
|
|
<span id="L965"><span class="lineNum"> 965</span> : }</span>
|
|
<span id="L966"><span class="lineNum"> 966</span> : </span>
|
|
<span id="L967"><span class="lineNum"> 967</span> : template <class T></span>
|
|
<span id="L968"><span class="lineNum"> 968</span> : constexpr bool operator<=(const optional<T>& x, const optional<T>& y) {</span>
|
|
<span id="L969"><span class="lineNum"> 969</span> : return !(y < x);</span>
|
|
<span id="L970"><span class="lineNum"> 970</span> : }</span>
|
|
<span id="L971"><span class="lineNum"> 971</span> : </span>
|
|
<span id="L972"><span class="lineNum"> 972</span> : template <class T></span>
|
|
<span id="L973"><span class="lineNum"> 973</span> : constexpr bool operator>=(const optional<T>& x, const optional<T>& y) {</span>
|
|
<span id="L974"><span class="lineNum"> 974</span> : return !(x < y);</span>
|
|
<span id="L975"><span class="lineNum"> 975</span> : }</span>
|
|
<span id="L976"><span class="lineNum"> 976</span> : </span>
|
|
<span id="L977"><span class="lineNum"> 977</span> : // 20.5.9, Comparison with nullopt</span>
|
|
<span id="L978"><span class="lineNum"> 978</span> : template <class T></span>
|
|
<span id="L979"><span class="lineNum"> 979</span> <span class="tlaGNC tlaBgGNC"> 401402 : constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept {</span></span>
|
|
<span id="L980"><span class="lineNum"> 980</span> <span class="tlaGNC"> 401402 : return (!x);</span></span>
|
|
<span id="L981"><span class="lineNum"> 981</span> : }</span>
|
|
<span id="L982"><span class="lineNum"> 982</span> : </span>
|
|
<span id="L983"><span class="lineNum"> 983</span> : template <class T></span>
|
|
<span id="L984"><span class="lineNum"> 984</span> : constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept {</span>
|
|
<span id="L985"><span class="lineNum"> 985</span> : return (!x);</span>
|
|
<span id="L986"><span class="lineNum"> 986</span> : }</span>
|
|
<span id="L987"><span class="lineNum"> 987</span> : </span>
|
|
<span id="L988"><span class="lineNum"> 988</span> : template <class T></span>
|
|
<span id="L989"><span class="lineNum"> 989</span> : constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept {</span>
|
|
<span id="L990"><span class="lineNum"> 990</span> : return bool(x);</span>
|
|
<span id="L991"><span class="lineNum"> 991</span> : }</span>
|
|
<span id="L992"><span class="lineNum"> 992</span> : </span>
|
|
<span id="L993"><span class="lineNum"> 993</span> : template <class T></span>
|
|
<span id="L994"><span class="lineNum"> 994</span> : constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept {</span>
|
|
<span id="L995"><span class="lineNum"> 995</span> : return bool(x);</span>
|
|
<span id="L996"><span class="lineNum"> 996</span> : }</span>
|
|
<span id="L997"><span class="lineNum"> 997</span> : </span>
|
|
<span id="L998"><span class="lineNum"> 998</span> : template <class T></span>
|
|
<span id="L999"><span class="lineNum"> 999</span> : constexpr bool operator<(const optional<T>&, nullopt_t) noexcept {</span>
|
|
<span id="L1000"><span class="lineNum"> 1000</span> : return false;</span>
|
|
<span id="L1001"><span class="lineNum"> 1001</span> : }</span>
|
|
<span id="L1002"><span class="lineNum"> 1002</span> : </span>
|
|
<span id="L1003"><span class="lineNum"> 1003</span> : template <class T></span>
|
|
<span id="L1004"><span class="lineNum"> 1004</span> : constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept {</span>
|
|
<span id="L1005"><span class="lineNum"> 1005</span> : return bool(x);</span>
|
|
<span id="L1006"><span class="lineNum"> 1006</span> : }</span>
|
|
<span id="L1007"><span class="lineNum"> 1007</span> : </span>
|
|
<span id="L1008"><span class="lineNum"> 1008</span> : template <class T></span>
|
|
<span id="L1009"><span class="lineNum"> 1009</span> : constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept {</span>
|
|
<span id="L1010"><span class="lineNum"> 1010</span> : return (!x);</span>
|
|
<span id="L1011"><span class="lineNum"> 1011</span> : }</span>
|
|
<span id="L1012"><span class="lineNum"> 1012</span> : </span>
|
|
<span id="L1013"><span class="lineNum"> 1013</span> : template <class T></span>
|
|
<span id="L1014"><span class="lineNum"> 1014</span> : constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept {</span>
|
|
<span id="L1015"><span class="lineNum"> 1015</span> : return true;</span>
|
|
<span id="L1016"><span class="lineNum"> 1016</span> : }</span>
|
|
<span id="L1017"><span class="lineNum"> 1017</span> : </span>
|
|
<span id="L1018"><span class="lineNum"> 1018</span> : template <class T></span>
|
|
<span id="L1019"><span class="lineNum"> 1019</span> : constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept {</span>
|
|
<span id="L1020"><span class="lineNum"> 1020</span> : return bool(x);</span>
|
|
<span id="L1021"><span class="lineNum"> 1021</span> : }</span>
|
|
<span id="L1022"><span class="lineNum"> 1022</span> : </span>
|
|
<span id="L1023"><span class="lineNum"> 1023</span> : template <class T></span>
|
|
<span id="L1024"><span class="lineNum"> 1024</span> : constexpr bool operator>(nullopt_t, const optional<T>&) noexcept {</span>
|
|
<span id="L1025"><span class="lineNum"> 1025</span> : return false;</span>
|
|
<span id="L1026"><span class="lineNum"> 1026</span> : }</span>
|
|
<span id="L1027"><span class="lineNum"> 1027</span> : </span>
|
|
<span id="L1028"><span class="lineNum"> 1028</span> : template <class T></span>
|
|
<span id="L1029"><span class="lineNum"> 1029</span> : constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept {</span>
|
|
<span id="L1030"><span class="lineNum"> 1030</span> : return true;</span>
|
|
<span id="L1031"><span class="lineNum"> 1031</span> : }</span>
|
|
<span id="L1032"><span class="lineNum"> 1032</span> : </span>
|
|
<span id="L1033"><span class="lineNum"> 1033</span> : template <class T></span>
|
|
<span id="L1034"><span class="lineNum"> 1034</span> : constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept {</span>
|
|
<span id="L1035"><span class="lineNum"> 1035</span> : return (!x);</span>
|
|
<span id="L1036"><span class="lineNum"> 1036</span> : }</span>
|
|
<span id="L1037"><span class="lineNum"> 1037</span> : </span>
|
|
<span id="L1038"><span class="lineNum"> 1038</span> : // 20.5.10, Comparison with T</span>
|
|
<span id="L1039"><span class="lineNum"> 1039</span> : template <class T, class U></span>
|
|
<span id="L1040"><span class="lineNum"> 1040</span> : constexpr bool operator==(const optional<T>& x, const U& v) {</span>
|
|
<span id="L1041"><span class="lineNum"> 1041</span> : return bool(x) ? *x == v : false;</span>
|
|
<span id="L1042"><span class="lineNum"> 1042</span> : }</span>
|
|
<span id="L1043"><span class="lineNum"> 1043</span> : </span>
|
|
<span id="L1044"><span class="lineNum"> 1044</span> : template <class T, class U></span>
|
|
<span id="L1045"><span class="lineNum"> 1045</span> : constexpr bool operator==(const U& v, const optional<T>& x) {</span>
|
|
<span id="L1046"><span class="lineNum"> 1046</span> : return bool(x) ? v == *x : false;</span>
|
|
<span id="L1047"><span class="lineNum"> 1047</span> : }</span>
|
|
<span id="L1048"><span class="lineNum"> 1048</span> : </span>
|
|
<span id="L1049"><span class="lineNum"> 1049</span> : template <class T, class U></span>
|
|
<span id="L1050"><span class="lineNum"> 1050</span> : constexpr bool operator!=(const optional<T>& x, const U& v) {</span>
|
|
<span id="L1051"><span class="lineNum"> 1051</span> : return bool(x) ? *x != v : true;</span>
|
|
<span id="L1052"><span class="lineNum"> 1052</span> : }</span>
|
|
<span id="L1053"><span class="lineNum"> 1053</span> : </span>
|
|
<span id="L1054"><span class="lineNum"> 1054</span> : template <class T, class U></span>
|
|
<span id="L1055"><span class="lineNum"> 1055</span> : constexpr bool operator!=(const U& v, const optional<T>& x) {</span>
|
|
<span id="L1056"><span class="lineNum"> 1056</span> : return bool(x) ? v != *x : true;</span>
|
|
<span id="L1057"><span class="lineNum"> 1057</span> : }</span>
|
|
<span id="L1058"><span class="lineNum"> 1058</span> : </span>
|
|
<span id="L1059"><span class="lineNum"> 1059</span> : template <class T, class U></span>
|
|
<span id="L1060"><span class="lineNum"> 1060</span> : constexpr bool operator<(const optional<T>& x, const U& v) {</span>
|
|
<span id="L1061"><span class="lineNum"> 1061</span> : return bool(x) ? *x < v : true;</span>
|
|
<span id="L1062"><span class="lineNum"> 1062</span> : }</span>
|
|
<span id="L1063"><span class="lineNum"> 1063</span> : </span>
|
|
<span id="L1064"><span class="lineNum"> 1064</span> : template <class T, class U></span>
|
|
<span id="L1065"><span class="lineNum"> 1065</span> : constexpr bool operator>(const U& v, const optional<T>& x) {</span>
|
|
<span id="L1066"><span class="lineNum"> 1066</span> : return bool(x) ? v > *x : true;</span>
|
|
<span id="L1067"><span class="lineNum"> 1067</span> : }</span>
|
|
<span id="L1068"><span class="lineNum"> 1068</span> : </span>
|
|
<span id="L1069"><span class="lineNum"> 1069</span> : template <class T, class U></span>
|
|
<span id="L1070"><span class="lineNum"> 1070</span> : constexpr bool operator>(const optional<T>& x, const U& v) {</span>
|
|
<span id="L1071"><span class="lineNum"> 1071</span> : return bool(x) ? *x > v : false;</span>
|
|
<span id="L1072"><span class="lineNum"> 1072</span> : }</span>
|
|
<span id="L1073"><span class="lineNum"> 1073</span> : </span>
|
|
<span id="L1074"><span class="lineNum"> 1074</span> : template <class T, class U></span>
|
|
<span id="L1075"><span class="lineNum"> 1075</span> : constexpr bool operator<(const U& v, const optional<T>& x) {</span>
|
|
<span id="L1076"><span class="lineNum"> 1076</span> : return bool(x) ? v < *x : false;</span>
|
|
<span id="L1077"><span class="lineNum"> 1077</span> : }</span>
|
|
<span id="L1078"><span class="lineNum"> 1078</span> : </span>
|
|
<span id="L1079"><span class="lineNum"> 1079</span> : template <class T, class U></span>
|
|
<span id="L1080"><span class="lineNum"> 1080</span> : constexpr bool operator>=(const optional<T>& x, const U& v) {</span>
|
|
<span id="L1081"><span class="lineNum"> 1081</span> : return bool(x) ? *x >= v : false;</span>
|
|
<span id="L1082"><span class="lineNum"> 1082</span> : }</span>
|
|
<span id="L1083"><span class="lineNum"> 1083</span> : </span>
|
|
<span id="L1084"><span class="lineNum"> 1084</span> : template <class T, class U></span>
|
|
<span id="L1085"><span class="lineNum"> 1085</span> : constexpr bool operator<=(const U& v, const optional<T>& x) {</span>
|
|
<span id="L1086"><span class="lineNum"> 1086</span> : return bool(x) ? v <= *x : false;</span>
|
|
<span id="L1087"><span class="lineNum"> 1087</span> : }</span>
|
|
<span id="L1088"><span class="lineNum"> 1088</span> : </span>
|
|
<span id="L1089"><span class="lineNum"> 1089</span> : template <class T, class U></span>
|
|
<span id="L1090"><span class="lineNum"> 1090</span> : constexpr bool operator<=(const optional<T>& x, const U& v) {</span>
|
|
<span id="L1091"><span class="lineNum"> 1091</span> : return bool(x) ? *x <= v : true;</span>
|
|
<span id="L1092"><span class="lineNum"> 1092</span> : }</span>
|
|
<span id="L1093"><span class="lineNum"> 1093</span> : </span>
|
|
<span id="L1094"><span class="lineNum"> 1094</span> : template <class T, class U></span>
|
|
<span id="L1095"><span class="lineNum"> 1095</span> : constexpr bool operator>=(const U& v, const optional<T>& x) {</span>
|
|
<span id="L1096"><span class="lineNum"> 1096</span> : return bool(x) ? v >= *x : true;</span>
|
|
<span id="L1097"><span class="lineNum"> 1097</span> : }</span>
|
|
<span id="L1098"><span class="lineNum"> 1098</span> : </span>
|
|
<span id="L1099"><span class="lineNum"> 1099</span> : // Comparison of optional<T&> with T</span>
|
|
<span id="L1100"><span class="lineNum"> 1100</span> : template <class T></span>
|
|
<span id="L1101"><span class="lineNum"> 1101</span> : constexpr bool operator==(const optional<T&>& x, const T& v) {</span>
|
|
<span id="L1102"><span class="lineNum"> 1102</span> : return bool(x) ? *x == v : false;</span>
|
|
<span id="L1103"><span class="lineNum"> 1103</span> : }</span>
|
|
<span id="L1104"><span class="lineNum"> 1104</span> : </span>
|
|
<span id="L1105"><span class="lineNum"> 1105</span> : template <class T></span>
|
|
<span id="L1106"><span class="lineNum"> 1106</span> : constexpr bool operator==(const T& v, const optional<T&>& x) {</span>
|
|
<span id="L1107"><span class="lineNum"> 1107</span> : return bool(x) ? v == *x : false;</span>
|
|
<span id="L1108"><span class="lineNum"> 1108</span> : }</span>
|
|
<span id="L1109"><span class="lineNum"> 1109</span> : </span>
|
|
<span id="L1110"><span class="lineNum"> 1110</span> : template <class T></span>
|
|
<span id="L1111"><span class="lineNum"> 1111</span> : constexpr bool operator!=(const optional<T&>& x, const T& v) {</span>
|
|
<span id="L1112"><span class="lineNum"> 1112</span> : return bool(x) ? *x != v : true;</span>
|
|
<span id="L1113"><span class="lineNum"> 1113</span> : }</span>
|
|
<span id="L1114"><span class="lineNum"> 1114</span> : </span>
|
|
<span id="L1115"><span class="lineNum"> 1115</span> : template <class T></span>
|
|
<span id="L1116"><span class="lineNum"> 1116</span> : constexpr bool operator!=(const T& v, const optional<T&>& x) {</span>
|
|
<span id="L1117"><span class="lineNum"> 1117</span> : return bool(x) ? v != *x : true;</span>
|
|
<span id="L1118"><span class="lineNum"> 1118</span> : }</span>
|
|
<span id="L1119"><span class="lineNum"> 1119</span> : </span>
|
|
<span id="L1120"><span class="lineNum"> 1120</span> : template <class T></span>
|
|
<span id="L1121"><span class="lineNum"> 1121</span> : constexpr bool operator<(const optional<T&>& x, const T& v) {</span>
|
|
<span id="L1122"><span class="lineNum"> 1122</span> : return bool(x) ? *x < v : true;</span>
|
|
<span id="L1123"><span class="lineNum"> 1123</span> : }</span>
|
|
<span id="L1124"><span class="lineNum"> 1124</span> : </span>
|
|
<span id="L1125"><span class="lineNum"> 1125</span> : template <class T></span>
|
|
<span id="L1126"><span class="lineNum"> 1126</span> : constexpr bool operator>(const T& v, const optional<T&>& x) {</span>
|
|
<span id="L1127"><span class="lineNum"> 1127</span> : return bool(x) ? v > *x : true;</span>
|
|
<span id="L1128"><span class="lineNum"> 1128</span> : }</span>
|
|
<span id="L1129"><span class="lineNum"> 1129</span> : </span>
|
|
<span id="L1130"><span class="lineNum"> 1130</span> : template <class T></span>
|
|
<span id="L1131"><span class="lineNum"> 1131</span> : constexpr bool operator>(const optional<T&>& x, const T& v) {</span>
|
|
<span id="L1132"><span class="lineNum"> 1132</span> : return bool(x) ? *x > v : false;</span>
|
|
<span id="L1133"><span class="lineNum"> 1133</span> : }</span>
|
|
<span id="L1134"><span class="lineNum"> 1134</span> : </span>
|
|
<span id="L1135"><span class="lineNum"> 1135</span> : template <class T></span>
|
|
<span id="L1136"><span class="lineNum"> 1136</span> : constexpr bool operator<(const T& v, const optional<T&>& x) {</span>
|
|
<span id="L1137"><span class="lineNum"> 1137</span> : return bool(x) ? v < *x : false;</span>
|
|
<span id="L1138"><span class="lineNum"> 1138</span> : }</span>
|
|
<span id="L1139"><span class="lineNum"> 1139</span> : </span>
|
|
<span id="L1140"><span class="lineNum"> 1140</span> : template <class T></span>
|
|
<span id="L1141"><span class="lineNum"> 1141</span> : constexpr bool operator>=(const optional<T&>& x, const T& v) {</span>
|
|
<span id="L1142"><span class="lineNum"> 1142</span> : return bool(x) ? *x >= v : false;</span>
|
|
<span id="L1143"><span class="lineNum"> 1143</span> : }</span>
|
|
<span id="L1144"><span class="lineNum"> 1144</span> : </span>
|
|
<span id="L1145"><span class="lineNum"> 1145</span> : template <class T></span>
|
|
<span id="L1146"><span class="lineNum"> 1146</span> : constexpr bool operator<=(const T& v, const optional<T&>& x) {</span>
|
|
<span id="L1147"><span class="lineNum"> 1147</span> : return bool(x) ? v <= *x : false;</span>
|
|
<span id="L1148"><span class="lineNum"> 1148</span> : }</span>
|
|
<span id="L1149"><span class="lineNum"> 1149</span> : </span>
|
|
<span id="L1150"><span class="lineNum"> 1150</span> : template <class T></span>
|
|
<span id="L1151"><span class="lineNum"> 1151</span> : constexpr bool operator<=(const optional<T&>& x, const T& v) {</span>
|
|
<span id="L1152"><span class="lineNum"> 1152</span> : return bool(x) ? *x <= v : true;</span>
|
|
<span id="L1153"><span class="lineNum"> 1153</span> : }</span>
|
|
<span id="L1154"><span class="lineNum"> 1154</span> : </span>
|
|
<span id="L1155"><span class="lineNum"> 1155</span> : template <class T></span>
|
|
<span id="L1156"><span class="lineNum"> 1156</span> : constexpr bool operator>=(const T& v, const optional<T&>& x) {</span>
|
|
<span id="L1157"><span class="lineNum"> 1157</span> : return bool(x) ? v >= *x : true;</span>
|
|
<span id="L1158"><span class="lineNum"> 1158</span> : }</span>
|
|
<span id="L1159"><span class="lineNum"> 1159</span> : </span>
|
|
<span id="L1160"><span class="lineNum"> 1160</span> : // Comparison of optional<T const&> with T</span>
|
|
<span id="L1161"><span class="lineNum"> 1161</span> : template <class T></span>
|
|
<span id="L1162"><span class="lineNum"> 1162</span> : constexpr bool operator==(const optional<const T&>& x, const T& v) {</span>
|
|
<span id="L1163"><span class="lineNum"> 1163</span> : return bool(x) ? *x == v : false;</span>
|
|
<span id="L1164"><span class="lineNum"> 1164</span> : }</span>
|
|
<span id="L1165"><span class="lineNum"> 1165</span> : </span>
|
|
<span id="L1166"><span class="lineNum"> 1166</span> : template <class T></span>
|
|
<span id="L1167"><span class="lineNum"> 1167</span> : constexpr bool operator==(const T& v, const optional<const T&>& x) {</span>
|
|
<span id="L1168"><span class="lineNum"> 1168</span> : return bool(x) ? v == *x : false;</span>
|
|
<span id="L1169"><span class="lineNum"> 1169</span> : }</span>
|
|
<span id="L1170"><span class="lineNum"> 1170</span> : </span>
|
|
<span id="L1171"><span class="lineNum"> 1171</span> : template <class T></span>
|
|
<span id="L1172"><span class="lineNum"> 1172</span> : constexpr bool operator!=(const optional<const T&>& x, const T& v) {</span>
|
|
<span id="L1173"><span class="lineNum"> 1173</span> : return bool(x) ? *x != v : true;</span>
|
|
<span id="L1174"><span class="lineNum"> 1174</span> : }</span>
|
|
<span id="L1175"><span class="lineNum"> 1175</span> : </span>
|
|
<span id="L1176"><span class="lineNum"> 1176</span> : template <class T></span>
|
|
<span id="L1177"><span class="lineNum"> 1177</span> : constexpr bool operator!=(const T& v, const optional<const T&>& x) {</span>
|
|
<span id="L1178"><span class="lineNum"> 1178</span> : return bool(x) ? v != *x : true;</span>
|
|
<span id="L1179"><span class="lineNum"> 1179</span> : }</span>
|
|
<span id="L1180"><span class="lineNum"> 1180</span> : </span>
|
|
<span id="L1181"><span class="lineNum"> 1181</span> : template <class T></span>
|
|
<span id="L1182"><span class="lineNum"> 1182</span> : constexpr bool operator<(const optional<const T&>& x, const T& v) {</span>
|
|
<span id="L1183"><span class="lineNum"> 1183</span> : return bool(x) ? *x < v : true;</span>
|
|
<span id="L1184"><span class="lineNum"> 1184</span> : }</span>
|
|
<span id="L1185"><span class="lineNum"> 1185</span> : </span>
|
|
<span id="L1186"><span class="lineNum"> 1186</span> : template <class T></span>
|
|
<span id="L1187"><span class="lineNum"> 1187</span> : constexpr bool operator>(const T& v, const optional<const T&>& x) {</span>
|
|
<span id="L1188"><span class="lineNum"> 1188</span> : return bool(x) ? v > *x : true;</span>
|
|
<span id="L1189"><span class="lineNum"> 1189</span> : }</span>
|
|
<span id="L1190"><span class="lineNum"> 1190</span> : </span>
|
|
<span id="L1191"><span class="lineNum"> 1191</span> : template <class T></span>
|
|
<span id="L1192"><span class="lineNum"> 1192</span> : constexpr bool operator>(const optional<const T&>& x, const T& v) {</span>
|
|
<span id="L1193"><span class="lineNum"> 1193</span> : return bool(x) ? *x > v : false;</span>
|
|
<span id="L1194"><span class="lineNum"> 1194</span> : }</span>
|
|
<span id="L1195"><span class="lineNum"> 1195</span> : </span>
|
|
<span id="L1196"><span class="lineNum"> 1196</span> : template <class T></span>
|
|
<span id="L1197"><span class="lineNum"> 1197</span> : constexpr bool operator<(const T& v, const optional<const T&>& x) {</span>
|
|
<span id="L1198"><span class="lineNum"> 1198</span> : return bool(x) ? v < *x : false;</span>
|
|
<span id="L1199"><span class="lineNum"> 1199</span> : }</span>
|
|
<span id="L1200"><span class="lineNum"> 1200</span> : </span>
|
|
<span id="L1201"><span class="lineNum"> 1201</span> : template <class T></span>
|
|
<span id="L1202"><span class="lineNum"> 1202</span> : constexpr bool operator>=(const optional<const T&>& x, const T& v) {</span>
|
|
<span id="L1203"><span class="lineNum"> 1203</span> : return bool(x) ? *x >= v : false;</span>
|
|
<span id="L1204"><span class="lineNum"> 1204</span> : }</span>
|
|
<span id="L1205"><span class="lineNum"> 1205</span> : </span>
|
|
<span id="L1206"><span class="lineNum"> 1206</span> : template <class T></span>
|
|
<span id="L1207"><span class="lineNum"> 1207</span> : constexpr bool operator<=(const T& v, const optional<const T&>& x) {</span>
|
|
<span id="L1208"><span class="lineNum"> 1208</span> : return bool(x) ? v <= *x : false;</span>
|
|
<span id="L1209"><span class="lineNum"> 1209</span> : }</span>
|
|
<span id="L1210"><span class="lineNum"> 1210</span> : </span>
|
|
<span id="L1211"><span class="lineNum"> 1211</span> : template <class T></span>
|
|
<span id="L1212"><span class="lineNum"> 1212</span> : constexpr bool operator<=(const optional<const T&>& x, const T& v) {</span>
|
|
<span id="L1213"><span class="lineNum"> 1213</span> : return bool(x) ? *x <= v : true;</span>
|
|
<span id="L1214"><span class="lineNum"> 1214</span> : }</span>
|
|
<span id="L1215"><span class="lineNum"> 1215</span> : </span>
|
|
<span id="L1216"><span class="lineNum"> 1216</span> : template <class T></span>
|
|
<span id="L1217"><span class="lineNum"> 1217</span> : constexpr bool operator>=(const T& v, const optional<const T&>& x) {</span>
|
|
<span id="L1218"><span class="lineNum"> 1218</span> : return bool(x) ? v >= *x : true;</span>
|
|
<span id="L1219"><span class="lineNum"> 1219</span> : }</span>
|
|
<span id="L1220"><span class="lineNum"> 1220</span> : </span>
|
|
<span id="L1221"><span class="lineNum"> 1221</span> : // 20.5.12, Specialized algorithms</span>
|
|
<span id="L1222"><span class="lineNum"> 1222</span> : template <class T></span>
|
|
<span id="L1223"><span class="lineNum"> 1223</span> : void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y))) {</span>
|
|
<span id="L1224"><span class="lineNum"> 1224</span> : x.swap(y);</span>
|
|
<span id="L1225"><span class="lineNum"> 1225</span> : }</span>
|
|
<span id="L1226"><span class="lineNum"> 1226</span> : </span>
|
|
<span id="L1227"><span class="lineNum"> 1227</span> : template <class T></span>
|
|
<span id="L1228"><span class="lineNum"> 1228</span> <span class="tlaGNC"> 418776 : constexpr optional<typename std::decay<T>::type> make_optional(T&& v) {</span></span>
|
|
<span id="L1229"><span class="lineNum"> 1229</span> <span class="tlaGNC"> 418776 : return optional<typename std::decay<T>::type>(constexpr_forward<T>(v));</span></span>
|
|
<span id="L1230"><span class="lineNum"> 1230</span> : }</span>
|
|
<span id="L1231"><span class="lineNum"> 1231</span> : </span>
|
|
<span id="L1232"><span class="lineNum"> 1232</span> : template <class X></span>
|
|
<span id="L1233"><span class="lineNum"> 1233</span> : constexpr optional<X&> make_optional(std::reference_wrapper<X> v) {</span>
|
|
<span id="L1234"><span class="lineNum"> 1234</span> : return optional<X&>(v.get());</span>
|
|
<span id="L1235"><span class="lineNum"> 1235</span> : }</span>
|
|
<span id="L1236"><span class="lineNum"> 1236</span> : </span>
|
|
<span id="L1237"><span class="lineNum"> 1237</span> : } // namespace c10</span>
|
|
<span id="L1238"><span class="lineNum"> 1238</span> : </span>
|
|
<span id="L1239"><span class="lineNum"> 1239</span> : namespace std {</span>
|
|
<span id="L1240"><span class="lineNum"> 1240</span> : template <typename T></span>
|
|
<span id="L1241"><span class="lineNum"> 1241</span> : struct hash<c10::optional<T>> {</span>
|
|
<span id="L1242"><span class="lineNum"> 1242</span> : typedef c10::invoke_result_t<std::hash<T>, T> result_type;</span>
|
|
<span id="L1243"><span class="lineNum"> 1243</span> : typedef c10::optional<T> argument_type;</span>
|
|
<span id="L1244"><span class="lineNum"> 1244</span> : </span>
|
|
<span id="L1245"><span class="lineNum"> 1245</span> : constexpr result_type operator()(argument_type const& arg) const {</span>
|
|
<span id="L1246"><span class="lineNum"> 1246</span> : return arg ? std::hash<T>{}(*arg) : result_type{};</span>
|
|
<span id="L1247"><span class="lineNum"> 1247</span> : }</span>
|
|
<span id="L1248"><span class="lineNum"> 1248</span> : };</span>
|
|
<span id="L1249"><span class="lineNum"> 1249</span> : </span>
|
|
<span id="L1250"><span class="lineNum"> 1250</span> : template <typename T></span>
|
|
<span id="L1251"><span class="lineNum"> 1251</span> : struct hash<c10::optional<T&>> {</span>
|
|
<span id="L1252"><span class="lineNum"> 1252</span> : typedef typename hash<T>::result_type result_type;</span>
|
|
<span id="L1253"><span class="lineNum"> 1253</span> : typedef c10::optional<T&> argument_type;</span>
|
|
<span id="L1254"><span class="lineNum"> 1254</span> : </span>
|
|
<span id="L1255"><span class="lineNum"> 1255</span> : constexpr result_type operator()(argument_type const& arg) const {</span>
|
|
<span id="L1256"><span class="lineNum"> 1256</span> : return arg ? std::hash<T>{}(*arg) : result_type{};</span>
|
|
<span id="L1257"><span class="lineNum"> 1257</span> : }</span>
|
|
<span id="L1258"><span class="lineNum"> 1258</span> : };</span>
|
|
<span id="L1259"><span class="lineNum"> 1259</span> : } // namespace std</span>
|
|
<span id="L1260"><span class="lineNum"> 1260</span> : </span>
|
|
<span id="L1261"><span class="lineNum"> 1261</span> : #undef TR2_OPTIONAL_REQUIRES</span>
|
|
<span id="L1262"><span class="lineNum"> 1262</span> : #undef TR2_OPTIONAL_ASSERTED_EXPRESSION</span>
|
|
<span id="L1263"><span class="lineNum"> 1263</span> : #undef TR2_OPTIONAL_HOST_CONSTEXPR</span>
|
|
<span id="L1264"><span class="lineNum"> 1264</span> : </span>
|
|
<span id="L1265"><span class="lineNum"> 1265</span> : C10_CLANG_DIAGNOSTIC_POP()</span>
|
|
<span id="L1266"><span class="lineNum"> 1266</span> : </span>
|
|
<span id="L1267"><span class="lineNum"> 1267</span> : #if defined(_MSC_VER) && !defined(__clang__)</span>
|
|
<span id="L1268"><span class="lineNum"> 1268</span> : #pragma warning(pop)</span>
|
|
<span id="L1269"><span class="lineNum"> 1269</span> : #endif</span>
|
|
<span id="L1270"><span class="lineNum"> 1270</span> : </span>
|
|
<span id="L1271"><span class="lineNum"> 1271</span> : #endif // C10_UTIL_OPTIONAL_H_</span>
|
|
</pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
|
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
<tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
<tr><td class="versionInfo">Generated by: <a href="https://github.com//linux-test-project/lcov" target="_parent">LCOV version 2.0-1</a></td></tr>
|
|
</table>
|
|
<br>
|
|
|
|
</body>
|
|
</html>
|