Skip to content

Commit

Permalink
Deploy preview for PR 546 🛫
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 22, 2023
1 parent 279dc4d commit b21a355
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pr-preview/pr-546/examples-core-reflection-traits-array.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h1>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">CUBOS_INFO</span><span class="p">(</span><span class="s">&quot;Element {}: {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="k">static_cast</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="kt">int32_t</span><span class="o">*&gt;</span><span class="p">(</span><span class="n">arrayTrait</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">instance</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">)));</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span></pre><p>In this example, we&#x27;re only supporting arrays of <code>int</code>s, but we could for example implement a printing function which supports all primitive types.</p><p>To make calling our function easier, we can add a convenience typed wrapper:</p><pre class="m-code"><span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">T</span><span class="o">&gt;</span>
<span class="p">}</span></pre><p>In this example, we&#x27;re only supporting arrays of <code>int32_t</code>s, but we could for example implement a printing function which supports all primitive types.</p><p>To make calling our function easier, we can add a convenience typed wrapper:</p><pre class="m-code"><span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">T</span><span class="o">&gt;</span>
<span class="kt">void</span><span class="w"> </span><span class="n">printArray</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="o">&amp;</span><span class="w"> </span><span class="n">array</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">using</span><span class="w"> </span><span class="n">cubos</span><span class="o">::</span><span class="n">core</span><span class="o">::</span><span class="n">reflection</span><span class="o">::</span><span class="n">reflect</span><span class="p">;</span>
Expand All @@ -90,7 +90,7 @@ <h1>
<span class="w"> </span><span class="c1">// Element 4: 5</span>
<span class="w"> </span><span class="c1">// Element 5: 8</span>
<span class="w"> </span><span class="c1">// Element 6: 13</span>
<span class="p">}</span></pre><p>Its important to note that both the includes above are necessary, as we&#x27;re reflecting the type <code>std::vector&lt;int&gt;</code>, which also means reflecting <code>int</code>.</p><p>Executing the sample should output:</p><pre class="m-code"><span class="w"> </span><span class="c1">// Array with 7 elements of type int32_t</span>
<span class="p">}</span></pre><p>Its important to note that both the includes above are necessary, as we&#x27;re reflecting the type <code>std::vector&lt;int32_t&gt;</code>, which also means reflecting <code>int32_t</code>.</p><p>Executing the sample should output:</p><pre class="m-code"><span class="w"> </span><span class="c1">// Array with 7 elements of type int32_t</span>
<span class="w"> </span><span class="c1">// Element 0: 1</span>
<span class="w"> </span><span class="c1">// Element 1: 1</span>
<span class="w"> </span><span class="c1">// Element 2: 2</span>
Expand Down

0 comments on commit b21a355

Please sign in to comment.