Created
August 15, 2019 13:15
-
-
Save qrealka/5ff8f22a5fc5c2e89c2bfa3de1fbb3a3 to your computer and use it in GitHub Desktop.
cpp11 sfinae
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
template<class T> | |
auto serialize_imp(std::ostream& os, T const& obj, int) | |
-> decltype(os << obj, void()) | |
{ | |
os << obj; | |
} | |
template<class T> | |
auto serialize_imp(std::ostream& os, T const& obj, long) | |
-> decltype(obj.stream(os), void()) | |
{ | |
obj.stream(os); | |
} | |
template<class T> | |
auto serialize(std::ostream& os, T const& obj) | |
-> decltype(serialize_imp(os, obj, 0), void()) | |
{ | |
serialize_imp(os, obj, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment