Custom_class_detail.h WrapMethod noexcept

pya: <p>Hi,</p>
<p>I would like to suggest the addition of the following function to custom_class_detail.h:</p>
<pre><code class="lang-auto">template &lt;typename R, typename CurrClass, typename... Args&gt;
struct WrapMethod&lt;R (CurrClass::*)(Args...) const noexcept&gt; {
  WrapMethod(R (CurrClass::*m)(Args...) const noexcept) : m(std::move(m)) {}

  R operator()(c10::intrusive_ptr&lt;CurrClass&gt; cur, Args... args) {
    return std::invoke(m, *cur, args...);
  }

  R (CurrClass::*m)(Args...) const;
};
</code></pre>
<p>Without the above specialization, I ran into the following error using g+±13 with –std=c++17 option:</p>
<pre><code class="lang-auto">error: invalid use of incomplete type ‘struct torch::detail::WrapMethod&lt;void (MyClass::*)() const noexcept&gt;’
  110 |   return WrapMethod&lt;Func&gt;(std::move(f));
</code></pre>

ptrblck: <p>Could you open a PR on GitHub describing the proposed change so the code owners can take a look at it, please?</p>

pya: <p>Done!</p>
<aside class="onebox githubpullrequest" data-onebox-src="https://github.com/pytorch/pytorch/pull/161135">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/pull/161135" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row" data-github-private-repo="false">



    <div class="github-icon-container" title="Pull Request">
      <svg width="60" height="60" class="github-icon" viewBox="0 0 12 16" aria-hidden="true"><path fill-rule="evenodd" d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
    </div>

  <div class="github-info-container">



      <h4>
        <a href="https://github.com/pytorch/pytorch/pull/161135" target="_blank" rel="noopener nofollow ugc">Update custom_class_detail.h</a>
      </h4>

    <div class="branches">
      <code>main</code> ← <code>bumi001:main</code>
    </div>

      <div class="github-info">
        <div class="date">
          opened <span class="discourse-local-date" data-format="ll" data-date="2025-08-21" data-time="03:29:51" data-timezone="UTC">03:29AM - 21 Aug 25 UTC</span>
        </div>

        <div class="user">
          <a href="https://github.com/bumi001" target="_blank" rel="noopener nofollow ugc">
            <img alt="" src="https://avatars.githubusercontent.com/u/14148656?v=4" class="onebox-avatar-inline" width="20" height="20">
            bumi001
          </a>
        </div>

        <div class="lines" title="1 commits changed 1 files with 11 additions and 0 deletions">
          <a href="https://github.com/pytorch/pytorch/pull/161135/files" target="_blank" rel="noopener nofollow ugc">
            <span class="added">+11</span>
            <span class="removed">-0</span>
          </a>
        </div>
      </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">[quote="pya, post:1, topic:222401"]
Without the above specialization, I ran int<span class="show-more-container"><a href="https://github.com/pytorch/pytorch/pull/161135" target="_blank" rel="noopener nofollow ugc" class="show-more">…</a></span><span class="excerpt hidden">o the following error using g+±13 with –std=c++17 option:

```
error: invalid use of incomplete type ‘struct torch::detail::WrapMethod&lt;void (MyClass::*)() const noexcept&gt;’
  110 |   return WrapMethod&lt;Func&gt;(std::move(f));
```
[/quote]

Fixes #ISSUE_NUMBER</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>