<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" version="1.1">
  <file original="NoName" source-language="en" datatype="plaintext" target-language="zh_Hans">
    <body>
      <trans-unit xml:space="preserve" approved="no" id="db7e3a3014c7f075" weblate-flags="safe-html, strict-same">
        <source>= Custom Conversions Boost.JSON uses two mechanisms to customize conversion between &lt;&lt;ref_value&gt;&gt; and user types. One mechanism involves specializing type traits. The other one is more powerful and requires defining overloads of `tag_invoke`. Both mechanisms will be further explained in this section.</source>
        <target state="translated">= 自定义转换 Boost.JSON 提供了两种机制用于自定义 &amp;lt;&lt;ref_value&gt;&amp;gt; 与用户类型之间的转换。一种机制涉及特化类型特征（type traits）。另一种机制更强大，需要定义`tag_invoke`的重载。本节将进一步解释这两种机制。&lt;/ref_value&gt;</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">10</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="29df1a0d51cdb284" weblate-flags="safe-html, strict-same">
        <source>Conversion Traits</source>
        <target state="translated">转换特征</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">16</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="ee8bd190809448d3" weblate-flags="safe-html, strict-same">
        <source>Previously a number of conversion type traits, like &lt;&lt;ref_is_tuple_like&gt;&gt; or &lt;&lt;ref_is_sequence_like&gt;&gt;,  were introduced. The library tries the traits one after another and uses the implementation that corresponds to the first matching trait. In some cases, though, a type would match a trait with a higher priority, but the user intends for it to belong to a lower priority category. If this happens the user can specialize the trait that's not supposed to match for that type to be an equivalent of `std::false_type`.</source>
        <target state="translated">之前已经介绍了一些转换类型特征，例如 &amp;lt;&lt;ref_is_tuple_like&gt;&amp;gt; 或 &amp;lt;&lt;ref_is_sequence_like&gt;&amp;gt;。库会依次尝试这些特征，并使用与第一个匹配特征对应的实现。然而，在某些情况下，某个类型可能会匹配到优先级更高的特征，而用户实际希望将其归入优先级更低的类别。如果发生这种情况，用户可以针对该类型特化那个不应匹配的特征，使其等同于`std::false_type`。&lt;/ref_is_sequence_like&gt;&lt;/ref_is_tuple_like&gt;</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">17</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="5057dd0f035191da" weblate-flags="safe-html, strict-same">
        <source>Consider this type:</source>
        <target state="translated">考虑以下类型：</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">25</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="af31edd89e4546e9" weblate-flags="safe-html, strict-same">
        <source>It exposes both a sequence API and a tuple API. But converting from &lt;&lt;ref_value&gt;&gt; to `user_ns::ip_address` would not be able to use implementation for sequences, since those are constructed empty and then populated one element at a time, while `ip_address` has a fixed size of 4. The tuple conversion would fit, though. The only problem is that &lt;&lt;ref_is_tuple_like&gt;&gt; has a lower priority than &lt;&lt;ref_is_sequence_like&gt;&gt;. In order to circumvent this, the user only needs to specialize &lt;&lt;ref_is_sequence_like&gt;&gt; to not match `ip_address`.</source>
        <target state="translated">它同时暴露了序列（sequence）API 和元组（tuple）API。然而，从 &amp;lt;&lt;ref_value&gt;&amp;gt; 转换到 user_ns::ip_address 时无法使用序列的实现，因为序列类型的转换会先构造一个空对象，再逐个填充元素，而 ip_address 的大小固定为 4。相比之下，元组转换是合适的。唯一的问题在于 &amp;lt;&lt;ref_is_tuple_like&gt;&amp;gt; 的优先级低于 &amp;lt;&lt;ref_is_sequence_like&gt;&amp;gt;。为绕过此问题，用户只需特化 &amp;lt;&lt;ref_is_sequence_like&gt;&amp;gt;，使其对 ip_address 不匹配即可。&lt;/ref_is_sequence_like&gt;&lt;/ref_is_sequence_like&gt;&lt;/ref_is_tuple_like&gt;&lt;/ref_value&gt;</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">32</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="ca3736f607b05d90" weblate-flags="safe-html, strict-same">
        <source>`tag_invoke` Overloads</source>
        <target state="translated">`tag_invoke`重载</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">45</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="bae52da73639ec2e" weblate-flags="safe-html, strict-same">
        <source>The second, more powerful approach, is to provide the conversion implementation yourself. With Boost.JSON this is done by defining an overload of `tag_invoke` function (the benefits of this mechanism are outlined in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1895r0.pdf[C++ proposal P1895]. In essence, `tag_invoke` provides a uniform interface for defining customization points by using argument-dependent lookup to find a viable overload from the point at which it is called. As the name suggests, a tag type is passed as an argument in order to:</source>
        <target state="translated">第二种、更强大的方法是自行提供转换实现。在 Boost.JSON 中，这是通过定义`tag_invoke`函数的重载来实现的（该机制的优点详见 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1895r0.pdf[C++提案P1895]）。本质上，`tag_invoke` 通过参数依赖查找（ADL）在调用点寻找可用的重载，从而为自定义扩展点提供统一接口。顾名思义，一个标签类型作为参数传递，用于：</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">46</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="fcd16e41abefe5d9" weblate-flags="safe-html, strict-same">
        <source>discard candidates that are unrelated to that particular</source>
        <target state="translated">排除与该特定自定义点无关的候选函数，</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">55</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="2e09de43c2ca9b1c" weblate-flags="safe-html, strict-same">
        <source>customization point, and</source>
        <target state="translated">并且</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">56</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="0000c8df510ab6a4" weblate-flags="safe-html, strict-same">
        <source>embed the user-defined type into the arguments list (e.g. by using a tag type</source>
        <target state="translated">将用户自定义类型嵌入到参数列表中（例如，通过使用</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">58</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="032f7b87fa7e46c8" weblate-flags="safe-html, strict-same">
        <source>template such as `value_to_tag&lt;T&gt;`) so that its http://eel.is/c++draft/basic.lookup.argdep#2[associated namespaces and entities] are examined when name lookup is performed.</source>
        <target state="translated">像`value_to_tag&lt;t&gt;`这样的标签类型模板），以便在执行名称查找时检查其http://eel.is/c++draft/basic.lookup.argdep#2[关联的命名空间和实体]。&lt;/t&gt;</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">59</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="120c47070d4d98a4" weblate-flags="safe-html, strict-same">
        <source>This has the effect of finding user-provided `tag_invoke` overloads, even if they are declared (lexically) after the definition of the calling function.</source>
        <target state="translated">这能够识别用户提供的`tag_invoke`重载函数，即便这些重载函数是（从词法角度来看）在调用函数的定义之后声明的。</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">63</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="fa95bff76dbcc66e" weblate-flags="safe-html, strict-same">
        <source>Overloads of `tag_invoke` called by &lt;&lt;ref_value_from&gt;&gt; take the form:</source>
        <target state="translated">由 &amp;lt;&lt;ref_value_from&gt;&amp;gt; 调用的 `tag_invoke` 的重载形式如下：&lt;/ref_value_from&gt;</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">66</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="cbd0d793411c684e" weblate-flags="safe-html, strict-same">
        <source>``` void tag_invoke( const value_from_tag&amp;, value&amp;, T ); ```</source>
        <target state="translated">``` void tag_invoke( const value_from_tag&amp;amp;, value&amp;amp;, T ); ```</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">68</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="66340cb77630b9d1" weblate-flags="safe-html, strict-same">
        <source>While overloads of `tag_invoke` called by &lt;&lt;ref_value_to&gt;&gt; take the form:</source>
        <target state="translated">而由 &amp;lt;&lt;ref_value_to&gt;&amp;gt; 调用的`tag_invoke`重载采用以下形式：&lt;/ref_value_to&gt;</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">72</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="cceef2c3e2ebf8b6" weblate-flags="safe-html, strict-same">
        <source>``` T tag_invoke( const value_to_tag&lt; T &gt;&amp;, const value&amp; ); ```</source>
        <target state="translated">``` T tag_invoke( const value_to_tag&amp;lt; T &amp;gt;&amp;amp;, const value&amp;amp; ); ```</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">74</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="3703ad2a77aeec20" weblate-flags="safe-html, strict-same">
        <source>If we implemented conversion for `user_ns::ip_address` manually with this approach, it would look like this:</source>
        <target state="translated">如果我们采用这种方式手动对 `user_ns::ip_address` 进行转换，其效果将会是这样的：</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">78</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="05b05931dbf73bd2" weblate-flags="safe-html, strict-same">
        <source>Since the type being converted is embedded into the function's signature, user-provided overloads are visible to argument-dependent lookup and will be candidates when a conversion is performed:</source>
        <target state="translated">由于要转换的类型已嵌入到函数的签名中，因此用户自定义的重载形式会出现在依赖于参数的查找过程中，并且在进行转换时会成为候选选项：</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">86</context>
        </context-group>
      </trans-unit>
      <trans-unit xml:space="preserve" approved="no" id="2d8ed9a30bebe9c3" weblate-flags="safe-html, strict-same">
        <source>Users can freely combine types with custom conversions with types with library-provided conversions. The library handles them correctly:</source>
        <target state="translated">用户可以自由地将具有自定义转换的类型与具有库提供转换的类型组合使用，库能正确处理它们：</target>
        <context-group name="" purpose="location">
          <context context-type="sourcefile"></context>
          <context context-type="linenumber">95</context>
        </context-group>
      </trans-unit>
    </body>
  </file>
</xliff>
