# Custom\_class\_detail.h WrapMethod noexcept

**URL:** <https://discuss.pytorch.org/t/custom-class-detail-h-wrapmethod-noexcept/222401>\
**Category:** C++\
**Created:** [August 16, 2025, 2:27pm UTC](https://discuss.pytorch.org/t/custom-class-detail-h-wrapmethod-noexcept/222401 "2025-08-16T14:27:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pya](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pya](https://discuss.pytorch.org/u/pya)\
**Post date:** [August 16, 2025, 2:27pm UTC](https://discuss.pytorch.org/t/custom-class-detail-h-wrapmethod-noexcept/222401/1 "2025-08-16T14:27:38Z")

</div>

Hi,

I would like to suggest the addition of the following function to custom\_class\_detail.h:

```auto
template <typename R, typename CurrClass, typename... Args>
struct WrapMethod<R (CurrClass::*)(Args...) const noexcept> {
  WrapMethod(R (CurrClass::*m)(Args...) const noexcept) : m(std::move(m)) {}

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

  R (CurrClass::*m)(Args...) const;
};

```

Without the above specialization, I ran into the following error using g+±13 with –std=c++17 option:

```auto
error: invalid use of incomplete type ‘struct torch::detail::WrapMethod<void (MyClass::*)() const noexcept>’
  110 | return WrapMethod<Func>(std::move(f));

```

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [August 17, 2025, 1:39pm UTC](https://discuss.pytorch.org/t/custom-class-detail-h-wrapmethod-noexcept/222401/2 "2025-08-17T13:39:01Z")

</div>

Could you open a PR on GitHub describing the proposed change so the code owners can take a look at it, please?

---

<div class="post-metadata">

**Author:** ![pya](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pya](https://discuss.pytorch.org/u/pya)\
**Post date:** [August 21, 2025, 3:30am UTC](https://discuss.pytorch.org/t/custom-class-detail-h-wrapmethod-noexcept/222401/3 "2025-08-21T03:30:18Z")

</div>

Done!

> <https://github.com/pytorch/pytorch/pull/161135>
>
> \[quote="pya, post:1, topic:222401"\]
> Without the above specialization, I ran int…o the following error using g+±13 with –std=c++17 option:
> 
> \`\`\`
> error: invalid use of incomplete type ‘struct torch::detail::WrapMethod\<void (MyClass::\*)() const noexcept\>’
> 110 | return WrapMethod\<Func\>(std::move(f));
> \`\`\`
> \[/quote\]
> 
> Fixes #ISSUE\_NUMBER
