Created
June 15, 2021 15:26
-
-
Save BogdanAriton/47482dfbcd09dfd9d1cef38711461aea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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