Skip to content

Instantly share code, notes, and snippets.

@bolry
Created July 11, 2018 07:24
Show Gist options
  • Save bolry/ceb63d59cb06b93f86e6b99a15605080 to your computer and use it in GitHub Desktop.
Save bolry/ceb63d59cb06b93f86e6b99a15605080 to your computer and use it in GitHub Desktop.
Tricky C++ question
template<class T, int ... X>
T pi(T(X...));
#include <iostream>
void foo() { std::cout << __LINE__ << '\n'; }
void foo(int) { std::cout << __LINE__ << '\n'; }
template<typename T> void foo(T) { std::cout << __LINE__ << '\n'; }
template<> void foo(int) { std::cout << __LINE__ << '\n'; }
template<typename T>void foo(T *) { std::cout << __LINE__ << '\n'; }
struct S {};
void foo(S) { std::cout << __LINE__ << '\n'; }
struct ConvertibleToInt { ConvertibleToInt(int); };
void foo(ConvertibleToInt) { std::cout << __LINE__ << '\n'; }
namespace N {
namespace M { void foo(char) { std::cout << __LINE__ << '\n'; }}
void foo(double) { std::cout << __LINE__ << '\n'; }
}
int main() {
foo(1);
using namespace N::M;
foo(1);
return pi<int, 42>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment