Skip to content

Commit

Permalink
Tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
brevzin committed Dec 3, 2024
1 parent 37f72d5 commit a0be1a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
11 changes: 6 additions & 5 deletions 3380_extend_cnttp_2/extend-cnttp-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,10 @@ For template-argument equivalence, we can say that two values of class type `C`
```cpp
consteval auto template_argument_equivalent(C const& a, C const& b) -> bool {
struct Serializer {
std::vector<std::meta::info> v;
std::vector<std::meta::info> $output$;
consteval auto push(std::meta::info r) -> void {
v.push_back(r);
$output$.push_back(r);
}
// ... rest of API ...
Expand All @@ -806,7 +807,7 @@ consteval auto template_argument_equivalent(C const& a, C const& b) -> bool {
Serializer sa, sb;
a.to_meta_representation(sa);
b.to_meta_representation(sb);
return sa.v == sb.v;
return sa.$output$ == sb.$output$;
}
```
:::
Expand All @@ -832,13 +833,13 @@ const C $object$ = []{
auto $serializer$ = $make-serializer$();
c.to_meta_representation($serializer$);

auto $deserializer$ = $make-deserializer$($serializer$);
auto $deserializer$ = $make-deserializer-from$($serializer$);
return C::from_meta_representation($deserializer$);
}();
```
:::

The actual types of the (de)serializer objects are implementation-defined, the only thing that matters is that they conform to the interface above.
The actual types of the (de)serializer objects are implementation-defined, the only thing that matters is that they conform to the interface above. Note that, as a sanity check, the implementation could do a _second_ serialization round after the round-trip, do ensure that both the original and new values produce the same serialization.

We will also have to adjust `std::meta::reflect_value()` to also do this normalization. Which means:

Expand Down
34 changes: 19 additions & 15 deletions 3380_extend_cnttp_2/p3380r1.html
Original file line number Diff line number Diff line change
Expand Up @@ -1543,19 +1543,20 @@ <h2 data-number="3.2" id="template-argument-equivalence"><span class="header-sec
<blockquote>
<div class="sourceCode" id="cb21"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="kw">consteval</span> <span class="kw">auto</span> template_argument_equivalent<span class="op">(</span>C <span class="kw">const</span><span class="op">&amp;</span> a, C <span class="kw">const</span><span class="op">&amp;</span> b<span class="op">)</span> <span class="op">-&gt;</span> <span class="dt">bool</span> <span class="op">{</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">struct</span> Serializer <span class="op">{</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> std<span class="op">::</span>vector<span class="op">&lt;</span>std<span class="op">::</span>meta<span class="op">::</span>info<span class="op">&gt;</span> v;</span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">consteval</span> <span class="kw">auto</span> push<span class="op">(</span>std<span class="op">::</span>meta<span class="op">::</span>info r<span class="op">)</span> <span class="op">-&gt;</span> <span class="dt">void</span> <span class="op">{</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a> v<span class="op">.</span>push_back<span class="op">(</span>r<span class="op">)</span>;</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a> <span class="co">// ... rest of API ...</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span>;</span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a> Serializer sa, sb;</span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a> a<span class="op">.</span>to_meta_representation<span class="op">(</span>sa<span class="op">)</span>;</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a> b<span class="op">.</span>to_meta_representation<span class="op">(</span>sb<span class="op">)</span>;</span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> sa<span class="op">.</span>v <span class="op">==</span> sb<span class="op">.</span>v;</span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> std<span class="op">::</span>vector<span class="op">&lt;</span>std<span class="op">::</span>meta<span class="op">::</span>info<span class="op">&gt;</span> <em>output</em>;</span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">consteval</span> <span class="kw">auto</span> push<span class="op">(</span>std<span class="op">::</span>meta<span class="op">::</span>info r<span class="op">)</span> <span class="op">-&gt;</span> <span class="dt">void</span> <span class="op">{</span></span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a> <em>output</em><span class="op">.</span>push_back<span class="op">(</span>r<span class="op">)</span>;</span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a> <span class="co">// ... rest of API ...</span></span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span>;</span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a> Serializer sa, sb;</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a> a<span class="op">.</span>to_meta_representation<span class="op">(</span>sa<span class="op">)</span>;</span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a> b<span class="op">.</span>to_meta_representation<span class="op">(</span>sb<span class="op">)</span>;</span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> sa<span class="op">.</span><em>output</em> <span class="op">==</span> sb<span class="op">.</span><em>output</em>;</span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
</blockquote>
</div>
<p>That is, two values are template-argument-equivalent if they
Expand All @@ -1581,14 +1582,17 @@ <h2 data-number="3.3" id="normalization-1"><span class="header-section-number">3
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">auto</span> <em>serializer</em> <span class="op">=</span> <em>make-serializer</em><span class="op">()</span>;</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a> c<span class="op">.</span>to_meta_representation<span class="op">(</span><em>serializer</em><span class="op">)</span>;</span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">auto</span> <em>deserializer</em> <span class="op">=</span> <em>make-deserializer</em><span class="op">(</span><em>serializer</em><span class="op">)</span>;</span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">auto</span> <em>deserializer</em> <span class="op">=</span> <em>make-deserializer-from</em><span class="op">(</span><em>serializer</em><span class="op">)</span>;</span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> C<span class="op">::</span>from_meta_representation<span class="op">(</span><em>deserializer</em><span class="op">)</span>;</span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a><span class="op">}()</span>;</span></code></pre></div>
</blockquote>
</div>
<p>The actual types of the (de)serializer objects are
implementation-defined, the only thing that matters is that they conform
to the interface above.</p>
to the interface above. Note that, as a sanity check, the implementation
could do a <em>second</em> serialization round after the round-trip, do
ensure that both the original and new values produce the same
serialization.</p>
<p>We will also have to adjust <code class="sourceCode cpp">std<span class="op">::</span>meta<span class="op">::</span>reflect_value<span class="op">()</span></code>
to also do this normalization. Which means:</p>
<div class="std">
Expand Down

0 comments on commit a0be1a4

Please sign in to comment.