, - , n sfinae'd foo:
std::enable_if<!std::is_integral<T>::value && !std::is_same<T, std::string>::value>::type
, ( ).
:
#include <iostream>
#include <utility>
#include <string>
template<int N> struct Choice: Choice<N-1> {};
template<> struct Choice<0> {};
template<typename T, typename... Args>
std::enable_if_t<std::is_integral<T>::value>
bar(Choice<2>, Args&&...) { std::cout << "integral" << std::endl; }
template<typename T, typename... Args>
std::enable_if_t<std::is_same<T, std::string>::value>
bar(Choice<1>, Args&&...) { std::cout << "string" << std::endl; }
template<typename T, typename... Args>
void bar(Choice<0>, Args&&...) { std::cout << "whatever" << std::endl; }
template<typename T, typename... Args>
void foo(Args&&... args) { bar<T>(Choice<100>{}, std::forward<Args>(args)...); }
int main() {
foo<bool>("foo");
foo<std::string>(42);
foo<void>(.0, "bar");
}
, , .
, N 0. , , T sfinae.
sfinae i- , Choice<0> ( , std::enable_if<!std::is_integral<T>::value && !std::is_same<T, std::string>::value>::type).
( ) , , , Choice<N>.
Coliru.