Skip to content

Instantly share code, notes, and snippets.

@Pharap
Created October 21, 2018 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pharap/d9fd6f29ff2028acd817570e210d0c7d to your computer and use it in GitHub Desktop.
Save Pharap/d9fd6f29ff2028acd817570e210d0c7d to your computer and use it in GitHub Desktop.
Demonstrates that function pointer dereferencing is equivalent to identity
#include <type_traits>
#include <iostream>
int func(void) { return 42; }
int main(void)
{
auto fp0 = func;
auto fp1 = *func;
auto fp2 = *******func;
static_assert(std::is_same<decltype(fp0), decltype(fp1)>::value, "func is not the same as *func");
static_assert(std::is_same<decltype(fp0), decltype(fp2)>::value, "func is not the same as *******func");
static_assert(std::is_same<decltype(fp1), decltype(fp2)>::value, "*func is not the same as *******func");
std::cout << func() << '\n';
std::cout << (*func)() << '\n';
std::cout << (*******func)() << '\n';
(void)std::cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment