Skip to content

Instantly share code, notes, and snippets.

@fortheday
Created May 9, 2018 08:40
Show Gist options
  • Save fortheday/0fc8c10ee8ac543ecc72585163732404 to your computer and use it in GitHub Desktop.
Save fortheday/0fc8c10ee8ac543ecc72585163732404 to your computer and use it in GitHub Desktop.
#include <functional>
class FScopedExecuter
{
private:
using T_FUNC = std::function<void(void)>;
T_FUNC m_Func;
public:
FScopedExecuter(T_FUNC &&rvFunc) : m_Func(rvFunc) {}
~FScopedExecuter() { m_Func(); }
};
void Test()
{
{
FScopedExecuter executer([]() { LOG("Execute!"); });
}
}
@fortheday
Copy link
Author

std::function<>내부에 힙할당이 있으면서 이동생성자를 구현했다면 rvalue를 사용한 것이 의미가 있을 수 있다. 그렇지 않다면 복사생성자가 호출될 것이다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment