title: Is it possible to detect if a lambda has “this” in the capture group?
body: <p>In c++17 is it possible to do template meta-programming to detect if “this” was part of the capture group some how? Or at runtime?</p>
  <p>I have a class A that accepts the lambda for later invocation. However, if the object B owning A captures “this” in the lambda it gives A, then it can cause a subtle use-after free. Being able to crash in this scenario would be valuable.</p>
  <p>I’m aware their wouldn’t be 100% (eg a user could capture it as “a = this” or “b = (void*)this”). I also don’t expect to be able to capture all problems (eg if I capture a reference to a member variable). I’m just looking to add some confidence in the obviously wrong scenarios</p>