1 2 3 4 5 6 7 8 9 10 11 12 13
| #include <type_traits>
#include <iostream>
#include <string>
template <typename Bool, class = typename std::enable_if<std::is_fundamental<Bool>::value>::type> void f(const Bool& b) {std::cout<<"void f(const bool& b)"<<std::endl;}
template <typename String, class = typename std::enable_if<std::is_convertible<String, std::string>::value>::type, class = void> void f(const String& str) {std::cout<<"void f(const std::string& str)"<<std::endl;}
template <typename... Args> void f(const Args&... args) {std::cout<<"void f(const Args&... args)"<<std::endl;}
int main()
{
f(true);
f(std::string("Hello"));
f("Hello");
f(0);
} |
Partager