#include #include #include #include template constexpr bool supported = false; template std::string describe(const T& x) { using U = std::remove_cv_t>; if constexpr (std::is_integral_v) { return "integer:" + std::to_string(x); } else if constexpr (std::is_same_v) { return "text:" + std::to_string(x.size()); } else { static_assert(supported, "requires integer or string"); } } int main() { const int n = 7; std::string s = "abc"; assert(describe(n) == "integer:7"); assert(describe(s) == "text:3"); std::cout << describe(n) << ' ' << describe(s) << '\n'; }