Last active
December 19, 2015 07:59
-
-
Save Oberon00/5922937 to your computer and use it in GitHub Desktop.
C++ overload resolution and partial ordering of function template specializations
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 <iostream> | |
#include <cstddef> | |
template <std::size_t N> | |
void foo(char const (&)[N]) | |
{ | |
std::cout << "foo<" << N << ">(char const (&)["<< N << "])\n"; | |
} | |
template <typename T> | |
void foo(T const*) | |
{ | |
std::cout << "foo(T const*)"; | |
} | |
int main() | |
{ | |
foo("bar"); | |
} |
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 <iostream> // std::cout | |
#include <cstddef> // std::size_t | |
void foo(char const (&)[4]) | |
{ | |
std::cout << "foo(char const (&)["<< 4 << "])\n"; | |
} | |
void foo(char const*) | |
{ | |
std::cout << "foo(char const*)"; | |
} | |
int main() | |
{ | |
foo("bar"); | |
} |
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 <iostream> | |
#include <cstddef> | |
template <std::size_t N> | |
void foo(char const (&)[N]) | |
{ | |
std::cout << "foo<" << N << ">(char const (&)["<< N << "])\n"; | |
} | |
template <typename T> | |
void foo(T) | |
{ | |
std::cout << "foo(T)"; | |
} | |
int main() | |
{ | |
foo("bar"); | |
} |
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 <iostream> // std::cout | |
#include <cstddef> // std::size_t | |
template <std::size_t N> | |
void foo(char const (&)[N]) | |
{ | |
std::cout << "foo<" << N << ">(char const (&)["<< N << "])\n"; | |
} | |
void foo(char const*) | |
{ | |
std::cout << "foo(char const*)"; | |
} | |
int main() | |
{ | |
foo("bar"); | |
} | |
// Output: foo(char const*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment