Created
October 21, 2018 09:11
-
-
Save Pharap/d9fd6f29ff2028acd817570e210d0c7d to your computer and use it in GitHub Desktop.
Demonstrates that function pointer dereferencing is equivalent to identity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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