Skip to content

Instantly share code, notes, and snippets.

@BogdanAriton
Created June 15, 2021 15:26
Show Gist options
  • Save BogdanAriton/47482dfbcd09dfd9d1cef38711461aea to your computer and use it in GitHub Desktop.
Save BogdanAriton/47482dfbcd09dfd9d1cef38711461aea to your computer and use it in GitHub Desktop.
namespace helper
{
// these expressions will be evaluated at compile time
template <typename T>
constexpr typename std::enable_if<!std::is_convertible<T, std::string>::value, std::string>::type
to_string(const T &val) // cannot be converted directly thus we have to use type traits to determine if we can use to_string
{
return std::to_string(val);
};
template <typename T>
constexpr typename std::enable_if<std::is_convertible<T, std::string>::value, std::string>::type
to_string(const T &val) // converts to string directly
{
return val;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment