Skip to content

Instantly share code, notes, and snippets.

@evanzillians
Created April 1, 2013 09:56
Show Gist options
  • Save evanzillians/5284080 to your computer and use it in GitHub Desktop.
Save evanzillians/5284080 to your computer and use it in GitHub Desktop.
get destructors at compile time
#include <functional>
#include <vector>
template<typename T>
std::function<void(void *)> get_dtor()
{
return [](void *p)
{
return static_cast<T *>(p)->~T();
};
}
template<typename ...T>
void test()
{
std::vector<std::function<void(void *)>> dtors{
get_dtor<T>()...
};
}
int main()
{
test<int, float>();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment