Last active
July 12, 2017 20:59
-
-
Save stryku/00077ed563e1ddb0f9546fb3922a908f 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 details | |
| { | |
| template <typename Type> | |
| struct HasToString { | |
| private: | |
| template<typename T> | |
| static constexpr auto check(T*) -> typename std::is_same< | |
| decltype(std::declval<T>().toString()), | |
| std::string | |
| >::type; | |
| template<typename> | |
| static constexpr std::false_type check(...); | |
| using type = decltype(check<Type>(nullptr)); | |
| public: | |
| static constexpr bool value = type::value; | |
| }; | |
| } | |
| template <typename T> | |
| constexpr auto HasToString = details::HasToString<T>::value; | |
| template <typename T> | |
| std::enable_if_t<HasToString<T>, std::string> | |
| toString(const T& value) | |
| { | |
| return value.toString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment