Last active
December 1, 2020 00:29
-
-
Save srz-zumix/e70b72d1c9649e3c1fe918f8d4521949 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
| #include <iostream> | |
| #include <cstdlib> | |
| #include <type_traits> | |
| #include "donot-change.h" | |
| struct X | |
| { | |
| }; | |
| template <class T> | |
| concept printable = requires (T x) { ::std::cout << x; }; | |
| template<typename T> | |
| requires (!printable<T>) | |
| void print(const T&) | |
| { | |
| ::std::cout << "unknown" << ::std::endl; | |
| } | |
| int main() | |
| { | |
| print(1); | |
| print(nullptr); | |
| print(X()); | |
| } | |
| // https://wandbox.org/permlink/yznTfVoLiDd3deC9 |
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<typename T> | |
| void print(const T& val) | |
| { | |
| ::std::cout << val << ::std::endl; | |
| } |
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
| #include <iostream> | |
| #include <cstdlib> | |
| #include <type_traits> | |
| #include "donot-change.h" | |
| struct X | |
| { | |
| }; | |
| void print(...) | |
| { | |
| ::std::cout << "unknown" << ::std::endl; | |
| } | |
| template<typename T> | |
| void print(const T& val, typename std::enable_if<std::is_same<decltype((::std::cout << std::declval<T>()), int()), int>::value>::type* = nullptr) | |
| { | |
| ::std::cout << val << ::std::endl; | |
| } | |
| #if __GNUC__ < 8 | |
| template<> | |
| void print(const ::std::nullptr_t&) | |
| { | |
| ::std::cout << "nullptr" << ::std::endl; | |
| } | |
| #endif | |
| int main() | |
| { | |
| print(1); | |
| print(nullptr); | |
| print(X()); | |
| } | |
| // https://wandbox.org/permlink/5Yoc4b6Px7V89r17 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment